-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
108 lines (81 loc) · 3.4 KB
/
db.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import sqlite3
#import os.path as path
class DBhandler:
def __init__(self):
"""def restaurant_duplicate_check(self, name):
self.cur.execute("SELECT * FROM restaurant('name') as nameInfo")
for res in nameInfo
restaurants = self.db.child("restaurant").get()
for res in restaurants.each():
if res.key() == name:
return False
return True"""
def insert_restaurant(self, name, data, img_path):
con = sqlite3.connect("database.db")
cur = con.cursor()
#cur = self.con.cursor()
"""restaurant_info ={
"addr": data['addr'],
"tel": data['tel'],
"category": data['category'],
"park": data['park'],
"time": data['time'],
"site": data['site'],
"img_path": img_path
}"""
sql = "INSERT INTO restaurant VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')" % (name, data['addr'], data['category'], img_path, data['park'],data['site'],data['tel'],data['time'],data['writer'])
cur.execute(sql)
con.commit()
con.close()
return True
#중복확인하는거 해야흠
"""if self.restaurant_duplicate_check(name):
sql = "INSERT INTO restaurant VALUES ('%s','%s','%s','%s','%s','%s','%s','%s')" % (data['name'], data['addr'], data['category'], img_path, data['park'],data['site'],data['tel'],data['time'])
self.cur.execute(sql)
return True
else:
return False"""
def modify_restaurant(self, name, data, img_path):
con = sqlite3.connect("database.db")
cur = con.cursor()
sql = "UPDATE restaurant SET name='%s',addr='%s',category='%s', img_path='%s',park='%s',site='%s', tel='%s',time='%s', writer='%s' WHERE name='%s'" % (data['name'], data['addr'], data['category'], img_path, data['park'],data['site'],data['tel'],data['time'],data['writer'], name)
cur.execute(sql)
con.commit()
con.close()
return True
def get_restaurants(self):
con = sqlite3.connect("database.db")
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute("SELECT * FROM restaurant")
rows = cur.fetchall()
con.close()
return rows
def get_restaurant_byname(self, name):
con = sqlite3.connect("database.db")
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute("SELECT * FROM restaurant")
rows = cur.fetchall()
if(len(rows) ==0 ):#db 비어있는 경우
return "None"
for value in rows:
if str(value['name']) == name:
return value
return "None"
def remove_restaurant(self, name):
#print(name)
con = sqlite3.connect("database.db")
cur = con.cursor()
cur.execute('DELETE FROM restaurant where name=?',(name,))
con.commit()
con.close()
return
def find_user(self, id_, pw_):
con=sqlite3.connect("database.db", check_same_thread=False)
cur = con.cursor()
cur.execute(f"SELECT * FROM user WHERE id='{id_}' AND pw='{pw_}';")
if cur.fetchone():
return True
else:
return False