-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
53 lines (38 loc) · 1.33 KB
/
Copy pathdatabase.py
File metadata and controls
53 lines (38 loc) · 1.33 KB
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
import time
import sqlite3
chargePerUnitTime = 0.1
def checkExistance(conn, registration):
cur = conn.cursor()
cur.execute("SELECT * FROM PARKING WHERE regNo = ?" ,(registration,))
rows = cur.fetchall()
if(len(rows) == 0):
return False
else:
return True
def Database_access(registration):
#!/usr/bin/python
conn = sqlite3.connect('test.db')
print "Opened database successfully"
starttime = str(time.time())
if(checkExistance(conn, registration) == False):
sql = '''INSERT INTO PARKING (regNo, entryTime) VALUES(?, ?)'''
conn.execute(sql,(registration, starttime))
else:
cur = conn.cursor()
cur.execute("SELECT entryTime FROM PARKING WHERE regNo = ?", (registration,))
rows = cur.fetchall()
starttime = rows[0][0]
endTime = time.time()
timeParked = endTime - float(starttime)
charge = timeParked * chargePerUnitTime
conn.execute("UPDATE PARKING SET exitTime= ?, charge= ? WHERE regNo = ?", (str(endTime), str(charge), str(registration)))
#cur = conn.cursor()
#cur.execute("SELECT * FROM PARKING")
cur = conn.cursor()
cur.execute("SELECT * FROM PARKING")
rows = cur.fetchall()
for row in rows:
print(row)
conn.commit()
conn.close()
#Database_access("wewe9444")