Sorry,

Database is sqlite. From my understanding sqlite would store the value
as a string.

>From running the following test it seems that the orignal type of
value stored (datetime vs date) is being maintained in sqlite
regardless of the Column type:

import datetime

from sqlalchemy import *
from sqlalchemy.orm import *

engine = create_engine('sqlite://', echo=False)

Session = sessionmaker(bind=engine, autoflush=True,
transactional=True)

meta = MetaData()

test_table = Table('test', meta,
    Column('id', Integer, primary_key=True),
    Column('name', String),
    Column('date', Date))

class Test(object):
    def __init__(self, name, date):
        self.name = name
        self.date = date
    def __repr__(self):
        return "<%s: %s>" % (self.name, self.date)

mapper(Test, test_table)

if __name__ == '__main__':

    t1 = Test('date', datetime.date(2007, 12, 18))
    t2 = Test('datetime', datetime.datetime(2007, 12, 18))
    t3 = Test('control', datetime.date(2007, 1, 1))

    meta.create_all(engine)

    sess = Session()
    sess.save(t1)
    sess.save(t2)
    sess.save(t3)

    sess.flush()
    sess.clear()

    print 'All:'
    print sess.query(Test).all()
    print 'Datetime:'
    print sess.query(Test).filter_by(date=datetime.datetime(2007, 12,
18)).all()
    print 'Date:'
    print sess.query(Test).filter_by(date=datetime.date(2007, 12,
18)).all()

Result:

All:
[<date: 2007-12-18>, <datetime: 2007-12-18>, <control: 2007-01-01>]
Datetime:
[<datetime: 2007-12-18>]
Date:
[<date: 2007-12-18>]

Thanks,

- Justin


On Dec 18, 1:19 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> not sure, it depends on what kind of database youre using (and what
> DBAPI) as well as the actual type of column is is on the database
> side.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to