Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cx_Oracle
- import logging
- class Oracle(object):
- """
- Connector class to connect to Oracle database and run queries
- """
- def __init__(self, db_config):
- # mode should be 0 if not cx_Oracle.SYSDBA
- self.logger = logging.getLogger(__name__)
- if db_config:
- self.username = db_config["username"]
- self.password = db_config["password"]
- self.host = db_config["host"]
- self.port = db_config["port"]
- self.sid = db_config["sid"]
- self.mode = int(db_config["mode"])
- self._cursor = None
- self._connection = None
- self.connect_string = self.username + '/' + self.password + '@' + self.host + ':' + self.port + '/' + self.sid
- try:
- self._connection = cx_Oracle.connect(self.connect_string, mode=self.mode, threaded=True)
- self._cursor = self._connection.cursor()
- self.idVar = self._cursor.var(cx_Oracle.NUMBER)
- except Exception as e:
- print "Exception while trying to initialize database connection object : ", e
- else:
- raise DbConfigNotFoundException
- def param_query(self, q, param):
- try:
- self._cursor.execute(q, param)
- return self._cursor.fetchall()
- except Exception as e:
- logger.exception(e)
- raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement