-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoracledb.py
More file actions
39 lines (34 loc) · 1.14 KB
/
oracledb.py
File metadata and controls
39 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Oracle Database Connection Wrapper.
@author: Mohamed Riyad <@RyadPasha>
@url: http://ryadpasha.com
@email: me@ryadpasha.com
@license: MIT License
"""
import cx_Oracle
class OracleDB:
"""
Usage:
db = OracleDB("user", "pass", "yourserver.com", 1523, "YOUR_SID")
db.connect()
db.cursor.execute("SELECT yourcolumn FROM yourtable")
result1 = [x[0] for x in db.cursor]
db.close()
db.connect()
db.cursor.execute("SELECT yourothercolumn FROM yourothertable")
result2 = [x[0] for x in db.cursor]
db.close()
# do stuff with result1 and result2 ...
"""
def __init__(self, user, password, server, port, sid):
self.tns = cx_Oracle.makedsn(server, port, sid)
self.connection = None
self.cursor = None
self.user = user
self.password = password
def connect(self):
self.connection = cx_Oracle.connect(self.user, self.password, self.tns)
self.cursor = self.connection.cursor()
def close(self):
self.cursor.close()
self.connection.close()