From ec7ade50824e63d8aec4fba64ecd0f93577ec853 Mon Sep 17 00:00:00 2001 From: Vedant P Iyer Date: Wed, 27 Nov 2024 12:33:59 -0700 Subject: [PATCH] updated sqlite units table to separate column name and unit --- dsi/backends/sqlite.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dsi/backends/sqlite.py b/dsi/backends/sqlite.py index 46564d7..b39d3e6 100644 --- a/dsi/backends/sqlite.py +++ b/dsi/backends/sqlite.py @@ -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: @@ -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() @@ -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