provide wrapper function for DROP TABLE

Use psycopg2 formatting to ensure correct quoting.
This commit is contained in:
Sarah Hoffmann
2021-07-12 20:32:46 +02:00
parent cf98cff2a1
commit 06602b4ec0
5 changed files with 26 additions and 16 deletions

View File

@@ -141,6 +141,6 @@ def get_url(url):
try:
with urlrequest.urlopen(urlrequest.Request(url, headers=headers)) as response:
return response.read().decode('utf-8')
except:
except Exception:
LOG.fatal('Failed to load URL: %s', url)
raise

View File

@@ -29,7 +29,7 @@ def drop_update_tables(conn):
tables = [r[0] for r in cur]
for table in tables:
cur.execute('DROP TABLE IF EXISTS "{}" CASCADE'.format(table))
cur.drop_table(table, cascade=True)
conn.commit()

View File

@@ -49,7 +49,7 @@ def load_address_levels(conn, table, levels):
_add_address_level_rows_from_entry(rows, entry)
with conn.cursor() as cur:
cur.execute('DROP TABLE IF EXISTS {}'.format(table))
cur.drop_table(table)
cur.execute("""CREATE TABLE {} (country_code varchar(2),
class TEXT,

View File

@@ -248,20 +248,14 @@ class SPImporter():
Delete the place_classtype tables.
"""
LOG.warning('Cleaning database...')
# Array containing all queries to execute.
# Contains tuples of format (query, parameters)
queries_parameters = []
# Delete place_classtype tables corresponding to class/type which
# are not on the wiki anymore.
for table in self.table_phrases_to_delete:
self.statistics_handler.notify_one_table_deleted()
query = SQL('DROP TABLE IF EXISTS {}').format(Identifier(table))
queries_parameters.append((query, ()))
with self.db_connection.cursor() as db_cursor:
for query, parameters in queries_parameters:
db_cursor.execute(query, parameters)
for table in self.table_phrases_to_delete:
self.statistics_handler.notify_one_table_deleted()
db_cursor.drop_table(table)
def _convert_php_settings_if_needed(self, file_path):
"""