Skip to content

Commit

Permalink
updated sqlite units table to separate column name and unit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedant P Iyer committed Nov 27, 2024
1 parent 94f201c commit ec7ade5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dsi/backends/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ def put_artifacts(self, collection, isVerbose=False):
self.types = types #This will only copy the last table from artifacts (collections input)

if "dsi_units" in artifacts.keys():
create_query = "CREATE TABLE IF NOT EXISTS dsi_units (table_name TEXT, column_and_unit TEXT UNIQUE)"
create_query = "CREATE TABLE IF NOT EXISTS dsi_units (table_name TEXT, column TEXT UNIQUE, unit TEXT)"
self.cur.execute(create_query)
for tableName, tableData in artifacts["dsi_units"].items():
if len(tableData) > 0:
for col_unit_pair in tableData:
str_query = f'INSERT OR IGNORE INTO dsi_units VALUES ("{tableName}", "{col_unit_pair}")'
str_query = f'INSERT OR IGNORE INTO dsi_units VALUES ("{tableName}", "{col_unit_pair[0]}", "{col_unit_pair[1]}")'
try:
self.cur.execute(str_query)
except sqlite3.Error as e:
Expand Down Expand Up @@ -330,6 +330,8 @@ def read_to_artifact(self):
if tableName == "dsi_units":
artifact["dsi_units"] = self.read_units_helper()
continue
if tableName == "sqlite_sequence":
continue

tableInfo = self.cur.execute(f"PRAGMA table_info({tableName});").fetchall()
colDict = OrderedDict()
Expand Down Expand Up @@ -371,7 +373,7 @@ def read_units_helper(self):
tableName = row[0]
if tableName not in unitsDict.keys():
unitsDict[tableName] = []
unitsDict[tableName].append(eval(row[1]))
unitsDict[tableName].append((row[1], row[2]))
return unitsDict

# Closes connection to server
Expand Down

0 comments on commit ec7ade5

Please sign in to comment.