Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions scripts/ilapfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,17 +718,20 @@ def does_column_exist_in_db(path, table_name, col_name):
'''Checks if a specific col exists'''
db = open_sqlite_db_readonly(path)
col_name = col_name.lower()
try:
db.row_factory = sqlite3.Row # For fetching columns by name
if db:
query = f"pragma table_info('{table_name}');"
cursor = db.cursor()
cursor.execute(query)
all_rows = cursor.fetchall()
for row in all_rows:
if row['name'].lower() == col_name:
return True
except sqlite3.Error as ex:
logfunc(f"Query error, query={query} Error={str(ex)}")
try:
db.row_factory = sqlite3.Row # For fetching columns by name
cursor = db.cursor()
cursor.execute(query)
all_rows = cursor.fetchall()
for row in all_rows:
if row['name'].lower() == col_name:
return True
except sqlite3.Error as ex:
logfunc(f"Query error, query={query} Error={str(ex)}")
finally:
db.close()
return False

def does_table_exist_in_db(path, table_name):
Expand All @@ -742,6 +745,8 @@ def does_table_exist_in_db(path, table_name):
return True
except sqlite3.Error as ex:
logfunc(f"Query error, query={query} Error={str(ex)}")
finally:
db.close()
return False

def null_absent_columns(path, query):
Expand All @@ -767,21 +772,26 @@ def null_absent_columns(path, query):
return query

replaced = []
for _ in range(50): # a query cannot need more than this
try:
db.execute('EXPLAIN ' + query)
break
except sqlite3.OperationalError as ex:
match = re.match(r'no such column:\s*(\S+)', str(ex))
if not match:
try:
for _ in range(50): # a query cannot need more than this
try:
db.execute('EXPLAIN ' + query)
break
except sqlite3.OperationalError as ex:
match = re.match(r'no such column:\s*(\S+)', str(ex))
if not match:
break
reference = match.group(1)
if reference in replaced:
break # not making progress, leave it alone
replaced.append(reference)
query = _null_out_column(query, reference)
except sqlite3.Error:
break
reference = match.group(1)
if reference in replaced:
break # not making progress, leave it alone
replaced.append(reference)
query = _null_out_column(query, reference)
except sqlite3.Error:
break
finally:
# Artifacts call this once per query, so an unclosed handle here is one
# leak per query for the whole run rather than a one-off.
db.close()

if replaced:
logfunc(f'{os.path.basename(path)}: column(s) absent from this version are reported '
Expand Down Expand Up @@ -820,6 +830,8 @@ def does_view_exist_in_db(path, table_name):
return True
except sqlite3.Error as ex:
logfunc(f"Query error, query={query} Error={str(ex)}")
finally:
db.close()
return False


Expand Down
Loading