|
|
@ -93,7 +93,7 @@ class SQLRW :
|
|
|
|
found = False
|
|
|
|
found = False
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
|
|
table = self._tablename(_args['table'])
|
|
|
|
table = self._tablename(_args['table'])if 'table' in _args else self._tablename(self.table)
|
|
|
|
sql = "SELECT * FROM :table LIMIT 1".replace(":table",table)
|
|
|
|
sql = "SELECT * FROM :table LIMIT 1".replace(":table",table)
|
|
|
|
if self._engine :
|
|
|
|
if self._engine :
|
|
|
|
_conn = self._engine.connect()
|
|
|
|
_conn = self._engine.connect()
|
|
|
@ -192,9 +192,9 @@ class SQLWriter(SQLRW,Writer):
|
|
|
|
fields = _args['fields']
|
|
|
|
fields = _args['fields']
|
|
|
|
# table = self._tablename(self.table)
|
|
|
|
# table = self._tablename(self.table)
|
|
|
|
sql = " ".join(["CREATE TABLE",table," (", ",".join([ name +' '+ self._dtype for name in fields]),")"])
|
|
|
|
sql = " ".join(["CREATE TABLE",table," (", ",".join([ name +' '+ self._dtype for name in fields]),")"])
|
|
|
|
print (sql)
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
schema = _args['schema']
|
|
|
|
schema = _args['schema'] if 'schema' in _args else ''
|
|
|
|
|
|
|
|
|
|
|
|
_map = _args['map'] if 'map' in _args else {}
|
|
|
|
_map = _args['map'] if 'map' in _args else {}
|
|
|
|
sql = [] # ["CREATE TABLE ",_args['table'],"("]
|
|
|
|
sql = [] # ["CREATE TABLE ",_args['table'],"("]
|
|
|
@ -214,7 +214,7 @@ class SQLWriter(SQLRW,Writer):
|
|
|
|
cursor.execute(sql)
|
|
|
|
cursor.execute(sql)
|
|
|
|
except Exception as e :
|
|
|
|
except Exception as e :
|
|
|
|
print (e)
|
|
|
|
print (e)
|
|
|
|
print (sql)
|
|
|
|
# print (sql)
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
# cursor.close()
|
|
|
|
# cursor.close()
|
|
|
@ -296,18 +296,18 @@ class SQLWriter(SQLRW,Writer):
|
|
|
|
_info = pd.DataFrame(info)
|
|
|
|
_info = pd.DataFrame(info)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if self._engine :
|
|
|
|
if self._engine :
|
|
|
|
# # pd.to_sql(_info,self._engine)
|
|
|
|
# pd.to_sql(_info,self._engine)
|
|
|
|
# print (_info.columns.tolist())
|
|
|
|
|
|
|
|
# rows = _info.to_sql(table,self._engine,if_exists='append',index=False)
|
|
|
|
rows = _info.to_sql(table,self._engine,if_exists='append',index=False)
|
|
|
|
# print ([rows])
|
|
|
|
|
|
|
|
# else:
|
|
|
|
else:
|
|
|
|
_fields = ",".join(self.fields)
|
|
|
|
_fields = ",".join(self.fields)
|
|
|
|
_sql = _sql.replace(":fields",_fields)
|
|
|
|
_sql = _sql.replace(":fields",_fields)
|
|
|
|
values = ", ".join("?"*len(self.fields)) if self._provider == 'netezza' else ",".join(["%s" for name in self.fields])
|
|
|
|
values = ", ".join("?"*len(self.fields)) if self._provider == 'netezza' else ",".join(["%s" for name in self.fields])
|
|
|
|
_sql = _sql.replace(":values",values)
|
|
|
|
_sql = _sql.replace(":values",values)
|
|
|
|
|
|
|
|
|
|
|
|
cursor.executemany(_sql,_info.values.tolist())
|
|
|
|
cursor.executemany(_sql,_info.values.tolist())
|
|
|
|
# cursor.commit()
|
|
|
|
# cursor.commit()
|
|
|
|
|
|
|
|
|
|
|
|
# self.conn.commit()
|
|
|
|
# self.conn.commit()
|
|
|
|