[pywin32-checkins] pywin32/adodbapi adodbapi.py,1.2.2.1,1.2.2.2
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Vernon C. <kf...@us...> - 2008-11-13 04:28:25
|
Update of /cvsroot/pywin32/pywin32/adodbapi In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv30556 Modified Files: Tag: py3k adodbapi.py Log Message: Merge 2.2.2 changes and Test using Python 2.6 Index: adodbapi.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/adodbapi/adodbapi.py,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -C2 -d -r1.2.2.1 -r1.2.2.2 *** adodbapi.py 20 Sep 2008 19:54:59 -0000 1.2.2.1 --- adodbapi.py 13 Nov 2008 04:28:21 -0000 1.2.2.2 *************** *** 1,3 **** ! """adodbapi v2.2.1 - A python DB API 2.0 interface to Microsoft ADO Copyright (C) 2002 Henrik Ekelund --- 1,3 ---- ! """adodbapi v2.2.3 - A python DB API 2.0 interface to Microsoft ADO Copyright (C) 2002 Henrik Ekelund *************** *** 19,26 **** version 2.1 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 """ import time import calendar --- 19,36 ---- 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 + # numeric and monitary data columns are now returned as Decimal data, + # try adding the following line to get that data as strings: ... + #adodbapi.variantConversions[adodbapi.adoExactNumericTypes]=adodbapi.cvtString # get currency as strings + import string + import exceptions import time import calendar *************** *** 29,37 **** import traceback import datetime ! ! try: ! import decimal ! except ImportError: #perhaps running Cpython 2.3 ! import win32com.decimal_23 as decimal try: --- 39,43 ---- import traceback import datetime ! import decimal try: *************** *** 43,47 **** DateTime = type(NotImplemented) #impossible value except ImportError: # implies running on IronPython ! from System import Activator, Type, DBNull, DateTime from clr import Reference def Dispatch(dispatch): --- 49,54 ---- 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 from clr import Reference def Dispatch(dispatch): *************** *** 53,57 **** import pythoncom pythoncom.__future_currency__ = True ! def standardErrorHandler(connection,cursor,errorclass,errorvalue): err=(errorclass,errorvalue) --- 60,69 ---- 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) *************** *** 313,324 **** class Connection(object): def __init__(self,adoConn): self.adoConn=adoConn self.supportsTransactions=False ! 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 self.adoConn.CursorLocation = defaultCursorLocation #v2.1 Rose if self.supportsTransactions: --- 325,347 ---- class Connection(object): + from adodbapi import Warning, Error, InterfaceError, DataError, \ + DatabaseError, OperationalError, IntegrityError, InternalError, \ + NotSupportedError, ProgrammingError #required by api definition def __init__(self,adoConn): 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: *************** *** 498,503 **** def _returnADOCommandParameters(self,adoCommand): retLst=[] ! for i in range(adoCommand.Parameters.Count): ! p=adoCommand.Parameters[i] if verbose > 2: print('return', p.Name, p.Type, p.Direction, repr(p.Value)) --- 521,529 ---- def _returnADOCommandParameters(self,adoCommand): 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)) *************** *** 526,530 **** self.description=[] for i in range(nOfFields): ! f=rs.Fields[i] name=f.Name type_code=f.Type --- 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 *************** *** 615,619 **** if cnt!=len(parameters): for i in range(cnt): ! if self.cmd.Parameters[i].Direction == adParamReturnValue: returnValueIndex=i break --- 644,652 ---- 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 break *************** *** 622,626 **** if parmIndx == returnValueIndex: parmIndx+=1 ! p=self.cmd.Parameters[parmIndx] if verbose > 2: print('Parameter %d ADOtype %d, python %s' % (parmIndx,p.Type,type(elem))) --- 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))) *************** *** 649,653 **** if L>0: #v2.1 Cole something does not like p.Size as Zero p.Size = L #v2.1 Jevon ! elif tp == memoryview: #v2.1 Cole -- ADO BINARY p.AppendChunk(elem) elif isinstance(elem,decimal.Decimal): #v2.2 Cole --- 685,689 ---- 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 *************** *** 655,658 **** --- 691,697 ---- p.Value = s p.Size = len(s) + elif isinstance(elem, long) and not win32: # Iron Python Long + s = SystemDecimal(elem) + p.Value = s else: p.Value=elem *************** *** 1147,1151 **** typeMap= { ! memoryview: adBinary, float: adNumeric, ## Should this differentiate between an int that fits in a long and one that requires 64-bit datatype ? --- 1186,1190 ---- typeMap= { ! memoryViewType: adBinary, float: adNumeric, ## Should this differentiate between an int that fits in a long and one that requires 64-bit datatype ? *************** *** 1209,1212 **** --- 1248,1257 ---- raise + def cvtBuffer(variant): + return memoryview(variant) + + def cvtUnicode(variant): + return str(variant) + def identity(x): return x *************** *** 1249,1253 **** adoRowIdTypes: int, adoStringTypes: identity, ! adoBinaryTypes: identity, ! adoRemainingTypes: identity ! }) --- 1294,1297 ---- adoRowIdTypes: int, adoStringTypes: identity, ! adoBinaryTypes: cvtBuffer, ! adoRemainingTypes: identity }) |