-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsql_funcs.py
More file actions
32 lines (29 loc) · 861 Bytes
/
sql_funcs.py
File metadata and controls
32 lines (29 loc) · 861 Bytes
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
import sqlite3
def create_table(conn, command):
try:
cur = conn.cursor()
cur.execute(command)
conn.commit()
cur.close()
except Exception as error:
print('Unable to create table:',error)
def get_query(conn, query):
try:
cur = conn.cursor()
cur.execute(query)
result = cur.fetchall()
cur.close()
return result
except Exception as error:
print('Unable to execute query:',error)
def insert_row(conn, command, data):
try:
cur = conn.cursor()
cur.execute(command, data)
cur.close()
except sqlite3.Error as er:
print('SQLite error: %s' % (' '.join(er.args)))
print("Exception class is: ", er.__class__)
print('SQLite traceback: ')
except Exception as error:
print('Unable to add alert:',error)