Skip to content

Commit

Permalink
adodbapi version 2.1.1
Browse files Browse the repository at this point in the history
Bug fix so nextset() will work even if a result set is empty [Bob Kline]
Bug fix to call CoInintialize before calling Dispatch [Adam Vandenberg]
Cleanups to test routines
  • Loading branch information
vernondcole committed Aug 6, 2008
1 parent 05f2dc5 commit fe3669c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 60 deletions.
17 changes: 9 additions & 8 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""adodbapi v2.1 - A python DB API 2.0 interface to Microsoft ADO
"""adodbapi v2.1.1 - A python DB API 2.0 interface to Microsoft ADO
Copyright (C) 2002 Henrik Ekelund
Email: <http://sourceforge.net/sendmessage.php?touser=618411>
Expand Down Expand Up @@ -245,9 +245,9 @@ def connect(connstr, timeout=30): #v2.1 Simons
"Connection string as in the ADO documentation, SQL timeout in seconds"
global verbose
try:
conn=Dispatch('ADODB.Connection')
if win32:
pythoncom.CoInitialize() #v2.1 Paj
pythoncom.CoInitialize() #v2.1 Paj
conn=Dispatch('ADODB.Connection') #connect _after_ CoIninialize v2.1.1 adamvan
except:
raise InterfaceError #Probably COM Error
try:
Expand Down Expand Up @@ -501,9 +501,10 @@ def _returnADOCommandParameters(self,adoCommand):
retLst.append(pyObject)
return retLst

def _makeDescriptionFromRS(self,rs):
def _makeDescriptionFromRS(self,rs):
self.rs = rs #v2.1.1 bkline
if (rs == None) or (rs.State == adStateClosed):
self.rs=None
##self.rs=None #removed v2.1.1 bkline
self.description=None
else:
#self.rowcount=rs.RecordCount
Expand All @@ -515,7 +516,7 @@ def _makeDescriptionFromRS(self,rs):
# Switching to client-side cursors will force a static cursor,
# and rowcount will then be set accurately [Cole]
self.rowcount = -1
self.rs=rs
##self.rs=rs #removed v2.1.1 bkline
nOfFields=rs.Fields.Count
self.description=[]
for i in range(nOfFields):
Expand All @@ -541,7 +542,7 @@ def close(self):
self.conn = None #this will make all future method calls on me throw an exception
if self.rs and self.rs.State != adStateClosed: # rs exists and is open #v2.1 Rose
self.rs.Close() #v2.1 Rose
self.rs = None #let go of the recordset os ADO will let it be disposed #v2.1 Rose
self.rs = None #let go of the recordset so ADO will let it be disposed #v2.1 Rose

# ------------------------
# a note about Strategies:
Expand Down Expand Up @@ -740,7 +741,7 @@ def _fetch(self, rows=None):
if self.conn == None:
self._raiseCursorError(Error,None)
return
if rs == None:
if rs == None or rs.State == adStateClosed: #v2.1.1 bkline
self._raiseCursorError(Error,None)
return
else:
Expand Down
13 changes: 7 additions & 6 deletions adodbapi/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Prerequisites:
* Python 2.3 or higher.
* (this version included within) Mark Hammond's win32all python for windows extensions.


Whats new in version 2.1.1?
1. Bugfix so nextset() will work even if a rowset is empty [ Bob Kline ]
2. Bugfix to call CoInitailize() before calling Dispatch() [ Adam Vandenberg ]

Whats new in version 2.1?
1. Use of Decimal.decimal data type for currency and numeric data. [ Cole ]
2. add optional timeout parameter to the connect method i.e.:
Expand Down Expand Up @@ -63,7 +68,6 @@ License
-------
LGPL, see http://www.opensource.org/licenses/lgpl-license.php


Documentation
-------------
Start with:
Expand All @@ -74,15 +78,12 @@ and look at the test cases in adodbapi/test directory.
Mailing lists
-------------
The adodbapi mailing lists have been deactivated. Submit comments to the
bug tracker.
pywin32 lists.

Contribute
----------
Use the sourceforge bug tracking system to submit bugs, feature requests
and comments.

Relase history
--------------
2.1.1 Bugfix to CoIninialize() and nextset()
2.1 Python 2.4 version
2.0 See what's new above.
1.0.1 Bug fix: Null values for numeric fields. Thanks to Tim Golden.
Expand Down
41 changes: 16 additions & 25 deletions adodbapi/tests/adodbapitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Updated for decimal data and version 2.1 by Vernon Cole
AS400 tests removed v 2.1.1 - Vernon Cole
"""

import unittest
Expand Down Expand Up @@ -387,9 +388,10 @@ def testCurrencyDataType(self):
crsr=conn.cursor()
crsr.execute(tabdef)

for multiplier in (1,decimal.Decimal('2.5'),78,9999,999999,7007):
for multiplier in (1,decimal.Decimal('2.5'),78,9999,99999,7007):
crsr.execute("DELETE FROM tblTemp")
crsr.execute("INSERT INTO tblTemp(fldCurr) VALUES (12.50*%f)" % multiplier)
correct = decimal.Decimal('12.50') * multiplier
crsr.execute("INSERT INTO tblTemp(fldCurr) VALUES (?)",[correct])

sql="SELECT fldCurr FROM tblTemp "
try:
Expand All @@ -398,7 +400,6 @@ def testCurrencyDataType(self):
conn.printADOerrors()
print sql
fldcurr=crsr.fetchone()[0]
correct = decimal.Decimal('12.50') * multiplier
self.assertEquals( fldcurr,correct)

def testErrorConnect(self):
Expand Down Expand Up @@ -534,6 +535,17 @@ def setUp(self):
self.fail('SetUpError: Can not connect to the testdatabase, all other tests will fail...\nAdo error:%s' % adoConn.Errors(0))
self.engine = 'ACCESS'

def tearDown(self):
try:
self.conn.rollback()
except:
pass
try:
self.conn.close()
except:
pass
self.conn=None

def getConnection(self):
return adodbapi.connect(adodbapitestconfig.connStrAccess)

Expand All @@ -560,26 +572,6 @@ def testOkConnect(self):
c=adodbapi.connect(adodbapitestconfig.connStrMySql)
assert c != None

class TestADOwithAS400DB(CommonDBTests):
def setUp(self):
try:
adoConn=win32com.client.Dispatch("ADODB.Connection")
except:
self.fail('SetUpError: Is MDAC installed?')
try:
adoConn.Open(adodbapitestconfig.connStrAS400)
except:
self.fail('SetUpError: Can not connect to the testdatabase, all other tests will fail...\nAdo error:%s' % adoConn.Errors(0))
self.engine = 'IBMDA400'

def getConnection(self):
return adodbapi.connect(adodbapitestconfig.connStrAS400)

def testOkConnect(self):
c=adodbapi.connect(adodbapitestconfig.connStrAS400)
assert c != None


class TimeConverterInterfaceTest(unittest.TestCase):
def testIDate(self):
assert self.tc.Date(1990,2,2)
Expand Down Expand Up @@ -731,8 +723,7 @@ def testTimestamp(self):
suites.append( unittest.makeSuite(TestADOwithSQLServer,'test'))
if adodbapitestconfig.doMySqlTest:
suites.append( unittest.makeSuite(TestADOwithMySql,'test'))
if adodbapitestconfig.doAS400Test:
suites.append( unittest.makeSuite(TestADOwithAS400DB,'test'))

suite=unittest.TestSuite(suites)
if __name__ == '__main__':
defaultDateConverter=adodbapi.dateconverter
Expand Down
28 changes: 7 additions & 21 deletions adodbapi/tests/adodbapitestconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

doAccessTest = True
doSqlServerTest = True
doMySqlTest = True

try: #If mx extensions are installed, use mxDateTime
import mx.DateTime
doMxDateTimeTest=True
except:
doMxDateTimeTest=False #Requires eGenixMXExtensions
doAS400Test = False
doMySqlTest = False


import sys
if float(sys.version[:3])>2.29:
doDateTimeTest=True #Requires Python 2.3 Alpha2
Expand Down Expand Up @@ -81,10 +83,10 @@
doSqlServerTest = False

if doMySqlTest:
_computername='5.128.134.143'
_computername='10.100.5.249'
_databasename='test'

connStrMySql = 'Driver={MySQL ODBC 3.51 Driver};Server=%s;Port=3306;Database=%s;Option=3;' % \
connStrMySql = 'Driver={MySQL ODBC 5.1 Driver};Server=%s;Port=3306;Database=%s;Option=3;' % \
(_computername,_databasename)
print ' ...Testing MySql login...'
try:
Expand All @@ -94,20 +96,4 @@
print inst.args[0][2] # should be the error message
doMySqlTest = False

if doAS400Test:
#OLE DB -> "PROVIDER=IBMDA400; DATA SOURCE=MY_SYSTEM_NAME;USER ID=myUserName;PASSWORD=myPwd;DEFAULT COLLECTION=MY_LIBRARY;"
connStrAS400skl = "Provider=IBMDA400; DATA SOURCE=%s;DEFAULT COLLECTION=%s;User ID=%s;Password=%s"
# NOTE! user's PC must have OLE support installed in IBM Client Access Express
_computername='PEPPER'
_databasename="DPDAN"
_username = raw_input(' AS400 User ID for data retrieval [%s]:' % defaultUser)
_password = getpass.getpass(' AS400 password:') #read the password
connStrAS400 = connStrAS400skl % (_computername,_databasename,_username,_password) #build the connection string
print ' ...Testing AS400 login...'
try:
s = adodbapi.connect(connStrAS400) #connect to server
s.close()
except adodbapi.DatabaseError, inst:
print inst.args[0][2] # should be the AS400 error message
doAS400Test = False


0 comments on commit fe3669c

Please sign in to comment.