Skip to content

Commit

Permalink
Use constants in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
memgonzales committed Sep 1, 2023
1 parent b184786 commit 65eec10
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 1 addition & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@
connection = sqlite3.connect(const.FILE_STATUS_DB)
cursor = connection.cursor()

query = '''CREATE TABLE file_table (
name TEXT,
UNIQUE(name));'''
query = f'CREATE TABLE IF NOT EXISTS {const.FILE_STATUS_TABLE} (name TEXT, UNIQUE(name));'

cursor.execute(query)
connection.commit()
Expand Down
1 change: 1 addition & 0 deletions callbacks/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Constants(object):
# =========

FILE_STATUS_DB = f'{TEMP}/file_status.db'
FILE_STATUS_TABLE = 'file_status'

def __init__(self):
pass
4 changes: 2 additions & 2 deletions callbacks/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def shorten_name(name):
connection = sqlite3.connect(const.FILE_STATUS_DB)
cursor = connection.cursor()

query = f'INSERT OR IGNORE INTO file_table(name) VALUES("{name}")'
query = f'INSERT OR IGNORE INTO {const.FILE_STATUS_TABLE}(name) VALUES("{name}")'

cursor.execute(query)
connection.commit()
Expand All @@ -92,7 +92,7 @@ def shorten_name(name):
connection = sqlite3.connect(const.FILE_STATUS_DB)
cursor = connection.cursor()

query = f'SELECT rowid FROM file_table WHERE name = "{name}"'
query = f'SELECT rowid FROM {const.FILE_STATUS_TABLE} WHERE name = "{name}"'
cursor.execute(query)
row_id = cursor.fetchall()[0][0]

Expand Down

0 comments on commit 65eec10

Please sign in to comment.