Advertisement
Guest User

Untitled

a guest
Mar 30th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import cx_Oracle
  2. import logging
  3.  
  4. class Oracle(object):
  5. """
  6. Connector class to connect to Oracle database and run queries
  7. """
  8. def __init__(self, db_config):
  9. # mode should be 0 if not cx_Oracle.SYSDBA
  10. self.logger = logging.getLogger(__name__)
  11. if db_config:
  12. self.username = db_config["username"]
  13. self.password = db_config["password"]
  14. self.host = db_config["host"]
  15. self.port = db_config["port"]
  16. self.sid = db_config["sid"]
  17. self.mode = int(db_config["mode"])
  18. self._cursor = None
  19. self._connection = None
  20. self.connect_string = self.username + '/' + self.password + '@' + self.host + ':' + self.port + '/' + self.sid
  21. try:
  22. self._connection = cx_Oracle.connect(self.connect_string, mode=self.mode, threaded=True)
  23. self._cursor = self._connection.cursor()
  24. self.idVar = self._cursor.var(cx_Oracle.NUMBER)
  25. except Exception as e:
  26. print "Exception while trying to initialize database connection object : ", e
  27. else:
  28. raise DbConfigNotFoundException
  29.  
  30. def param_query(self, q, param):
  31. try:
  32. self._cursor.execute(q, param)
  33. return self._cursor.fetchall()
  34. except Exception as e:
  35. logger.exception(e)
  36. raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement