tweaking ADO RecordSet tuple?

David Fuess fuess at att.net
Wed Feb 14 22:23:27 EST 2001


On Wed, 14 Feb 2001 20:59:16 +0100, "Eduard Hiti" <KatMouse at gmx.de>
wrote:

General comment: With COM and ADO the number of variable types and
situations you encounter are so wide and varied that each one seems to
be a special case. I have managed to control the beast by restricting
the variable types created in my databases. But we don't always have
that luxury ...

>I'm using ADO with Python just fine.
>COM Unicode usage was always handled very well by win32com.

But you may still want to convert them to latin1 if you intend to
perform string operations on the data items. Many string functions
fail when you feed them certain unicode characters (like u-umlaut).

>
>Date values can be converted to 'time' module format simply by using int():
>
>    import pywintypes, time
>
>    t = pywintypes.Time(time.time())     # this is the COM date type in
>Python
>    time.strftime("%Y-%m-%d %H:%M:%S", time.localtime( int(t) ) )
>

I've had a lot of trouble with this because the datum may be different
between the database server and the UNIX time functions. On SQL Server
7 the datum is 1/1/1900. Instead I use the .Format() function of the
database time object to format the time into a string. It takes the
same arguments as strftime. (This is the method duscussed next :-) )

>This seems to be a little messy, since time.time() returns a float, so
>conversion with int() will lose information. What is worse, using float()
>will return wrong values.
>
>pywintypes.Time has a 'Format' method, too:
>
>    t.Format("%m%d%Y")
>
>which will return a string representation of the date.
>
>I heard that the mxDateTime module has excellent support for COM date types,
>but I didn't need it, so can't comment on that module.
>
>Greetings,
>
>    Eduard
>
>
>----- Original Message -----
>From: <fluxent at yahoo.com>
>Newsgroups: comp.lang.python
>To: <python-list at cwi.nl>
>Sent: Wednesday, February 14, 2001 7:30 PM
>Subject: tweaking ADO RecordSet tuple?
>
>
>| context/architecture: Python, ASP, MsSQL. Sending query to MsSQL,
>| getting back RecordSet, outputting HTML table.
>|
>| Am I correct in understanding that to work with a RecordSet in
>| a "normal" (to me) manner, I need to:
>| - transpose it, since GetRows returns columns, not rows
>| - convert from unicode and dateobjects to useful stuff
>|
>| Is there some code sitting someplace that people are usually using
>| for this purpose? Or are so few people using ADO that it hasn't
>| bubbled up?
>|
>|
>|
>
>




More information about the Python-list mailing list