ADOdbapi converting all data to strings

Max Slimmer mslimmer at csbuilders.net
Mon Aug 16 02:44:44 EDT 2004


I guess I wasn't clear and only confused the question with date.  The
problem I have is that NUMERIC data time fields are being returned as
strings.  So if the database has a column declared as int or as float or
number of any kind, when I do a select I get back the value as a unicode
string and I want integers to be returned as integers and numbers with
percision (decimal points) to be returned as float.  Dates get returned as
type datetime and that is great, it is the NUMERIC data types that are
returned as strings which is the problem.



> -----Original Message-----
> From: Robert Brewer [mailto:fumanchu at amor.org]
> Sent: Sunday, August 15, 2004 11:18 PM
> To: max; python-list at python.org
> Subject: RE: ADOdbapi converting all data to strings
>
>
> max wrote:
> > I am trying to access a foxpro database, using odbc all is well except
> > that dates prior to 1970 are not returned as valid usable data, so
> > would like to use ADO. When I select data containing numbers (long or
> > float) they are converted and returned as unicode strings. Dates are
> > returned as datetime.date which is great. Is there any way to change
> > this behavior other than to explicitly change back all fields using
> > cursor.description information.
>
> I *think* you're saying that you have a COM date (which is similar to a
> float), and want a datetime.date.
>
>
> import datetime
> # 12/30/1899, the zero-Date for ADO = 693594
> zeroDate = datetime.date(1899, 12, 30).toordinal()
>
> def coerce_datetime(value):
>     return datetime.date.fromordinal(int(float(value)) + zeroDate)
>
>
> COM times are more complicated. Inquire further if you need to handle
> them.
>
>
> Robert Brewer
> MIS
> Amor Ministries
> fumamchu at amor.org
>




More information about the Python-list mailing list