bug fix: batch update fixes

pull/1/head
Steve L. Nyemba 4 years ago
parent fa615aa931
commit 5bf2012c59

@ -8,7 +8,7 @@ def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read() return open(os.path.join(os.path.dirname(__file__), fname)).read()
args = { args = {
"name":"data-transport", "name":"data-transport",
"version":"1.3.4", "version":"1.3.6",
"author":"The Phi Technology LLC","author_email":"info@the-phi.com", "author":"The Phi Technology LLC","author_email":"info@the-phi.com",
"license":"MIT", "license":"MIT",
"packages":["transport"]} "packages":["transport"]}

@ -59,6 +59,7 @@ class SQLRW :
@TODO: Store procedure calls @TODO: Store procedure calls
""" """
cursor = self.conn.cursor() cursor = self.conn.cursor()
_out = None
try: try:
if "select" in _sql.lower() : if "select" in _sql.lower() :
cursor.close() cursor.close()
@ -69,6 +70,7 @@ class SQLRW :
self.conn.commit() self.conn.commit()
finally: finally:
self.conn.commit()
cursor.close() cursor.close()
def close(self): def close(self):
try: try:
@ -142,13 +144,14 @@ class SQLWriter(SQLRW,Writer):
if self._cast == False : if self._cast == False :
values = ",".join(_row.values()) values = ",".join(_row.values())
else: else:
values = "'"+"','".join([str(value) for value in _row.values()])+"'" # values = "'"+"','".join([str(value) for value in _row.values()])+"'"
values = [",".join(["%(",name,")s"]) for name in _row.keys()]
# values = [ "".join(["'",str(_row[key]),"'"]) if np.nan(_row[key]).isnumeric() else str(_row[key]) for key in _row] # values = [ "".join(["'",str(_row[key]),"'"]) if np.nan(_row[key]).isnumeric() else str(_row[key]) for key in _row]
# print (values) # print (values)
query = _sql.replace(":fields",",".join(fields)).replace(":values",values) query = _sql.replace(":fields",",".join(fields)).replace(":values",values)
cursor.execute(query) cursor.execute(query,_row.values())
pass pass
@ -160,10 +163,11 @@ class SQLWriter(SQLRW,Writer):
# for row in info : # for row in info :
# values = ["'".join(["",value,""]) if not str(value).isnumeric() else value for value in row.values()] # values = ["'".join(["",value,""]) if not str(value).isnumeric() else value for value in row.values()]
cursor.executemany(_sql,info) cursor.executemany(_sql,info)
self.conn.commit() # self.conn.commit()
except Exception as e: except Exception as e:
print (e) print (e)
finally: finally:
self.conn.commit()
cursor.close() cursor.close()
pass pass
def close(self): def close(self):

Loading…
Cancel
Save