-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbAspect.py
32 lines (26 loc) · 1.16 KB
/
dbAspect.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
import pymysql.cursors
class DBConnection():
def __init__(self):
self.connection = pymysql.connect(host='localhost', user='root',
password='')
with self.connection.cursor() as cursor:
cursor.execute("CREATE DATABASE IF NOT EXISTS alpr")
self.connection.commit()
def save_alpr(self, license_plate_text, moment):
"""
Saves the license plate text in the database table
Parameters:
-----------
license_plate_text: str; the text on the license plate
moment: str; the current date and time
"""
try:
with self.connection.cursor() as cursor:
table_sql = "CREATE TABLE IF NOT EXISTS `alpr`.`alpr` ( `id` INT NOT NULL AUTO_INCREMENT , `plate_text` VARCHAR(15) NOT NULL , `moment` VARCHAR(30) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;"
cursor.execute(table_sql)
#insert record
sql = "INSERT INTO `alpr`.`alpr` (plate_text, moment) VALUES(%s, %s)"
cursor.execute(sql, (license_plate_text, moment))
self.connection.commit()
finally:
pass