@@ -1384,9 +1384,9 @@ def set_by_pk(
1384
1384
# don't update self/dependents if we are going to below anyway
1385
1385
self .prompt_save (update_elements = False )
1386
1386
1387
- # Move to the numerical index of where the primary key is located. If the pk
1388
- # value can't be found, move to the last index
1389
- idx = [ i for i , value in enumerate ( self .rows [self .pk_column ]) if value == pk ]
1387
+ # Move to the numerical index of where the primary key is located.
1388
+ # If the pk value can't be found, move to the last index
1389
+ idx = self . rows . sort_index (). index [ self .rows [self .pk_column ] == pk ]. tolist ()
1390
1390
idx = idx [0 ] if idx else len (self .rows .index )
1391
1391
self .current_index = idx
1392
1392
@@ -1683,7 +1683,7 @@ def save_record(
1683
1683
result = self .driver .save_record (
1684
1684
self , q ["changed_row" ], q ["where_clause" ]
1685
1685
)
1686
- if result .exception is not None :
1686
+ if result .attrs [ " exception" ] is not None :
1687
1687
self .frm .popup .ok (
1688
1688
lang .dataset_save_keyed_fail_title ,
1689
1689
lang .dataset_save_keyed_fail .format_map (
@@ -1850,21 +1850,21 @@ def delete_record(
1850
1850
# Delete child records first!
1851
1851
result = self .driver .delete_record (self , True )
1852
1852
1853
- if not isinstance ( result , pd . DataFrame ):
1854
- if result == DELETE_RECURSION_LIMIT_ERROR :
1855
- self . frm . popup . ok (
1856
- lang . delete_failed_title ,
1857
- lang . delete_failed . format_map (
1858
- LangFormat ( exception = lang .delete_recursion_limit_error )
1859
- ),
1860
- )
1861
- elif result . exception is not None :
1862
- self . frm . popup . ok (
1863
- lang . delete_failed_title ,
1864
- lang . delete_failed . format_map (
1865
- LangFormat ( exception = result . exception )
1866
- ),
1867
- )
1853
+ if (
1854
+ not isinstance ( result , pd . DataFrame )
1855
+ and result == DELETE_RECURSION_LIMIT_ERROR
1856
+ ):
1857
+ self . frm . popup . ok (
1858
+ lang .delete_failed_title ,
1859
+ lang . delete_failed . format_map (
1860
+ LangFormat ( exception = lang . delete_recursion_limit_error )
1861
+ ),
1862
+ )
1863
+ elif result . attrs [ "exception" ] is not None :
1864
+ self . frm . popup . ok (
1865
+ lang . delete_failed_title ,
1866
+ lang . delete_failed . format_map ( LangFormat ( exception = result . exception ) ),
1867
+ )
1868
1868
1869
1869
# callback
1870
1870
if "after_delete" in self .callbacks :
@@ -2379,7 +2379,7 @@ def insert_row(self, row: dict, idx: int = None) -> None:
2379
2379
if idx is None :
2380
2380
idx = len (self .rows .index )
2381
2381
idx_label = self .rows .index .max () if len (self .rows .index ) > 0 else 0
2382
- self .rows .attrs ["virtual" ].loc [idx_label ] = True
2382
+ self .rows .attrs ["virtual" ].loc [idx_label ] = 1 # True, series only holds int64
2383
2383
2384
2384
2385
2385
class Form :
@@ -3295,7 +3295,7 @@ def update_elements(
3295
3295
3296
3296
# Disable duplicate if no rows, edit protect, or current row virtual
3297
3297
elif ":table_duplicate" in m ["event" ]:
3298
- disable = (
3298
+ disable = bool (
3299
3299
len (self [data_key ].rows .index ) == 0
3300
3300
or self ._edit_protect
3301
3301
or self [data_key ]
@@ -6533,7 +6533,7 @@ def duplicate_record(self, dataset: DataSet, children: bool) -> pd.DataFrame:
6533
6533
]
6534
6534
for q in queries :
6535
6535
res = self .execute (q )
6536
- if res .exception :
6536
+ if res .attrs [ " exception" ] :
6537
6537
return res
6538
6538
6539
6539
child_duplicated .append (r .child_table )
@@ -6914,7 +6914,7 @@ def save_record(
6914
6914
# Have SQlite save this record
6915
6915
result = super ().save_record (dataset , changed_row , where_clause )
6916
6916
6917
- if result .exception is None :
6917
+ if result .attrs [ " exception" ] is None :
6918
6918
# No it is safe to write our data back out to the CSV file
6919
6919
6920
6920
# Update the DataSet object's DataFra,e with the changes, so then
@@ -7043,7 +7043,7 @@ def execute(
7043
7043
7044
7044
lastrowid = cursor .lastrowid if cursor .lastrowid else None
7045
7045
7046
- return pd . DataFrame (
7046
+ return Result . set (
7047
7047
[dict (row ) for row in rows ], lastrowid , exception , column_info
7048
7048
)
7049
7049
@@ -7052,15 +7052,15 @@ def get_tables(self):
7052
7052
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = %s"
7053
7053
)
7054
7054
rows = self .execute (query , [self .database ], silent = True )
7055
- return [ row [ "TABLE_NAME" ] for row in rows ]
7055
+ return list ( rows [ "TABLE_NAME" ])
7056
7056
7057
7057
def column_info (self , table ):
7058
7058
# Return a list of column names
7059
7059
query = "DESCRIBE {}" .format (table )
7060
7060
rows = self .execute (query , silent = True )
7061
7061
col_info = ColumnInfo (self , table )
7062
7062
7063
- for row in rows :
7063
+ for _ , row in rows . iterrows () :
7064
7064
name = row ["Field" ]
7065
7065
# Check if the value is a bytes-like object, and decode if necessary
7066
7066
type_value = (
@@ -7084,9 +7084,10 @@ def column_info(self, table):
7084
7084
7085
7085
def pk_column (self , table ):
7086
7086
query = "SHOW KEYS FROM {} WHERE Key_name = 'PRIMARY'" .format (table )
7087
- cur = self .execute (query , silent = True )
7088
- row = cur .fetchone ()
7089
- return row ["Column_name" ] if row else None
7087
+ rows = self .execute (query , silent = True )
7088
+ for _ , row in rows .iterrows ():
7089
+ return row ["Column_name" ]
7090
+ return None
7090
7091
7091
7092
def relationships (self ):
7092
7093
# Return a list of dicts {from_table,to_table,from_column,to_column,requery}
@@ -7099,7 +7100,7 @@ def relationships(self):
7099
7100
)
7100
7101
rows = self .execute (query , (from_table ,), silent = True )
7101
7102
7102
- for row in rows :
7103
+ for _ , row in rows . iterrows () :
7103
7104
dic = {}
7104
7105
# Get the constraint information
7105
7106
on_update , on_delete = self .constraint (row ["CONSTRAINT_NAME" ])
@@ -7131,7 +7132,12 @@ def constraint(self, constraint_name):
7131
7132
f"'{ constraint_name } '"
7132
7133
)
7133
7134
rows = self .execute (query , silent = True )
7134
- return rows [0 ]["UPDATE_RULE" ], rows [0 ]["DELETE_RULE" ]
7135
+ for _ , row in rows .iterrows ():
7136
+ if "UPDATE_RULE" in row :
7137
+ update_rule = row ["UPDATE_RULE" ]
7138
+ if "DELETE_RULE" in row :
7139
+ delete_rule = row ["DELETE_RULE" ]
7140
+ return update_rule , delete_rule
7135
7141
7136
7142
7137
7143
# --------------------------------------------------------------------------------------
@@ -7289,7 +7295,7 @@ def execute(
7289
7295
# In Postgres, the cursor does not return a lastrowid. We will not set it here,
7290
7296
# we will instead set it in save_records() due to the RETURNING stement of the
7291
7297
# query
7292
- return pd . DataFrame (
7298
+ return Result . set (
7293
7299
[dict (row ) for row in rows ], exception = exception , column_info = column_info
7294
7300
)
7295
7301
@@ -7300,7 +7306,7 @@ def get_tables(self):
7300
7306
)
7301
7307
# query = "SELECT tablename FROM pg_tables WHERE table_schema='public'"
7302
7308
rows = self .execute (query , silent = True )
7303
- return [ row [ "table_name" ] for row in rows ]
7309
+ return list ( rows [ "table_name" ])
7304
7310
7305
7311
def column_info (self , table : str ) -> ColumnInfo :
7306
7312
# Return a list of column names
@@ -7309,7 +7315,7 @@ def column_info(self, table: str) -> ColumnInfo:
7309
7315
7310
7316
col_info = ColumnInfo (self , table )
7311
7317
pk_column = self .pk_column (table )
7312
- for row in rows :
7318
+ for _ , row in rows . iterrows () :
7313
7319
name = row ["column_name" ]
7314
7320
domain = row ["data_type" ].upper ()
7315
7321
notnull = row ["is_nullable" ] != "YES"
@@ -7334,9 +7340,10 @@ def pk_column(self, table):
7334
7340
"kcu.constraint_name WHERE tc.constraint_type = 'PRIMARY KEY' AND "
7335
7341
f"tc.table_name = '{ table } ' "
7336
7342
)
7337
- cur = self .execute (query , silent = True )
7338
- row = cur .fetchone ()
7339
- return row ["column_name" ] if row else None
7343
+ rows = self .execute (query , silent = True )
7344
+ for _ , row in rows .iterrows ():
7345
+ return row ["column_name" ]
7346
+ return None
7340
7347
7341
7348
def relationships (self ):
7342
7349
# Return a list of dicts {from_table,to_table,from_column,to_column,requery}
@@ -7357,7 +7364,7 @@ def relationships(self):
7357
7364
7358
7365
rows = self .execute (query , (from_table ,), silent = True )
7359
7366
7360
- for row in rows :
7367
+ for _ , row in rows . iterrows () :
7361
7368
dic = {}
7362
7369
# Get the constraint information
7363
7370
# constraint = self.constraint(row['conname'])
@@ -7403,7 +7410,9 @@ def next_pk(self, table: str, pk_column: str) -> int:
7403
7410
# wrap the quoted string in singe quotes. Phew!
7404
7411
q = f"SELECT nextval('{ seq } ') LIMIT 1;"
7405
7412
rows = self .execute (q , silent = True )
7406
- return rows .fetchone ()["nextval" ]
7413
+ for _ , row in rows .iterrows ():
7414
+ return row ["nextval" ]
7415
+ return None
7407
7416
7408
7417
def insert_record (self , table : str , pk : int , pk_column : str , row : dict ):
7409
7418
# insert_record() for Postgres is a little different from the rest. Instead of
@@ -7419,7 +7428,7 @@ def insert_record(self, table: str, pk: int, pk_column: str, row: dict):
7419
7428
values = [value for key , value in row .items ()]
7420
7429
result = self .execute (query , tuple (values ))
7421
7430
7422
- result .lastid = pk
7431
+ result .attrs [ " lastid" ] = pk
7423
7432
return result
7424
7433
7425
7434
def execute_script (self , script ):
0 commit comments