Python and ADO 2.5?

Eduard Hiti eduard.hiti at t-online.de
Sun Jun 11 07:20:34 EDT 2000


"Peter Immarco" <android at micron.net> wrote in message
news:39430E84.2679DD45 at micron.net...
> I am thinking of replacing my VBScript ASP's with Python.  VBScript is
> excellent for integrating with ADO (Active Data Objects) databases.  Is
> Python as facile?
>

I used ADO 2.5 in my last Python project, and had no problems at all. Most
of the time, ADO access in VB translates almost directly to python syntax.
Features of ADO I used with no problem include parameterized commands, batch
updating and client side cursors.

One thing to keep in mind is the way pythoncom handles out-parameters of
method calls: These values are returned as part of the method result, e.g
the Execute method of the Connection object returns a tuple consisting of an
RecordSet object and the RecordsAffected value (see MSDN):

    recordset, affected = db_connect.Execute("select * from ...")

In VB you would only get the recordset returned and RecordsAffected would
get stuffed in a reference parameter of the call.

Another point is handling of date values: They are returned as objects with
type pywintypes.TimeType. The documentation for this type is very terse, and
I had to dig into the pythoncom demos to find their interface: One useful
method is Format(<formatstring>), which will return a string from TimeType:

    import pywintypes
    if type(x) == pywintypes.TimeType:
        return x.Format("%d.%m.%Y")

For more information on COM and Python I recommend Mark Hammond's "Python
Programming on Win32" (which covers almost the entire COM body, albeit
sometimes not too deeply: "Advanced Python Programming..." ?), which has a
chapter on database programming.

Good luck,

    Eduard






More information about the Python-list mailing list