/usr/share/pyshared/adodb/adodb_oci8.py is in python-adodb 2.10-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | ########################################################################
# Vers 2.10 16 July 2008, (c)2004-2008 John Lim (jlim#natsoft.com) All Rights Reserved
# Released under a BSD-style license. See LICENSE.txt.
# Download: http://adodb.sourceforge.net/#pydownload
########################################################################
import adodb
from adodb import ADOConnection,ADOCursor
import cx_Oracle
# threadsafety=2 (connections)
# paramstyle=named (:name)
try:
True, False
except NameError:
# Maintain compatibility with Python 2.2
True, False = 1, 0
class adodb_oci8(adodb.ADOConnection):
databaseType = 'oci8'
dataProvider = 'oci8'
replaceQuote = "''"
metaColSQL = "select cname,coltype,width from col where tname='%s' order by colno"
sysDate = 'trunc(SYSDATE)'
sysTimeStamp = 'SYSDATE'
NLS_DATE_FORMAT = 'YYYY-MM-DD' ## To include time, use 'RRRR-MM-DD HH24:MI:SS'
def __init__(self):
pass
def Module(self):
return cx_Oracle
def _connect(self,host=None,user=None,password=None,database=None):
if user == None and password == None and database == None:
self._conn = cx_Oracle.connect('','',host)
else:
if host == None: self._conn = cx_Oracle.connect(user,password)
else: self._conn = cx_Oracle.connect(user,password,host)
self._query("ALTER SESSION SET NLS_DATE_FORMAT='"+self.NLS_DATE_FORMAT+"'")
def _newcursor(self,rs):
if self._autocommit: self._conn.commit()
rs = cursor_oci8(rs,self)
if rs._isselect: rs._rowcount = -1 # oci8 does not return recordcount
return rs
def BeginTrans(self):
if self._autocommit:
self._autocommit = False
def RollbackTrans(self):
self._conn.rollback()
self._autocommit = True
def CommitTrans(self):
self._conn.commit()
self._autocommit = True
# offset not supported
def SelectLimit(self,sql,limit,offset=-1,params=None):
if offset == -1:
return self.Execute("select * from ("+sql+") where rownum <= "+str(limit), params)
else:
raise StandardError, "SelectLimit does not support offset: " + sql
def DBDate(self,d):
if d == None: return 'null'
return "TO_DATE(%s,'%s')" % (d.strftime(self.fmtDate),self.NLS_DATE_FORMAT)
def DBTimeStamp(self,d):
if d == None: return 'null'
return "TO_DATE(%s,'%s')" % (d.strftime(self.fmtTimeStamp),self.NLS_DATE_FORMAT)
def UpdateBlob(self,table,field,blob,where,blobtype='BLOB'):
cursor = self._conn.cursor()
#self.debug = True
if blobtype == 'BLOB':
bt = cx_Oracle.BLOB
else:
bt = cx_Oracle.CLOB
cursor.setinputsizes(adodblob = bt)
sql = "update %s set %s=:%s WHERE %s" % (table,field,'adodblob',where)
self._query(sql,{'adodblob': blob},_cursor = cursor)
def GetAll(self,sql,params=None):
c = self._query(sql,params)
if c == None: return None
if self.getLOBs:
rows = []
while 1:
row = c.fetchone()
if row == None: break
rows.append(self._fixblobs(c.description,row))
return rows
else:
return c.fetchall()
def GetRow(self,sql,params=None):
c = self._query(sql,params)
if c == None: return None
arr = c.fetchone()
return self._fixblobs(c.description,arr)
def GetOne(self,sql,params=None):
c = self._query(sql,params)
if c == None: return None
arr = c.fetchone()
if (arr == None): return None
if (c.description[0][1] == cx_Oracle.BLOB or c.description[0][1] == cx_Oracle.CLOB):
return arr[0].read()
return arr[0]
def _hasblobs(self,description):
for fld in description:
t = fld[1]
if t == cx_Oracle.BLOB or t == cx_Oracle.CLOB:
return True
return False
def _fixblobs(self,description,row):
if not row: return row
arr = []
i = 0
for fld in description:
t = fld[1]
if t == cx_Oracle.BLOB or t == cx_Oracle.CLOB:
try:
lob_fld=row.read()
except:
arr.append(None)
else:
arr.append(lob_fld)
else:
arr.append(row[i])
i += 1
return arr
def MetaType(self, dtype):
dtype = dtype.upper()
if dtype == 'DATE':
return 'T'
return ADOConnection.MetaType(self, dtype)
def MetaColumns(self, table):
sql = self.metaColSQL % table.upper()
return self.GetAll(sql)
class cursor_oci8(adodb.ADOCursor):
getLOBs = None
def __init__(self,rs,conn):
if conn.getLOBs and rs.description:
# print rs.description
self.getLOBs = conn._hasblobs(rs.description)
else:
self.getLOBs = False
ADOCursor.__init__(self,rs,conn)
def MoveNext(self):
self.fields = self._cursor.fetchone()
self.EOF = (self.fields == None)
if self.getLOBs and not self.EOF:
self.fields = self._conn._fixblobs(self._cursor.description,self.fields)
return self.EOF
def FetchRow(self):
row = self.fields
self.fields = self._cursor.fetchone()
self.EOF = (self.fields == None)
if self.getLOBs and not self.EOF:
self.fields = self._conn._fixblobs(self._cursor.description,self.fields)
return row
if __name__ == '__main__':
db = adodb_oci8()
db.Connect('','scott','natsoft')
adodb.Test(db)
print db.MetaType('date')
print db.MetaType('VarChar')
print db.MetaType('DECiMAL')
#adodb.Test_Blob(db)
|