-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabaseInteractor.py
41 lines (33 loc) · 1.04 KB
/
databaseInteractor.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
import pymysql
class DatabaseInteractor(object):
"""docstring for ClassName"""
def __init__(self):
self.db = pymysql.connect("localhost","root","","minorproject" )
self.curs=self.db.cursor()
def insert(self,user_name,date,time,address):
try:
sql = "SELECT userid from `user` WHERE username = '%s' " %(user_name)
self.curs.execute(sql)
result = self.curs.fetchone()
if not self.curs.rowcount:
try:
print "here"
sql = "INSERT INTO `user`(username) VALUES ('%s')"%(user_name)
print sql
self.curs.execute(sql)
self.db.commit()
sql = "SELECT userid from `user` WHERE username = '%s' "%(user_name)
print sql
self.curs.execute(sql)
result = self.curs.fetchone()
except Exception as e:
raise e
except Exception as e:
raise e
user_id = result[0]
try:
sql = "INSERT INTO `extract`(`userid`,`date`,`time`,`address`) VALUES (%d,'%s','%s','%s')"%(user_id,date,time,address)
self.curs.execute(sql)
self.db.commit()
except Exception as e:
raise e