-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdb_controller.py
74 lines (69 loc) · 1.77 KB
/
db_controller.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
import psycopg2
from config import db_conf as config
def insert_db(sql,arg):
conn = None
value = None
try:
params = config()
conn = psycopg2.connect(**params)
cur = conn.cursor()
cur.execute(sql,(arg))
value = cur.fetchone()[0]
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
# print("insert_db :"+error)
pass
finally:
if conn is not None:
conn.close()
return value
def update_db(sql,arg):
conn = None
try:
params = config()
conn = psycopg2.connect(**params)
cur = conn.cursor()
cur.execute(sql,(arg))
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
# print("update_db :"+error)
pass
finally:
if conn is not None:
conn.close()
def get_SingleValue(sql,arg):
conn = None
value = None
try:
params = config()
conn = psycopg2.connect(**params)
cur = conn.cursor()
cur.execute(sql,(arg,))
value = cur.fetchone()[0]
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
# print("get_SingleValue dberror:"+error)
pass
finally:
if conn is not None:
conn.close()
return value
def get_AllValues(sql,arg):
conn = None
value = []
try:
params = config()
conn = psycopg2.connect(**params)
cur = conn.cursor()
cur.execute(sql,(arg,))
value = cur.fetchall()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
# print("get_AllValues :"+error)
pass
finally:
if conn is not None:
conn.close()
return value