-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdc1.py
38 lines (25 loc) · 1.04 KB
/
dc1.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
import sqlite3
def writeTofile(data, filename):
# Convert binary data to proper format and write it on Hard Disk
with open(filename, 'wb') as file:
file.write(data)
print("Stored blob data into: ", filename, "\n")
def readBlobData(Id):
try:
sqliteConnection = sqlite3.connect('project.db')
cursor = sqliteConnection.cursor()
print("Connected to SQLite")
sql_fetch_blob_query = """SELECT * from new_image where id = ?"""
cursor.execute(sql_fetch_blob_query, (Id,))
record = cursor.fetchall()
for row in record:
photo = row[1]
photoPath = "File.jpg"
writeTofile(photo, photoPath)
cursor.close()
except sqlite3.Error as error:
print("Failed to read blob data from sqlite table", error)
finally:
if sqliteConnection:
sqliteConnection.close()
print("sqlite connection is closed")