Skip to content

Commit 3623e51

Browse files
author
fpremoli
committed
change query e rowcount return e error handling
1 parent fbbf269 commit 3623e51

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/DatabaseLibrary/query.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,21 @@ def query(self,alias, selectStatement, sansTran=False, returnAsDict=False):
6868
mappedRows = []
6969
col_names = [c[0] for c in cur.description]
7070

71+
7172
for rowIdx in range(len(allRows)):
7273
d = {}
7374
for colIdx in range(len(allRows[rowIdx])):
7475
d[col_names[colIdx]] = allRows[rowIdx][colIdx]
7576
mappedRows.append(d)
76-
return mappedRows
77+
return 'DONE',mappedRows
7778

78-
return allRows
79+
return 'DONE',allRows
80+
except Exception as Err:
81+
logger.info('Error: %s' % Err)
82+
return 'ERROR',None
7983
finally:
8084
if cur:
81-
if not sansTran:
85+
if not sansTran:
8286
connection.rollback()
8387

8488
def row_count(self,alias, selectStatement, sansTran=False):
@@ -118,8 +122,11 @@ def row_count(self,alias, selectStatement, sansTran=False):
118122
if self.db_api_module_name in ["sqlite3", "ibm_db", "ibm_db_dbi", "pyodbc"]:
119123
rowCount = len(data)
120124
else:
121-
rowCount = cur.rowcount
122-
return rowCount
125+
rowCount = cur.rowcount
126+
return 'DONE',rowCount
127+
except Exception as Err:
128+
logger.info('Error: %s' % Err)
129+
return 'ERROR',None
123130
finally:
124131
if cur:
125132
if not sansTran:

0 commit comments

Comments
 (0)