-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrudImage.py
41 lines (30 loc) · 964 Bytes
/
CrudImage.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
from Connection import Connection
class CrudImage:
def insert(self, filename, text):
conn = Connection().conn()
cursor = conn.cursor()
sql = "INSERT INTO tess (filename, text) VALUES (%s, %s)"
cursor.execute(sql, (filename, text))
conn.commit()
lastid = cursor.lastrowid
cursor.close()
conn.close()
return lastid
def getAll(self):
conn = Connection().conn()
cursor = conn.cursor()
cursor.execute("SELECT * FROM tess")
result = cursor.fetchall()
cursor.close()
conn.close()
return result
def find(self, id):
conn = Connection().conn()
cursor = conn.cursor()
sql = "Select * FROM tess WHERE id = {id}".format(id = id)
print(sql)
cursor.execute(sql)
result = cursor.fetchall()
cursor.close()
conn.close()
return result