From df08adbc16186bb170e195e88a05e68623bd1bce Mon Sep 17 00:00:00 2001 From: gadorlhiac Date: Thu, 11 Apr 2024 11:05:41 -0700 Subject: [PATCH] BUG Escape column names in Task tables, for unsupported characters --- lute/io/_sqlite.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lute/io/_sqlite.py b/lute/io/_sqlite.py index 889466a1..a65cdfb8 100644 --- a/lute/io/_sqlite.py +++ b/lute/io/_sqlite.py @@ -157,7 +157,8 @@ def _make_task_table( current_cols: Dict[str, str] = _get_table_cols(con, task_name) if diff := _compare_cols(current_cols, columns): for col in diff.items(): - sql: str = f"ALTER TABLE {task_name} ADD COLUMN {col[0]} {col[1]}" + sql: str = f'ALTER TABLE {task_name} ADD COLUMN "{col[0]}" {col[1]}' + logger.debug(f"_make_task_table[ALTER]: {sql}") with con: con.execute(sql) @@ -172,6 +173,7 @@ def _make_task_table( "valid_flag INTEGER)" ) sql: str = f"CREATE TABLE IF NOT EXISTS {db_str}" + logger.debug(f"_make_task_table[CREATE]: {sql}") with con: con.execute(sql) return _does_table_exist(con, task_name) @@ -214,14 +216,15 @@ def _add_task_entry( entry (Dict[str, Any]): A dictionary of entries in the format of {COLUMN: ENTRY}. These are assumed to match the columns of the table. """ - placeholder_str: str = ", ".join("?" for x in range(len(entry))) + placeholder_str: str = ", ".join("?" for _ in range(len(entry))) keys: List[str] = [] values: List[str] = [] for key, value in entry.items(): keys.append(f'"{key}"') values.append(value) with con: - ins_str: str = "".join(f':"{x}", ' for x in entry.keys())[:-2] + # ins_str: str = "".join(f':"{x}", ' for x in entry.keys())[:-2] + logger.debug(f"_add_task_entry: {keys}\n\t\t{values}") res = con.execute( f"INSERT INTO {task_name} ({','.join(keys)}) VALUES ({placeholder_str})", values,