Skip to content

Commit 87e9fac

Browse files
committed
refs #281, Got a little bit of MSAccess working
Duplicate still broken. Out of time to look at it for now
1 parent 204842b commit 87e9fac

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

examples/Flatfile_examples/csv_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pysimplesql as ss
55
import PySimpleGUI as sg
66
import logging
7-
logger=logging.getLogger(__name__)
7+
logger = logging.getLogger(__name__)
88
logging.basicConfig(level=logging.DEBUG)
99

1010
# Let's use a fun language pack
0 Bytes
Binary file not shown.

pysimplesql/pysimplesql.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ def duplicate_record(
19661966
self.frm.popup.ok(
19671967
lang.duplicate_failed_title,
19681968
lang.duplicate_failed.format_map(
1969-
LangFormat(exception=result.exception)
1969+
LangFormat(exception=result.attrs["exception"])
19701970
),
19711971
)
19721972
else:
@@ -7758,10 +7758,10 @@ def execute(
77587758
row[column_name] = value
77597759
rows.append(row)
77607760

7761-
return pd.DataFrame(rows, None, exception, column_info)
7761+
return Result.set(rows, None, exception, column_info)
77627762

77637763
affected_rows = stmt.getUpdateCount()
7764-
return pd.DataFrame([], affected_rows, exception, column_info)
7764+
return Result.set([], affected_rows, exception, column_info)
77657765

77667766
def column_info(self, table):
77677767
meta_data = self.con.getMetaData()
@@ -7852,7 +7852,7 @@ def relationships(self):
78527852

78537853
def max_pk(self, table: str, pk_column: str) -> int:
78547854
rows = self.execute(f"SELECT MAX({pk_column}) as max_pk FROM {table}")
7855-
return rows.fetchone()["MAX_PK"] # returned as upper case
7855+
return rows.iloc[0]["MAX_PK"] # returned as upper case
78567856

78577857
def _get_column_definitions(self, table_name):
78587858
# Creates a comma separated list of column names and types to be used in a
@@ -7862,6 +7862,7 @@ def _get_column_definitions(self, table_name):
78627862
for c in columns:
78637863
cols += f"{c['name']} {c['domain']}, "
78647864
cols = cols[:-2]
7865+
print("\ncols\n", cols)
78657866
return cols
78667867

78677868
def duplicate_record(self, dataset: DataSet, children: bool) -> pd.DataFrame:
@@ -7882,23 +7883,23 @@ def duplicate_record(self, dataset: DataSet, children: bool) -> pd.DataFrame:
78827883
# Create tmp table, update pk column in temp and insert into table
78837884
f"WHERE {pk_column}={dataset.get_current(dataset.pk_column)}"
78847885
query = [
7885-
f"DROP TABLE IF EXISTS [{tmp_table}];",
7886-
f"CREATE TABLE [{tmp_table}] ({self._get_column_definitions(table)});",
7886+
f"DROP TABLE IF EXISTS {tmp_table};",
7887+
f"CREATE TABLE {tmp_table} ({self._get_column_definitions(table)});",
78877888
(
7888-
f"INSERT INTO [{tmp_table}] (SELECT * FROM [{table}] "
7889+
f"INSERT INTO {tmp_table} (SELECT * FROM {table} "
78897890
f"WHERE {pk_column}={dataset.get_current(dataset.pk_column)});"
78907891
),
78917892
(
7892-
f"UPDATE [{tmp_table}] SET {pk_column} = "
7893+
f"UPDATE {tmp_table} SET {pk_column} = "
78937894
f"{self.next_pk(dataset.table, dataset.pk_column)};"
78947895
),
7895-
f"UPDATE [{tmp_table}] SET {description_column} = {description}",
7896-
f"INSERT INTO [{table}] SELECT * FROM [{tmp_table}];",
7897-
f"DROP TABLE IF EXISTS [{tmp_table}]",
7896+
f"UPDATE {tmp_table}]SET {description_column} = {description}",
7897+
f"INSERT INTO {table} SELECT * FROM {tmp_table};",
7898+
f"DROP TABLE IF EXISTS {tmp_table}",
78987899
]
78997900
for q in query:
79007901
res = self.execute(q)
7901-
if res.exception:
7902+
if res.attrs["exception"]:
79027903
return res
79037904

79047905
# Now we save the new pk
@@ -7925,21 +7926,21 @@ def duplicate_record(self, dataset: DataSet, children: bool) -> pd.DataFrame:
79257926
# Update children's pk_columns to NULL and set correct parent
79267927
# PK value.
79277928
queries = [
7928-
f"DROP TABLE IF EXISTS [{tmp_child}]",
7929+
f"DROP TABLE IF EXISTS {tmp_child}",
79297930
(
7930-
f"CREATE TABLE [{tmp_table}] "
7931+
f"CREATE TABLE {tmp_table} "
79317932
f"({self._get_column_definitions(table)});"
79327933
),
79337934
(
7934-
f"INSERT INTO [{tmp_table}] (SELECT * FROM [{table}] "
7935+
f"INSERT INTO {tmp_table} (SELECT * FROM {table} "
79357936
f"WHERE {pk_column}="
79367937
f"{dataset.get_current(dataset.pk_column)});"
79377938
),
79387939
# don't next_pk(), because child can be plural.
7939-
f"UPDATE [{tmp_child}] SET {pk_column} = NULL;",
7940-
f"UPDATE [{tmp_child}] SET {fk_column} = {pk}",
7941-
f"INSERT INTO [{child}] SELECT * FROM [{tmp_child}];",
7942-
f"DROP TABLE IF EXISTS [{tmp_child}]",
7940+
f"UPDATE {tmp_child} SET {pk_column} = NULL;",
7941+
f"UPDATE {tmp_child} SET {fk_column} = {pk}",
7942+
f"INSERT INTO {child} SELECT * FROM {tmp_child};",
7943+
f"DROP TABLE IF EXISTS {tmp_child}",
79437944
]
79447945
for q in queries:
79457946
res = self.execute(q)

0 commit comments

Comments
 (0)