[pywin32-checkins] pywin32/adodbapi adodbapi.py, 1.5, 1.6 readme.txt, 1.5, 1.6
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Vernon C. <kf...@us...> - 2008-12-08 18:13:58
|
Update of /cvsroot/pywin32/pywin32/adodbapi In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv25942 Modified Files: adodbapi.py readme.txt Log Message: adodbapi 2.2.4 (IPy 2.0 and 2to3 ready) Index: adodbapi.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/adodbapi/adodbapi.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** adodbapi.py 11 Nov 2008 23:54:29 -0000 1.5 --- adodbapi.py 8 Dec 2008 18:13:53 -0000 1.6 *************** *** 1,3 **** ! """adodbapi v2.2.2 - A python DB API 2.0 interface to Microsoft ADO Copyright (C) 2002 Henrik Ekelund --- 1,3 ---- ! """adodbapi v2.2.4 - A python DB API 2.0 interface to Microsoft ADO Copyright (C) 2002 Henrik Ekelund *************** *** 44,53 **** try: import win32com.client ! def Dispatch(dispatch): ! return win32com.client.Dispatch(dispatch) ! win32 = True ! DBNull = types.NoneType ! DateTime = types.NotImplementedType #impossible value except ImportError: # implies running on IronPython from System import Activator, Type, DBNull, DateTime, Array, Byte from System import Decimal as SystemDecimal --- 44,53 ---- 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 *************** *** 56,65 **** type = Type.GetTypeFromProgID(dispatch) return Activator.CreateInstance(type) ! win32 = False #implies IronPython ! ! if win32: import pythoncom pythoncom.__future_currency__ = True 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 = unicode #this line will be altered by 2to3.py to '= str' + longType = long #thil line will be altered by 2to3.py to '= int' + memoryViewType = types.BufferType #will be altered to '= memoryview' + if sys.version[0] == '3': + StringTypes = [str] + else: + memoryview = buffer + bytes = str + StringTypes = types.StringTypes # will be messed up by 2to3 but never used + def standardErrorHandler(connection,cursor,errorclass,errorvalue): err=(errorclass,errorvalue) *************** *** 74,78 **** #Use self.types to compare if an input parameter is a datetime self.types = (type(self.Date(2000,1,1)), ! type(self.Time(12,01,1)), type(self.Timestamp(2000,1,1,12,1,1))) def COMDate(self,obj): --- 91,95 ---- #Use self.types to compare if an input parameter is a datetime self.types = (type(self.Date(2000,1,1)), ! type(self.Time(12,1,1)), type(self.Timestamp(2000,1,1,12,1,1))) def COMDate(self,obj): *************** *** 180,190 **** 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) *************** *** 195,198 **** --- 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): *************** *** 204,208 **** 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 ---- *************** *** 225,229 **** class Error(exceptions.StandardError): ! pass class Warning(exceptions.StandardError): --- 241,250 ---- class Error(exceptions.StandardError): ! 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.StandardError): *************** *** 261,265 **** "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 *************** *** 327,343 **** 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: *************** *** 377,381 **** except (Exception), e: self._raiseConnectionError(InternalError,e) ! if win32: pythoncom.CoUninitialize() #v2.1 Paj --- 391,395 ---- except (Exception), e: self._raiseConnectionError(InternalError,e) ! if not onIronPython: pythoncom.CoUninitialize() #v2.1 Paj *************** *** 517,524 **** 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) *************** *** 547,554 **** 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 *************** *** 637,646 **** if isStoredProcedureCall: cnt=self.cmd.Parameters.Count ! 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 --- 645,651 ---- if isStoredProcedureCall: cnt=self.cmd.Parameters.Count ! if cnt!=len(parameters): for i in range(cnt): ! dir = getIndexedValue(self.cmd.Parameters,i).Direction if dir == adParamReturnValue: returnValueIndex=i *************** *** 650,657 **** 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)) *************** *** 668,672 **** p.Value = s p.Size = len(s) ! elif tp in types.StringTypes: #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: *************** *** 680,684 **** if L>0: #v2.1 Cole something does not like p.Size as Zero p.Size = L #v2.1 Jevon ! elif tp == types.BufferType: #v2.1 Cole -- ADO BINARY p.AppendChunk(elem) elif isinstance(elem,decimal.Decimal): #v2.2 Cole --- 682,686 ---- if L>0: #v2.1 Cole something does not like p.Size as Zero p.Size = L #v2.1 Jevon ! elif tp == memoryViewType: #v2.1 Cole -- ADO BINARY p.AppendChunk(elem) elif isinstance(elem,decimal.Decimal): #v2.2 Cole *************** *** 686,691 **** 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: *************** *** 696,705 **** # ----- 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, 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, e: *************** *** 708,716 **** tbk += u'-- Trying parameter %d = %s\n' \ %(parmIndx, repr(parameters[parmIndx])) ! tblist=(traceback.format_exception(sys.exc_type, ! sys.exc_value, ! sys.exc_traceback, ! 8)) ! tb=string.join(tblist) tracebackhistory = tbk + tb + u'-- on command: "%s"\n-- with parameters: %s' \ %(operation,parameters) --- 710,715 ---- tbk += u'-- Trying parameter %d = %s\n' \ %(parmIndx, repr(parameters[parmIndx])) ! tblist=traceback.format_exception(sys.exc_type,sys.exc_value,sys.exc_traceback,8) ! tb=''.join(tblist) tracebackhistory = tbk + tb + u'-- on command: "%s"\n-- with parameters: %s' \ %(operation,parameters) *************** *** 805,816 **** 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)): *************** *** 820,823 **** --- 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): *************** *** 886,890 **** 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, exc: ! self._raiseCursorError(NotSupportedError, exc.args) ! else: #pywin32 try: #[begin 2.1 ekelund] rsTuple=self.rs.NextRecordset() # *************** *** 892,902 **** 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, exc: - self._raiseCursorError(NotSupportedError, exc.args) self._makeDescriptionFromRS(rs) if rs: --- 898,901 ---- *************** *** 942,951 **** """This function constructs an object holding a date value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details). """ ! return apply(Date,time.gmtime(ticks)[:3]) def TimeFromTicks(ticks): """This function constructs an object holding a time value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details). """ ! return apply(Time,time.gmtime(ticks)[3:6]) def TimestampFromTicks(ticks): --- 941,950 ---- """This function constructs an object holding a date value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details). """ ! return Date(*time.gmtime(ticks)[:3]) def TimeFromTicks(ticks): """This function constructs an object holding a time value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details). """ ! return Time(*time.gmtime(ticks)[3:6]) def TimestampFromTicks(ticks): *************** *** 953,961 **** ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details). """ ! return apply(Timestamp,time.gmtime(ticks)[:6]) def Binary(aString): """This function constructs an object capable of holding a binary (long) string value. """ ! return buffer(aString) #v2.1 Cole comment out: BinaryType = Binary('a') --- 952,960 ---- ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details). """ ! return Timestamp(*time.gmtime(ticks)[:6]) def Binary(aString): """This function constructs an object capable of holding a binary (long) string value. """ ! return memoryview(aString) #v2.1 Cole comment out: BinaryType = Binary('a') *************** *** 1148,1156 **** def __cmp__(self,other): if other in self.values: ! return 0 ! if other < self.values: ! return 1 ! else: ! return -1 adoIntegerTypes=(adInteger,adSmallInt,adTinyInt,adUnsignedInt, --- 1147,1152 ---- def __cmp__(self,other): if other in self.values: ! return 0 ! return 1 adoIntegerTypes=(adInteger,adSmallInt,adTinyInt,adUnsignedInt, *************** *** 1185,1199 **** ROWID = DBAPITypeObject(adoRowIdTypes) ! typeMap= { ! types.BufferType: adBinary, ! types.FloatType: adNumeric, ! types.IntType: adInteger, ! types.LongType: adBigInt, ! types.StringType: adBSTR, ! types.NoneType: adEmpty, ! types.UnicodeType: adBSTR, ! types.BooleanType: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, ! unicode: 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 *************** *** 1211,1215 **** 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() *************** *** 1219,1223 **** 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()) *************** *** 1248,1255 **** def cvtBuffer(variant): ! return buffer(variant) def cvtUnicode(variant): ! return unicode(variant) def identity(x): return x --- 1247,1254 ---- def cvtBuffer(variant): ! return memoryview(variant) def cvtUnicode(variant): ! return unicode(variant) # will be altered by 2to3 to 'str(variant)' def identity(x): return x *************** *** 1257,1261 **** class VariantConversionMap(dict): def __init__(self, aDict): ! for k, v in aDict.iteritems(): self[k] = v # we must call __setitem__ --- 1256,1260 ---- class VariantConversionMap(dict): def __init__(self, aDict): ! for k, v in aDict.items(): self[k] = v # we must call __setitem__ *************** *** 1289,1293 **** adCurrency: cvtNumeric, adoExactNumericTypes: cvtNumeric, # use cvtNumeric to force decimal rather than unicode ! adoLongTypes : long, adoIntegerTypes: int, adoRowIdTypes: int, --- 1288,1292 ---- adCurrency: cvtNumeric, adoExactNumericTypes: cvtNumeric, # use cvtNumeric to force decimal rather than unicode ! adoLongTypes : long, # 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.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** readme.txt 11 Nov 2008 23:54:29 -0000 1.5 --- readme.txt 8 Dec 2008 18:13:53 -0000 1.6 *************** *** 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> *************** *** 32,35 **** --- 33,41 ---- 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 |