Advertisement
Guest User

Untitled

a guest
Sep 4th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. """
  2. Oracle database connection wrapper
  3. @author: jbaranski
  4. """
  5. import cx_Oracle
  6.  
  7.  
  8. class OracleDB:
  9. """
  10. Usage:
  11. db = OracleDB("user", "pass", "yourserver.com", 1523, "YOUR_SID")
  12. db.connect()
  13. db.cursor.execute("SELECT yourcolumn FROM yourtable")
  14. result1 = [x[0] for x in db.cursor]
  15. db.close()
  16. db.connect()
  17. db.cursor.execute("SELECT yourothercolumn FROM yourothertable")
  18. result2 = [x[0] for x in db.cursor]
  19. db.close()
  20. # do stuff with result1 and result2 ...
  21. """
  22. def __init__(self, user, password, server, port, sid):
  23. self.tns = cx_Oracle.makedsn(server, port, sid)
  24. self.connection = None
  25. self.cursor = None
  26. self.user = user
  27. self.password = password
  28.  
  29. def connect(self):
  30. self.connection = cx_Oracle.connect(self.user, self.password, self.tns)
  31. self.cursor = self.connection.cursor()
  32.  
  33. def close(self):
  34. self.cursor.close()
  35. self.connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement