forked from CodecoolBase/ask-mate-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment_data_manager.py
More file actions
76 lines (60 loc) · 2.27 KB
/
comment_data_manager.py
File metadata and controls
76 lines (60 loc) · 2.27 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
import connection
@connection.connection_handler
def update_view_number(cursor, q_id):
cursor.execute("""
update question
set view_number = view_number+1
where id = %(q_id)s
""",
{'q_id': q_id})
@connection.connection_handler
def update_vote_number(cursor, vote, q_id):
cursor.execute("""
UPDATE question
set vote_number = %(vote)s
WHERE id = %(q_id)s
""",
{'vote': vote, 'q_id': q_id})
@connection.connection_handler
def add_comment_to_question(cursor, q_id, comment_message, u_id, s_time):
cursor.execute("""
insert into comment(question_id, message, user_id, submission_time)
values (%(q_id)s,%(comment_message)s,%(u_id)s,%(s_time)s)
""",
{'q_id': q_id, 'comment_message': comment_message, 'u_id': u_id, 's_time': s_time})
@connection.connection_handler
def add_comment_to_answer(cursor, a_id, comment_message):
cursor.execute("""
insert into comment(answer_id, message)
values (%(a_id)s,%(comment_message)s)
""",
{'a_id': a_id, 'comment_message': comment_message})
@connection.connection_handler
def collect_comment_to_question(cursor, q_id):
cursor.execute("""
Select message from comment
where question_id = %(q_id)s
""",
{'q_id': q_id})
result = cursor.fetchall()
return result
@connection.connection_handler
def collect_comment_to_answer(cursor, a_id):
cursor.execute("""
Select message, answer_id from comment
where answer_id = %(a_id)s
""",
{'a_id': a_id})
result = cursor.fetchall()
return result
@connection.connection_handler
def get_all_comments_from_user(cursor, u_id):
cursor.execute("""
Select comment.message as comment, question.title as question, question.id as q_id, answer.question_id as question_id, answer.message as answer from comment
full join answer on comment.answer_id = answer.id
full join question on comment.question_id = question.id
where comment.user_id = %(u_id)s
""",
{'u_id': u_id})
result = cursor.fetchall()
return result