Fix database.py
This commit is contained in:
parent
27587468ba
commit
5f0237a48f
|
@ -4,6 +4,7 @@ from pathlib import Path
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from ordigi import LOG
|
||||||
from ordigi.utils import distance_between_two_points
|
from ordigi.utils import distance_between_two_points
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ class Sqlite:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.db_type = 'SQLite format 3'
|
self.db_type = 'SQLite format 3'
|
||||||
|
self.log = LOG.getChild(self.__class__.__name__)
|
||||||
self.types = {'text': (str, datetime), 'integer': (int,), 'real': (float,)}
|
self.types = {'text': (str, datetime), 'integer': (int,), 'real': (float,)}
|
||||||
|
|
||||||
self.filename = Path(db_dir, 'collection.db')
|
self.filename = Path(db_dir, 'collection.db')
|
||||||
|
@ -40,6 +42,7 @@ class Sqlite:
|
||||||
'DateOriginal': 'text',
|
'DateOriginal': 'text',
|
||||||
'DateCreated': 'text',
|
'DateCreated': 'text',
|
||||||
'DateModified': 'text',
|
'DateModified': 'text',
|
||||||
|
'FileModifyDate': 'text',
|
||||||
'CameraMake': 'text',
|
'CameraMake': 'text',
|
||||||
'CameraModel': 'text',
|
'CameraModel': 'text',
|
||||||
'OriginalName': 'text',
|
'OriginalName': 'text',
|
||||||
|
@ -119,8 +122,13 @@ class Sqlite:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _run(self, query, n=0):
|
def _run(self, query, n=0):
|
||||||
result = False
|
self.log.debug(f"Sqlite run '{query}'")
|
||||||
result = self.cur.execute(query).fetchone()
|
|
||||||
|
try:
|
||||||
|
result = self.cur.execute(query).fetchone()
|
||||||
|
except sqlite3.DatabaseError as e:
|
||||||
|
self.log.error(e)
|
||||||
|
result = False
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
return result[n]
|
return result[n]
|
||||||
|
@ -217,12 +225,19 @@ class Sqlite:
|
||||||
|
|
||||||
return self.add_row(table, row_data)
|
return self.add_row(table, row_data)
|
||||||
|
|
||||||
|
|
||||||
|
def escape_quote(self, string):
|
||||||
|
return string.translate(str.maketrans({"'": r"''"}))
|
||||||
|
|
||||||
|
|
||||||
def get_checksum(self, file_path):
|
def get_checksum(self, file_path):
|
||||||
query = f"select Checksum from metadata where FilePath='{file_path}'"
|
file_path_e = self.escape_quote(str(file_path))
|
||||||
|
query = f"select Checksum from metadata where FilePath='{file_path_e}'"
|
||||||
return self._run(query)
|
return self._run(query)
|
||||||
|
|
||||||
def get_metadata_data(self, file_path, data):
|
def get_metadata_data(self, file_path, data):
|
||||||
query = f"select {data} from metadata where FilePath='{file_path}'"
|
file_path_e = self.escape_quote(str(file_path))
|
||||||
|
query = f"select {data} from metadata where FilePath='{file_path_e}'"
|
||||||
return self._run(query)
|
return self._run(query)
|
||||||
|
|
||||||
def match_location(self, latitude, longitude):
|
def match_location(self, latitude, longitude):
|
||||||
|
|
Loading…
Reference in New Issue