forked from p4r4noj4/ED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_commands.py
76 lines (61 loc) · 3.12 KB
/
sql_commands.py
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
"""
SQL commands used by other scripts
"""
# SELECTS
COMMENTS_GRAPH = """
SELECT user_comments_reply.name, users.name FROM
(SELECT user_comments.name AS name, user_comments.comment_id AS comment_id,
user_comments.parent_comment, comments.user_id AS parent_user_id FROM
(SELECT name, c1.comment_id AS comment_id, c1.parent_id AS parent_comment FROM `users`
LEFT OUTER JOIN comments AS c1 ON c1.user_id=users.user_id WHERE c1.parent_id!=0) AS user_comments
LEFT JOIN comments ON user_comments.parent_comment=comments.comment_id) AS user_comments_reply
LEFT JOIN users ON user_comments_reply.parent_user_id=users.user_id"""
COMMENTS_GRAPH_SIMPLE = """
SELECT * FROM (SELECT name, c1.talk_id AS talk_id FROM `users`
LEFT OUTER JOIN comments AS c1 ON c1.user_id=users.user_id) AS user_comments"""
TALKS_USERS_GRAPH = """
SELECT name, c1.talk_id AS talk_id
FROM `users`
LEFT OUTER JOIN comments AS c1 ON c1.user_id = users.user_id
"""
TALKS_USERS_FILTERED_GRAPH = """
SELECT DISTINCT filtered_users.name, c2.talk_id FROM (SELECT * FROM (SELECT count(c1.talk_id) AS number_comments, name, users.user_id FROM `users`
LEFT OUTER JOIN comments AS c1 ON c1.user_id=users.user_id
GROUP BY name) AS commenting_users WHERE number_comments>5) AS filtered_users
LEFT JOIN comments AS c2 ON filtered_users.user_id=c2.user_id
"""
COMMENTS_THEMES_GRAPH = """
SELECT name1, name2, name FROM
(SELECT name1, name2, theme_id FROM
(SELECT user_comments_reply.name AS name1, users.name AS name2, talk_id AS comment_talk_id FROM
(SELECT user_comments.name AS name, user_comments.comment_id AS comment_id,
user_comments.parent_comment, comments.user_id AS parent_user_id, comments.talk_id AS talk_id FROM
(SELECT name, c1.comment_id AS comment_id, c1.parent_id AS parent_comment FROM `users`
LEFT OUTER JOIN comments AS c1 ON c1.user_id=users.user_id WHERE c1.parent_id!=0) AS user_comments
LEFT JOIN comments ON user_comments.parent_comment=comments.comment_id) AS user_comments_reply
LEFT JOIN users ON user_comments_reply.parent_user_id=users.user_id) AS user_user
LEFT JOIN talk_themes ON talk_themes.talk_id=comment_talk_id) AS user_user_theme_talk
LEFT JOIN themes ON themes.id=theme_id"""
TALKS_THEMES = """
SELECT names_themes.name, themes.name FROM
(SELECT id, name, talk_themes.theme_id AS theme_id FROM talks
LEFT JOIN talk_themes ON talk_themes.talk_id=talks.id) AS names_themes
LEFT JOIN themes ON themes.id=names_themes.theme_id"""
TALKS_THEMES_MAX = """
SELECT names_themes.name, themes.name FROM
(SELECT id, name, theme_id FROM talks
LEFT JOIN talk_themes ON talk_id=id) AS names_themes
LEFT JOIN themes ON themes.id=talk_themes.theme_id"""
TALKS_RATINGS_HIGHEST = """
SELECT d.talk_id AS talk1, t.talk_id AS talk2, d.name AS rating_name FROM
ratings_temp AS t
LEFT JOIN
ratings_temp AS d ON t.name = d.name WHERE t.talk_id != d.talk_id"""
TALKS_RATINGS = """
SELECT d.talk_id AS talk1, t.talk_id AS talk2, d.name AS rating_name FROM
ratings AS t
LEFT JOIN
ratings AS d ON t.name = d.name WHERE t.talk_id != d.talk_id"""
# INSERTS
ADD_USER = """INSERT INTO users VALUES (%s,%s,%s,%s, %s)"""
SAVE_COMMENT = """INSERT INTO comments VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""