56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
import os
|
|
import sqlite3
|
|
from sqlite3 import Error
|
|
from werkzeug.datastructures import FileStorage
|
|
|
|
|
|
class LFDB:
|
|
|
|
def __init__(self, db_path):
|
|
# self.lf = LFUtilities.load(settings.DATASET_BEBLID)
|
|
# self.ids = np.loadtxt(settings.DATASET_IDS, dtype=str).tolist()
|
|
# self.bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
|
|
self.conn = sqlite3.connect(db_path, check_same_thread=False)
|
|
|
|
def close(self):
|
|
if self.conn:
|
|
self.conn.close()
|
|
|
|
def put(self, docId, features):
|
|
try:
|
|
self.conn.text_factory = str
|
|
#print("[INFO] : Successful connection!")
|
|
cur = self.conn.cursor()
|
|
insert_file = '''INSERT INTO lf(docId, features) VALUES(?, ?)'''
|
|
cur = self.conn.cursor()
|
|
cur.execute(insert_file, (docId, features,))
|
|
#print("[INFO] : The blob for ", docId, " is in the database.")
|
|
except Error as e:
|
|
print(e)
|
|
|
|
def commit(self):
|
|
try:
|
|
if self.conn:
|
|
self.conn.commit()
|
|
print("committing...")
|
|
except Error as e:
|
|
print(e)
|
|
|
|
def get(self, docId):
|
|
try:
|
|
self.conn.text_factory = str
|
|
cur = self.conn.cursor()
|
|
# print("[INFO] : Connected to SQLite to read_blob_data")
|
|
sql_fetch_blob_query = """SELECT * from lf where docId = ?"""
|
|
cur.execute(sql_fetch_blob_query, (docId,))
|
|
record = cur.fetchall()
|
|
for row in record:
|
|
converted_file_name = row[1]
|
|
blob = row[2]
|
|
# parse out the file name from converted_file_name
|
|
cur.close()
|
|
except sqlite3.Error as error:
|
|
print("[INFO] : Failed to read blob data from sqlite table", error)
|
|
return blob
|
|
|