Skip to content

Commit

Permalink
fix ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Caha committed Sep 6, 2024
1 parent 4d46c7f commit 38da02f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions workpackages/remapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def remap_table_wp_to_master(cursor, table_name, wp_name, new_master_fid):
wp_fids_missing = set()
sql = (
f"""SELECT {pkey_column_escaped} FROM {table_name_escaped} """
f"""LEFT JOIN {remap_table} AS mapped ON fid = mapped.wp_fid WHERE mapped.master_fid IS NULL"""
f"""LEFT JOIN {remap_table} AS mapped ON {pkey_column_escaped} = mapped.wp_fid WHERE mapped.master_fid IS NULL"""
)
for row in cursor.execute(sql):
wp_fids_missing.add(row[0])
Expand All @@ -131,7 +131,7 @@ def remap_table_wp_to_master(cursor, table_name, wp_name, new_master_fid):
mapping = [] # list of tuples (wp_fid, master_fid)
sql = (
f"""SELECT {pkey_column_escaped}, mapped.master_fid FROM {table_name_escaped} """
f"""LEFT JOIN {remap_table} AS mapped ON fid = mapped.wp_fid"""
f"""LEFT JOIN {remap_table} AS mapped ON {pkey_column_escaped} = mapped.wp_fid"""
)
for row in cursor.execute(sql):
mapping.append((row[0], row[1]))
Expand All @@ -141,5 +141,6 @@ def remap_table_wp_to_master(cursor, table_name, wp_name, new_master_fid):

for wp_fid, master_fid in mapping:
cursor.execute(
f"""UPDATE {table_name_escaped} SET {pkey_column_escaped} = ? WHERE fid = ?""", (master_fid, -wp_fid)
f"""UPDATE {table_name_escaped} SET {pkey_column_escaped} = ? WHERE {pkey_column_escaped} = ?""",
(master_fid, -wp_fid),
)
6 changes: 4 additions & 2 deletions workpackages/wp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import yaml

from .wp_utils import escape_double_quotes
from .remapping import remap_table_master_to_wp, remap_table_wp_to_master
from .remapping import remap_table_master_to_wp, remap_table_wp_to_master, _table_pkey

# Layout of files:
#
Expand Down Expand Up @@ -191,7 +191,9 @@ def _logger_callback(level, text_bytes):
for wp_table in wp_config.wp_tables:
wp_table_name = wp_table.name
wp_tab_name_esc = escape_double_quotes(wp_table_name)
c.execute(f"""SELECT max(fid) FROM {wp_tab_name_esc};""")
pkey_column = _table_pkey(c, wp_table_name)
pkey_column_escaped = escape_double_quotes(pkey_column)
c.execute(f"""SELECT max({pkey_column_escaped}) FROM {wp_tab_name_esc};""")
new_master_fid = c.fetchone()[0]
if new_master_fid is None:
new_master_fid = 1 # empty table so far
Expand Down

0 comments on commit 38da02f

Please sign in to comment.