-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_handler.py
43 lines (34 loc) · 1.14 KB
/
query_handler.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
import logging
import json
import os
import sys
root_folder = os.path.abspath(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root_folder)
import db_connection
def exec_query_with_message(sql_query):
message = None
with db_connection.Db_Connection() as conn:
logging.info("Connection established")
with conn.cursor() as cursor:
cursor.execute(sql_query)
message = cursor.fetchone()[0]
if message == None:
return message
return message
def exec_query_with_records(sql_query):
records = []
with db_connection.Db_Connection() as conn:
logging.info("Connection established")
with conn.cursor() as cursor:
cursor.execute(sql_query)
row = cursor.fetchone()
while row:
records.append(row)
row = cursor.fetchone()
return records
def exec_query_with_no_response(sql_query):
message = None
with db_connection.Db_Connection() as conn:
logging.info("Connection established")
with conn.cursor() as cursor:
cursor.execute(sql_query)