Update of /cvsroot/pywin32/pywin32/adodbapi
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv16778
Modified Files:
Tag: py3k
adodbapi.py readme.txt
Log Message:
version 2.2.4 after running thru 2to3
Index: adodbapi.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/adodbapi/adodbapi.py,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -C2 -d -r1.2.2.2 -r1.2.2.3
*** adodbapi.py 13 Nov 2008 04:28:21 -0000 1.2.2.2
--- adodbapi.py 8 Dec 2008 21:35:05 -0000 1.2.2.3
***************
*** 1,4 ****
! """adodbapi v2.2.3 - A python DB API 2.0 interface to Microsoft ADO
!
Copyright (C) 2002 Henrik Ekelund
Email: <http://sourceforge.net/sendmessage.php?touser=618411>
--- 1,4 ----
! """adodbapi v2.2.4(after 2to3) - A python DB API 2.0 interface to Microsoft ADO
! !!! 2to3 has been run on this source !!!
Copyright (C) 2002 Henrik Ekelund
Email: <http://sourceforge.net/sendmessage.php?touser=618411>
***************
*** 18,28 ****
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! version 2.1 by Vernon Cole -- update for Decimal data type
all uses of "verbose" below added by Cole for v2.1
- version 2.2.3 update for Python 3, require python 2.6 or later
"""
- from __future__ import print_function
- from __future__ import unicode_literals
-
# N.O.T.E.:...
# if you have been using an older version of adodbapi and are getting errors because
--- 18,25 ----
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! version 2.1 (and later) by Vernon Cole -- update for Decimal data type
! (requires Python 2.4 or above or or Python 2.3 with "import win32com.decimal_23")
all uses of "verbose" below added by Cole for v2.1
"""
# N.O.T.E.:...
# if you have been using an older version of adodbapi and are getting errors because
***************
*** 39,52 ****
import traceback
import datetime
! import decimal
try:
import win32com.client
! def Dispatch(dispatch):
! return win32com.client.Dispatch(dispatch)
! win32 = True
! DBNull = type(None)
! DateTime = type(NotImplemented) #impossible value
except ImportError: # implies running on IronPython
from System import Activator, Type, DBNull, DateTime, Array, Byte
from System import Decimal as SystemDecimal
--- 36,53 ----
import traceback
import datetime
!
! try:
! import decimal
! except ImportError: #perhaps running Cpython 2.3
! import win32com.decimal_23 as decimal
try:
import win32com.client
! onIronPython = False
except ImportError: # implies running on IronPython
+ onIronPython = True
+
+ # --- define objects to smooth out IronPython <-> CPython differences
+ if onIronPython:
from System import Activator, Type, DBNull, DateTime, Array, Byte
from System import Decimal as SystemDecimal
***************
*** 55,69 ****
type = Type.GetTypeFromProgID(dispatch)
return Activator.CreateInstance(type)
! win32 = False #implies IronPython
!
! if win32:
import pythoncom
pythoncom.__future_currency__ = True
! try:
! memoryViewType = memoryview # will work in p3k
! except:
! memoryViewType = types.BufferType # will work in 2.6
! memoryview = buffer
!
def standardErrorHandler(connection,cursor,errorclass,errorvalue):
err=(errorclass,errorvalue)
--- 56,82 ----
type = Type.GetTypeFromProgID(dispatch)
return Activator.CreateInstance(type)
! def getIndexedValue(obj,index):
! return obj.Item[index]
! else: #pywin32
import pythoncom
pythoncom.__future_currency__ = True
! def Dispatch(dispatch):
! return win32com.client.Dispatch(dispatch)
! def getIndexedValue(obj,index):
! return obj(index)
! DBNull = type(None)
! DateTime = type(NotImplemented) #impossible value
!
! # --- define objects to smooth out Python3000 <-> Python 2.x differences
! unicodeType = str #this line will be altered by 2to3.py to '= str'
! longType = int #thil line will be altered by 2to3.py to '= int'
! memoryViewType = memoryview #will be altered to '= memoryview'
! if sys.version[0] == '3':
! StringTypes = [str]
! else:
! memoryview = buffer
! bytes = str
! StringTypes = str # will be messed up by 2to3 but never used
!
def standardErrorHandler(connection,cursor,errorclass,errorvalue):
err=(errorclass,errorvalue)
***************
*** 184,194 ****
def __init__(self):
TimeConverter.__init__(self)
! if win32:
! def COMDate(self,timeobj):
! return float(pythoncom.MakeTime(time.mktime(timeobj)))
! def COMDateFromTuple(self,YMDHMSmsTuple):
! t=pythoncom.MakeTime(YMDHMSmsTuple)
! return float(t)
! else: #iron Python
def COMDate(self,timeobj):
return self.COMDateFromTuple(timeobj)
--- 197,201 ----
def __init__(self):
TimeConverter.__init__(self)
! if onIronPython:
def COMDate(self,timeobj):
return self.COMDateFromTuple(timeobj)
***************
*** 199,202 ****
--- 206,215 ----
fractPart = sec / 86400.0
return integerPart + fractPart
+ else: #pywin32
+ def COMDate(self,timeobj):
+ return float(pythoncom.MakeTime(time.mktime(timeobj)))
+ def COMDateFromTuple(self,YMDHMSmsTuple):
+ t=pythoncom.MakeTime(YMDHMSmsTuple)
+ return float(t)
def DateObjectFromCOMDate(self,comDate):
***************
*** 208,212 ****
secondsperday=86400 # 24*60*60
#ComDate is number of days since 1899-12-31, gmtime epoch is 1970-1-1 = 25569 days
- ##if not win32: fcomDate += (2.0/24) # fudge an error in iron python gmtime
t=time.gmtime(secondsperday*(fcomDate-25569.0))
return t #year,month,day,hour,minute,second,weekday,julianday,daylightsaving=t
--- 221,224 ----
***************
*** 228,235 ****
return s
! class Error(Exception):
! pass
! class Warning(Exception):
pass
--- 240,252 ----
return s
! class Error(exceptions.Exception):
! pass #Exception that is the base class of all other error
! #exceptions. You can use this to catch all errors with one
! #single 'except' statement. Warnings are not considered
! #errors and thus should not use this class as base. It must
! #be a subclass of the Python StandardError (defined in the
! #module exceptions).
! class Warning(exceptions.Exception):
pass
***************
*** 265,269 ****
"Connection string as in the ADO documentation, SQL timeout in seconds"
try:
! if win32:
pythoncom.CoInitialize() #v2.1 Paj
conn=Dispatch('ADODB.Connection') #connect _after_ CoIninialize v2.1.1 adamvan
--- 282,286 ----
"Connection string as in the ADO documentation, SQL timeout in seconds"
try:
! if not onIronPython:
pythoncom.CoInitialize() #v2.1 Paj
conn=Dispatch('ADODB.Connection') #connect _after_ CoIninialize v2.1.1 adamvan
***************
*** 331,347 ****
self.adoConn=adoConn
self.supportsTransactions=False
! if win32:
! for indx in range(adoConn.Properties.Count):
! if adoConn.Properties[indx].Name == 'Transaction DDL':
! if adoConn.Properties[indx].Value != 0: #v2.1 Albrecht
! self.supportsTransactions=True
! break
! else: # Iron Python
! for indx in range(adoConn.Properties.Count):
! name = adoConn.Properties.Item[indx].Name
! if name == 'Transaction DDL':
! if adoConn.Properties.Item[indx].Value != 0: #v2.1 Albrecht
! self.supportsTransactions=True
! break
self.adoConn.CursorLocation = defaultCursorLocation #v2.1 Rose
if self.supportsTransactions:
--- 348,357 ----
self.adoConn=adoConn
self.supportsTransactions=False
! for indx in range(adoConn.Properties.Count):
! name = getIndexedValue(adoConn.Properties,indx).Name
! if name == 'Transaction DDL':
! if getIndexedValue(adoConn.Properties,indx).Value != 0: #v2.1 Albrecht
! self.supportsTransactions=True
! break
self.adoConn.CursorLocation = defaultCursorLocation #v2.1 Rose
if self.supportsTransactions:
***************
*** 381,385 ****
except (Exception) as e:
self._raiseConnectionError(InternalError,e)
! if win32:
pythoncom.CoUninitialize() #v2.1 Paj
--- 391,395 ----
except (Exception) as e:
self._raiseConnectionError(InternalError,e)
! if not onIronPython:
pythoncom.CoUninitialize() #v2.1 Paj
***************
*** 463,467 ****
self.adoConn=None
-
class Cursor(object):
description=None
--- 473,476 ----
***************
*** 522,529 ****
retLst=[]
for i in range(adoCommand.Parameters.Count):
! if win32:
! p=adoCommand.Parameters[i]
! else:
! p=adoCommand.Parameters.Item[i]
if verbose > 2:
print('return', p.Name, p.Type, p.Direction, repr(p.Value))
--- 531,535 ----
retLst=[]
for i in range(adoCommand.Parameters.Count):
! p=getIndexedValue(adoCommand.Parameters,i)
if verbose > 2:
print('return', p.Name, p.Type, p.Direction, repr(p.Value))
***************
*** 552,559 ****
self.description=[]
for i in range(nOfFields):
! if win32:
! f = rs.Fields[i]
! else: # Iron Python
! f=rs.Fields.Item[i]
name=f.Name
type_code=f.Type
--- 558,562 ----
self.description=[]
for i in range(nOfFields):
! f=getIndexedValue(rs.Fields,i)
name=f.Name
type_code=f.Type
***************
*** 644,651 ****
if cnt!=len(parameters):
for i in range(cnt):
! if win32:
! dir = self.cmd.Parameters[i].Direction
! else:
! dir = self.cmd.Parameters.Item[i].Direction
if dir == adParamReturnValue:
returnValueIndex=i
--- 647,651 ----
if cnt!=len(parameters):
for i in range(cnt):
! dir = getIndexedValue(self.cmd.Parameters,i).Direction
if dir == adParamReturnValue:
returnValueIndex=i
***************
*** 655,662 ****
if parmIndx == returnValueIndex:
parmIndx+=1
! if win32:
! p=self.cmd.Parameters[parmIndx]
! else: # Iron Python
! p=self.cmd.Parameters.Item[parmIndx]
if verbose > 2:
print('Parameter %d ADOtype %d, python %s' % (parmIndx,p.Type,type(elem)))
--- 655,659 ----
if parmIndx == returnValueIndex:
parmIndx+=1
! p=getIndexedValue(self.cmd.Parameters,parmIndx)
if verbose > 2:
print('Parameter %d ADOtype %d, python %s' % (parmIndx,p.Type,type(elem)))
***************
*** 673,677 ****
p.Value = s
p.Size = len(s)
! elif tp == str: #v2.1 Jevon
L = len(elem)
if defaultParameterList:
--- 670,674 ----
p.Value = s
p.Size = len(s)
! elif tp in StringTypes: #v2.1 Jevon
L = len(elem)
if defaultParameterList:
***************
*** 691,696 ****
p.Value = s
p.Size = len(s)
! elif isinstance(elem, long) and not win32: # Iron Python Long
! s = SystemDecimal(elem)
p.Value = s
else:
--- 688,693 ----
p.Value = s
p.Size = len(s)
! elif isinstance(elem, longType) and onIronPython: # Iron Python Long
! s = SystemDecimal(elem) # feature workaround for IPy 2.0
p.Value = s
else:
***************
*** 701,710 ****
# ----- the actual SQL is executed here ---
! if win32:
! adoRetVal=self.cmd.Execute()
! else: #Iron Python
ra = Reference[int]()
rs = self.cmd.Execute(ra)
adoRetVal=(rs,ra.Value) #return a tuple like win32 does
# ----- ------------------------------- ---
except Exception as e:
--- 698,707 ----
# ----- the actual SQL is executed here ---
! if onIronPython:
ra = Reference[int]()
rs = self.cmd.Execute(ra)
adoRetVal=(rs,ra.Value) #return a tuple like win32 does
+ else: #pywin32
+ adoRetVal=self.cmd.Execute()
# ----- ------------------------------- ---
except Exception as e:
***************
*** 713,720 ****
tbk += '-- Trying parameter %d = %s\n' \
%(parmIndx, repr(parameters[parmIndx]))
! tblist=(traceback.format_exception(sys.exc_info()[0],
! sys.exc_info()[1],
! sys.exc_info()[2],
! 8))
tb=''.join(tblist)
tracebackhistory = tbk + tb + '-- on command: "%s"\n-- with parameters: %s' \
--- 710,714 ----
tbk += '-- Trying parameter %d = %s\n' \
%(parmIndx, repr(parameters[parmIndx]))
! tblist=traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2],8)
tb=''.join(tblist)
tracebackhistory = tbk + tb + '-- on command: "%s"\n-- with parameters: %s' \
***************
*** 810,821 ****
returnList=[]
i=0
! if win32:
! for descTuple in d:
! # Desctuple =(name, type_code, display_size, internal_size, precision, scale, null_ok).
! type_code=descTuple[1]
! returnList.append([convertVariantToPython(r,type_code) for r in ado_results[i]])
! i+=1
! return tuple(zip(*returnList))
! else: #Iron Python
type_codes = [descTuple[1] for descTuple in d]
for j in range(len(ado_results)/len(d)):
--- 804,808 ----
returnList=[]
i=0
! if onIronPython:
type_codes = [descTuple[1] for descTuple in d]
for j in range(len(ado_results)/len(d)):
***************
*** 825,828 ****
--- 812,822 ----
returnList.append(tuple(L))
return tuple(returnList)
+ else: #pywin32
+ for descTuple in d:
+ # Desctuple =(name, type_code, display_size, internal_size, precision, scale, null_ok).
+ type_code=descTuple[1]
+ returnList.append([convertVariantToPython(r,type_code) for r in ado_results[i]])
+ i+=1
+ return tuple(zip(*returnList))
def fetchone(self):
***************
*** 891,895 ****
return
else:
! if win32:
try: #[begin 2.1 ekelund]
rsTuple=self.rs.NextRecordset() #
--- 885,896 ----
return
else:
! if onIronPython:
! try:
! rs = self.rs.NextRecordset()
! except TypeError:
! rs = None
! except Error as exc:
! self._raiseCursorError(NotSupportedError, exc.args)
! else: #pywin32
try: #[begin 2.1 ekelund]
rsTuple=self.rs.NextRecordset() #
***************
*** 897,907 ****
self._raiseCursorError(NotSupportedError, exc.args)#[end 2.1 ekelund]
rs=rsTuple[0]
- else: # iron
- try:
- rs = self.rs.NextRecordset()
- except TypeError:
- rs = None
- except Error as exc:
- self._raiseCursorError(NotSupportedError, exc.args)
self._makeDescriptionFromRS(rs)
if rs:
--- 898,901 ----
***************
*** 1151,1156 ****
self.values = valuesTuple
! def __eq__(self,other):
! return other in self.values
adoIntegerTypes=(adInteger,adSmallInt,adTinyInt,adUnsignedInt,
--- 1145,1152 ----
self.values = valuesTuple
! def __cmp__(self,other):
! if other in self.values:
! return 0
! return 1
adoIntegerTypes=(adInteger,adSmallInt,adTinyInt,adUnsignedInt,
***************
*** 1185,1200 ****
ROWID = DBAPITypeObject(adoRowIdTypes)
! typeMap= {
! memoryViewType: adBinary,
float: adNumeric,
- ## Should this differentiate between an int that fits in a long and one that requires 64-bit datatype ?
- ## int: adInteger,
- int: adBigInt,
- bytes: adBSTR,
type(None): adEmpty,
! str: adBSTR,
bool:adBoolean #v2.1 Cole
}
!
try: # If mx extensions are installed, use mxDateTime
import mx.DateTime
--- 1181,1198 ----
ROWID = DBAPITypeObject(adoRowIdTypes)
! typeMap= { memoryViewType: adBinary,
float: adNumeric,
type(None): adEmpty,
! str: adBSTR, # this line will be altered by 2to3 to 'str:'
bool:adBoolean #v2.1 Cole
}
! if longType != int: #not Python 3
! typeMap[longType] = adBigInt #works in python 2.x
! typeMap[int] = adInteger
! typeMap[bytes] = adBSTR, # 2.x string type
! else: #python 3.0 integrated integers
! ## Should this differentiote between an int that fits ion an long and one that requires 64 bit datatype?
! typeMap[int] = adBigInt
!
try: # If mx extensions are installed, use mxDateTime
import mx.DateTime
***************
*** 1212,1216 ****
def cvtString(variant): # use to get old action of adodbapi v1 if desired
! if not win32: # iron python
try:
return variant.ToString()
--- 1210,1214 ----
def cvtString(variant): # use to get old action of adodbapi v1 if desired
! if onIronPython:
try:
return variant.ToString()
***************
*** 1220,1224 ****
def cvtNumeric(variant): #all v2.1 Cole
! if not win32: # iron python
try:
return decimal.Decimal(variant.ToString())
--- 1218,1222 ----
def cvtNumeric(variant): #all v2.1 Cole
! if onIronPython:
try:
return decimal.Decimal(variant.ToString())
***************
*** 1252,1256 ****
def cvtUnicode(variant):
! return str(variant)
def identity(x): return x
--- 1250,1254 ----
def cvtUnicode(variant):
! return str(variant) # will be altered by 2to3 to 'str(variant)'
def identity(x): return x
***************
*** 1258,1262 ****
class VariantConversionMap(dict):
def __init__(self, aDict):
! for k, v in aDict.items():
self[k] = v # we must call __setitem__
--- 1256,1260 ----
class VariantConversionMap(dict):
def __init__(self, aDict):
! for k, v in list(aDict.items()):
self[k] = v # we must call __setitem__
***************
*** 1276,1283 ****
def convertVariantToPython(variant, adType):
! #if verbose > 2:
! # print 'Converting type_code=%s, val=%s'%(adType,repr(variant))
! # print ' str=%s'%str(variant)
! # print 'conversion=',repr(variantConversions[adType])
if isinstance(variant,DBNull):
return None
--- 1274,1281 ----
def convertVariantToPython(variant, adType):
! if verbose > 3:
! print('Converting type_code=%s, val=%s'%(adType,repr(variant)))
! print('conversion function=',repr(variantConversions[adType]))
! print(' output=%s'%repr(variantConversions[adType](variant)))
if isinstance(variant,DBNull):
return None
***************
*** 1290,1294 ****
adCurrency: cvtNumeric,
adoExactNumericTypes: cvtNumeric, # use cvtNumeric to force decimal rather than unicode
! adoLongTypes : int,
adoIntegerTypes: int,
adoRowIdTypes: int,
--- 1288,1292 ----
adCurrency: cvtNumeric,
adoExactNumericTypes: cvtNumeric, # use cvtNumeric to force decimal rather than unicode
! adoLongTypes : int, # will by altered by 2to3 to ': int'
adoIntegerTypes: int,
adoRowIdTypes: int,
Index: readme.txt
===================================================================
RCS file: /cvsroot/pywin32/pywin32/adodbapi/readme.txt,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -C2 -d -r1.2.2.1 -r1.2.2.2
*** readme.txt 20 Sep 2008 19:54:59 -0000 1.2.2.1
--- readme.txt 8 Dec 2008 21:35:05 -0000 1.2.2.2
***************
*** 4,8 ****
A Python DB-API 2.0 module that makes it easy to use Microsoft ADO
! for connecting with databases and other data sources.
Home page: <http://sourceforge.net/projects/adodbapi>
--- 4,9 ----
A Python DB-API 2.0 module that makes it easy to use Microsoft ADO
! for connecting with databases and other data sources
! using either CPython or IronPython.
Home page: <http://sourceforge.net/projects/adodbapi>
***************
*** 20,24 ****
Note: as of 2.1.1, adodbapi is included in pywin32 versions 211 and later.
or
! Iron Python 2.0b4 or higher.
Whats new in version 2.2.1
--- 21,46 ----
Note: as of 2.1.1, adodbapi is included in pywin32 versions 211 and later.
or
! Iron Python 2.0 or higher.
!
! NOTE: ...........
! If you do not like the new default operation of returning Numeric columns as decimal.Decimal,
! you can select other options by the user defined convertion feature.
! Try:
! adodbapi.variantConversions[adodbapi.adNumeric] = adodbapi.cvtString
! or:
! adodbapi.variantConversions[adodbapi.adNumeric] = adodbapi.cvtFloat
! or:
! adodbapi.variantConversions[adodbapi.adNumeric] = my_convertion_function
! ............
! Whats new in version 2.2.4
! 1. Ready for Python3? -- refactored so that 2to3 will inject very few errors, seems to be almost runnable in Pyk3.
!
! What happened to version 2.2.3?
! It was an attempt to be Python3 ready, but done wrong, so killed off.
!
! whats new in version 2.2.2
! 1. Works with Iron Python 2.0RC1 (passes all tests except BINARY columns and old python time date conversion.)
! 2. Passes all dbapi20 tests (All errors and warnings are now defined for the connection object.)
! 3. Adds predefined conversion functions cvtBuffer and cvtUnicode if you want to use them.
Whats new in version 2.2.1
***************
*** 77,81 ****
Bjorn Pettersen.
! Authors (version 2.1)
-------
Vernon Cole
--- 99,103 ----
Bjorn Pettersen.
! Author (version 2.1 and later)
-------
Vernon Cole
***************
*** 100,103 ****
--- 122,128 ----
Relase history
--------------
+ 2.2.2 Iron Python support complete.
+ 2.2.1 Bugfix for string truncation
+ 2.2 Code cleanup. added feature: "adodbapi.variantConversions[adodbapi.adNumeric] = adodbapi.cvtString"
2.1.1 Bugfix to CoIninialize() and nextset()
2.1 Python 2.4 version
|