The issue is that in essence, both answers are right. ANSI SQL specifies
different data types for DATE fields and DATETIME fields, where DATE fields
do not hold the time portion. Oracle, SQL Server and other database engines
have their own ideas about how best to handle dates / datetimes.
SA splits the difference sometimes. All the various dialects inherit from an
ANSI dialect which treats the two types as distinct. On the other hand, most
dialects take the philosophy of "just hand whatever value you got off to the
DBAPI and what happens, happens".
At least one of SA purported benefits is that it helps to abstract the
various behaviors of it's supported database engines and thereby make SA
code at least theoretically a bit easier to work on multiple database
engines. This is kind of in direct conflict with the laissez-faire "let the
DBAPI decide" philosophy, which is why you sometimes see some of this
arguably schizophrenic behavior. If we give you DBAPI-neutral types today,
tomorrow somebody on the list will be complaining that it doesn't work the
other way around.
For the short term, you should look into the OracleDateTime type. But in
general, we need to know more about what users are looking for. I'm guessing
we can put you in the "DBAPI-neutral" camp?
On 11/12/07, Michael Schlenker <[EMAIL PROTECTED]> wrote:
>
>
> Hi all,
>
> I'm not sure if its a bug or an intended feature, but the default
> behaviour
> of sqlalchemy when reading Oracle DATE fields is annoying. cx_Oracle
> rightfully returns datetime.datetime objects, but Sqlalchemy truncates
> this
> to datetime.date objects.
>
> Why is it done like this (in lib/sqlalchemy/databases/oracle.py:34-60)?
> Wouldn't it be a better choice to default to OracleDateTime instead of
> OracleDate
> for queries without bound metadata?
>
> Its not a (major) problem when querying via a table object, where i can
> override
> the column type with a sane version (OracleDateTime), but for queries
> directly
> using conn.execute() its ugly.
>
> Basically this throws up:
>
> import sqlalchemy as sa
> import datetime
> engine = sa.create_engine('oracle://scott:[EMAIL PROTECTED]')
> conn = engine.connect()
> conn.execute('create table dtest (a DATE)')
> # insert a row with date and time
> now = datetime.datetime(2007,12,11,13,11,00)
> conn.execute('insert into dtest values (:dt)', {'dt':now})
> # check its there
> rows = conn.execute('select a from dtest where a=:dt',{'dt':now})
> for r in rows:
> if rows[0]==now:
> print "Found"
> else:
> print "Not Found"
>
> This prints 'Not Found' even though the row is there and is returned
> correctly
> by cx_Oracle.
>
> I would expect to get at least identity for this.
>
> So is this a bug and should i add a report or is it a 'feature' of some
> kind and will
> not change even if i report a bug?
>
> Michael
>
> --
> Michael Schlenker
> Software Engineer
>
> CONTACT Software GmbH Tel.: +49 (421) 20153-80
> Wiener Straße 1-3 Fax: +49 (421) 20153-41
> 28359 Bremen
> http://www.contact.de/ E-Mail: [EMAIL PROTECTED]
>
> Sitz der Gesellschaft: Bremen | Geschäftsführer: Karl Heinz Zachries
> Eingetragen im Handelsregister des Amtsgerichts Bremen unter HRB 13215
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---