[IronPython] How do I determine whether a database supports transactions?

Vernon Cole vernondcole at gmail.com
Wed Aug 20 02:58:50 CEST 2008


Hello all.
  I am the present maintainer of adodbapi, a pure python module which uses
ADO-DB to access SQL databases. (see adodbapi.sourceforge.net) It has been
my stated goal for some time to port the package to Iron Python, since it is
fully DB-API_2.0 compliant, and the existing SQL access library samples for
ipy are relatively light weight.

The present implementation works only in CPython and depends on pywin32 to
make COM calls to access ADO. I originally thought that I would replace all
of the COM interface with ADO.NET calls, but someone suggested that it would
be less rewriting to call COM from ipy, too.
<comments about the wisdom of this are welcome.>

I could use some help with my present snag.

   In the snippet below (which works in CPython) the Properties attribute of
the dispatch object is completely different between the two implementations.
I notice, when I do a dir(adoConn), that ipy shows two different attributes
called "Properties" , so perhaps the other one has the interface I want, if
I knew how to get at it. I didn't write this code so I don't know how or why
it works, but it is used to see whether a particular database supports
rollback and commit.

  What alternate code could I use to aviod calling adoConn.Properties(indx)
as a method?

#begin snippet .........
try:
    import win32com.client
    def Dispatch(dispatch):
        return win32com.client.Dispatch(dispatch)
    win32 = True
except ImportError:  #perhaps running on IronPython
    from System import Activator, Type
    def Dispatch(dispatch):
        type = Type.GetTypeFromProgID(dispatch)
        return Activator.CreateInstance(type)
    win32 = False    #implies IronPython

def connect(connstr, timeout=30):
    "Connection string as in the ADO documentation, SQL timeout in seconds"
    conn=Dispatch('ADODB.Connection')
    conn.CommandTimeout=timeout
    conn.ConnectionString=connstr
    conn.Open()
    return Connection(conn)

class Connection:
    def __init__(self,adoConn):
        self.adoConn=adoConn
        self.supportsTransactions=False
        for indx in range(adoConn.Properties.Count):  ### iron py errors on
the next line
            if adoConn.Properties(indx).Name == 'Transaction DDL' \
            and adoConn.Properties(indx).Value != 0:
                self.supportsTransactions=True
        self.adoConn.CursorLocation = defaultCursorLocation
        if self.supportsTransactions:
            self.adoConn.IsolationLevel=defaultIsolationLevel
            self.adoConn.BeginTrans() #Disables autocommit
        self.messages=[]
#end snippet ......

My resulting stack trace ends with:
  File "C:\Program Files\IronPython 2.0
Beta4\lib\site-packages\adodbapi\adodbapi.py", line 264, in connect
  File "C:\Program Files\IronPython 2.0
Beta4\lib\site-packages\adodbapi\adodbapi.py", line 317, in __init__
TypeError: __ComObject is not callable
---
Any suggestions are welcome.
--
Vernon Cole
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080819/e97ed231/attachment.html>


More information about the Ironpython-users mailing list