-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueries.sql
More file actions
executable file
·88 lines (79 loc) · 1.92 KB
/
queries.sql
File metadata and controls
executable file
·88 lines (79 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- NOTE THAT 'Norma' has to be replaced with the current logged in user in the Java code
/*
browse contact list
*/
SELECT u1.login AS Contacts, u1.status AS Status
FROM (
SELECT con.list_member
FROM USER_LIST_CONTAINS con, USR u
WHERE u.login = 'Norma'
AND u.contact_list = con.list_id
) AS list, USR u1
WHERE list.list_member = u1.login;
/*
browse block list
users in block list will not be able to send you messages
you are unable to add user to chat if you are in their block list
*/
SELECT u1.login AS Blocked_Contacts
FROM (
SELECT con.list_member
FROM USER_LIST_CONTAINS con, USR u
WHERE u.login = 'Norma'
AND u.block_list = con.list_id
) AS list, USR u1
WHERE list.list_member = u1.login;
/*
delete from block/contact list
*/
DELETE FROM USER_LIST_CONTAINS
WHERE list_member = 'Arne'
AND list_id =
(
SELECT contact_list
FROM USR
WHERE login = 'Norma'
);
/*
add to contact/block list
adding invalid username does not add to list
find way to notify user in this event
*/
INSERT INTO USER_LIST_CONTAINS
SELECT u1.contact_list, u2.login
FROM
(
SELECT *
FROM USR
WHERE login = 'Norma'
) u1, USR u2
WHERE u2.login = 'Cecil.Gaylord';
/*
delete acc
check if other records refer to acc preventing deletion. like for a chat.
ex: chat foreign key init_sender refers to deleted acc (bad situation)
use trigger perhaps to check for chats of init_sender = usr.login and prevent deletion
*/
DELETE FROM Usr
WHERE login = 'Norma';
/*
delete chat and messages
*/
DELETE FROM Message WHERE chat_id = num;
/*
browse current chats
*/
SELECT chats.chat_id AS Current_Chats
FROM CHAT_LIST chats, USR u1
WHERE u1.login = 'Norma' AND chats.member = u1.login;
/*
add chat with initial members
*/
INSERT INTO CHAT VALUES (DEFAULT,'private','Norma');
/*then*/
INSERT INTO CHAT_LIST VALUES ('CHAT_ID', 'member');
/*
browse messages
10 at a time chronologically
*/
select * from table order by timestamp desc