Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cx_Oracle
- class Oracle:
- def __init__(self, username, password, database):
- self.username = username
- self.password = password
- self.database = database
- def __enter__(self):
- self.connection = cx_Oracle.connect(self.username, self.password, self.database)
- self.cursor = self.connection.cursor()
- return self
- def __exit__(self, exc_type, exc_val, exc_tb):
- self.cursor.close()
- self.connection.close()
- def fetchall(self, query):
- self.cursor.execute(query)
- return self.cursor.fetchall()
- # Simple usage
- with Oracle('test', 'test', 'test') as oracle:
- query = "SELECT * FROM test"
- result = oracle.fetchall(query)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement