fix result when exception

This commit is contained in:
Antonio J. Delgado 2023-02-03 09:26:27 +02:00
parent 035fc51deb
commit 082341090e

View file

@ -61,14 +61,15 @@ class find_duplicate_files:
def _check_file_cache(self, file):
file_sql = file.replace("'", "''")
query = f"SELECT hash FROM files WHERE file = '{file_sql}'"
row = False
if isinstance(query, bytes):
query = query.decode('utf-8')
try:
result = self.cur.execute(query)
row = result.fetchone()
except Exception as error:
self._log.error(f"Error executing query '{query}'. {error}")
#sys.exit(2)
row = result.fetchone()
if row and len(row) > 0:
return row[0]
else:
@ -77,14 +78,15 @@ class find_duplicate_files:
def _cache_file(self, file, hash):
file_sql = file.replace("'", "''")
query = f"INSERT INTO files (file, hash) VALUES ('{file_sql}', '{hash}')"
result = False
if isinstance(query, bytes):
query = query.decode('utf-8')
try:
result = self.cur.execute(query)
self.cache_db.commit()
except Exception as error:
self._log.error(f"Error executing query '{query}'. {error}")
#sys.exit(3)
self.cache_db.commit()
return result
def _cache_size(self):