-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlite.py
49 lines (33 loc) · 867 Bytes
/
sqlite.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
import settings
import sqlite3
DB = settings.sql_DB
def set(query, args):
rowid = -1
try:
conn = sqlite3.connect(DB)
cursor = conn.cursor()
cursor.execute(query, args)
rowid = cursor.lastrowid
conn.commit()
cursor.close()
conn.close()
except sqlite3.Error as e:
print "An error occurred:", e.args[0]
return rowid
def get(query, args):
rows = (-1, 'Error')
try:
count = 0
conn = sqlite3.connect(DB)
cursor = conn.cursor()
if len(args) == 0:
cursor.execute(query)
else:
cursor.execute(query, args)
rows = cursor.fetchall()
count = len(rows)
cursor.close()
conn.close()
except sqlite3.Error as e:
print "An error occurred:", e.args[0]
return rows, count