import petl as etl
from sqlalchemy import create_engine
import cx_Oracle
ORACLE_CONNECT = "the connection string for target oracle"
engine = create_engine('the connection string for source oracle')
connection = engine.connect()
#connection = cx_Oracle.connect(ORACLE_CONNECT)
class CursorProxy(object):
def __init__(self, cursor):
self._cursor = cursor
def executemany(self, statement, parameters, **kwargs):
# convert parameters to a list
parameters = list(parameters)
# check clob
print(statement)
input_sizes = {}
input_sizes[1] = cx_Oracle.CLOB
#for row in list(parameters):
#print(row)
#for k, v in row.items():
# if isinstance(v, basestring) and len(v) > 2000:
# input_sizes[k] = cx_Oracle.CLOB
self._cursor.setinputsizes(**input_sizes)
# pass through to proxied cursor
return self._cursor.executemany(statement, parameters, **kwargs)
def __getattr__(self, item):
return getattr(self._cursor, item)
def get_cursor():
return CursorProxy(cx_Oracle.connect(ORACLE_CONNECT).cursor())
table = etl.fromdb(connection, 'SELECT ID , BIG_TEXT FROM RESEARCH WHERE ROWNUM <= 10')
table = etl.rename(table,{'id': 'ID', 'big_text': 'BIG_TEXT'})
etl.todb(table, get_cursor(), 'TESTAAAAA', commit=True, dialect='oracle')