>>> print db.version
10.2.0.1.0
>>> versioning = db.version.split('.')
>>> print versioning
['10', '2', '0', '1', '0']
>>> if versioning[0]=='10':
... print "Running 10g"
... elif versioning[0]=='9':
... print "Running 9i"
...
Running 10g
>>> print db.dsn
localhost:1521/XE
Oracle
|
cx_Oracle
|
Python
|
VARCHAR2
NVARCHAR2 LONG |
cx_Oracle.STRING
|
str
|
CHAR
|
cx_Oracle.FIXED_CHAR
|
|
NUMBER
|
cx_Oracle.NUMBER
|
int
|
FLOAT
|
float
|
|
DATE
|
cx_Oracle.DATETIME
|
datetime.datetime
|
TIMESTAMP
|
cx_Oracle.TIMESTAMP
|
|
CLOB
|
cx_Oracle.CLOB
|
cx_Oracle.LOB
|
BLOB
|
cx_Oracle.BLOB
|
>>> create_table = """
CREATE TABLE python_modules (
module_name VARCHAR2(50) NOT NULL,
file_path VARCHAR2(300) NOT NULL
)
"""
>>> from sys import modules
>>> cursor.execute(create_table)
>>> M = []
>>> for m_name, m_info in modules.items():
... try:
... M.append((m_name, m_info.__file__))
... except AttributeError:
... pass
...
>>> len(M)
76
>>> cursor.prepare("INSERT INTO python_modules(module_name, file_path) VALUES (:1, :2)")
>>> cursor.executemany(None, M)
>>> db.commit()
>>> r = cursor.execute("SELECT COUNT(*) FROM python_modules")
>>> print cursor.fetchone()
(76,)
>>> cursor.execute("DROP TABLE python_modules PURGE")