Entry
VBScript is excellent for integrating with ADO (Active Data Objects) databases. Is python as facile?
Jun 12th, 2000 06:15
unknown unknown, Eduard Hiti
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.