Skip to content

Commit 32266f1

Browse files
committed
refs #281, Duplicate record working
Duplicating records working once again
1 parent 28118ed commit 32266f1

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

examples/SQLite_examples/Journal.db

0 Bytes
Binary file not shown.

pysimplesql/pysimplesql.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ def duplicate_record(
19461946

19471947
# Have the driver duplicate the record
19481948
result = self.driver.duplicate_record(self, children)
1949-
if result.exception:
1949+
if result.attrs["exception"]:
19501950
self.driver.rollback()
19511951
self.frm.popup.ok(
19521952
lang.duplicate_failed_title,
@@ -1955,7 +1955,7 @@ def duplicate_record(
19551955
),
19561956
)
19571957
else:
1958-
pk = result.lastrowid
1958+
pk = result.attrs["lastrowid"]
19591959

19601960
# callback
19611961
if "after_duplicate" in self.callbacks:
@@ -2203,6 +2203,7 @@ def sort_by_column(self, column: str, table: str, reverse=False) -> None:
22032203

22042204
# We don't want to sort by foreign keys directly - we want to sort by the
22052205
# description column of the foreign table that the foreign key references
2206+
tmp_column = None
22062207
rels = Relationship.get_relationships(table)
22072208
for rel in rels:
22082209
if column == rel.fk_column:
@@ -2212,9 +2213,9 @@ def sort_by_column(self, column: str, table: str, reverse=False) -> None:
22122213
mapping = dict(zip(df_parent[rel.pk_column], df_parent[desc_parent]))
22132214

22142215
# Create a temporary column in self.rows for the fk data
2215-
tmp = f"temp_{rel.parent_table}.{rel.pk_column}"
2216-
self.rows[tmp] = self.rows[rel.fk_column].map(mapping)
2217-
column = tmp
2216+
tmp_column = f"temp_{rel.parent_table}.{rel.pk_column}"
2217+
self.rows[tmp_column] = self.rows[rel.fk_column].map(mapping)
2218+
column = tmp_column
22182219
break
22192220
try:
22202221
self.rows.sort_values(
@@ -2226,7 +2227,8 @@ def sort_by_column(self, column: str, table: str, reverse=False) -> None:
22262227
logger.debug(f"DataFrame could not sort by column {column}. KeyError.")
22272228
finally:
22282229
# Drop the temporary description column (if it exists)
2229-
self.rows.drop(columns=tmp, inplace=True, errors="ignore")
2230+
if tmp_column is not None:
2231+
self.rows.drop(columns=tmp, inplace=True, errors="ignore")
22302232

22312233
def sort_by_index(self, index: int, table: str, reverse=False):
22322234
"""
@@ -6019,7 +6021,7 @@ class Result:
60196021
@classmethod
60206022
def set(
60216023
cls,
6022-
row_data: dict,
6024+
row_data: dict = None,
60236025
lastrowid: int = None,
60246026
exception: Exception = None,
60256027
column_info: ColumnInfo = None,
@@ -6465,11 +6467,11 @@ def duplicate_record(self, dataset: DataSet, children: bool) -> pd.DataFrame:
64656467
]
64666468
for q in query:
64676469
res = self.execute(q)
6468-
if res.exception:
6470+
if res.attrs["exception"]:
64696471
return res
64706472

64716473
# Now we save the new pk
6472-
pk = res.lastrowid
6474+
pk = res.attrs["lastrowid"]
64736475

64746476
# create list of which children we have duplicated
64756477
child_duplicated = []

0 commit comments

Comments
 (0)