I have below code. In the first function am creating database connection. And in last function am inserting the data into a table. Since am not committing the records, data is not getting committed in the database. If I return both cursor and connection as, return cur, conn, how do I access them in another function
import cx_Oracle
class transformation():
def oracle_conn(self):
con = cx_Oracle.connect('user/password@localhost:1521/xe')
cur = con.cursor()
return cur
def extract(self):
data = self.oracle_conn().execute('select * from employees').fetchall()
return [(row) for row in data]
def load(self):
values = self.expression()
query = 'INSERT INTO hr.employees_python (EMPLOYEE_ID, NAME, EMAIL, ' \
'PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY, MONTH, ' \
'DAY, YEAR) values (:0, :1, :2, :3, :4, :5, :6, :7, :8, :9)'
self.oracle_conn().executemany(query, values)
a = transformation()
a.load()
Any suggestion will be helpful.
self.cur = ...