---------- Forwarded message ----------
From: limodou <[EMAIL PROTECTED]>
Date: 2005-12-19 下午1:56
Subject: Re: [Sqlalchemy-users] Need I to convert the DateTime column type?
To: Michael Bayer <[EMAIL PROTECTED]>
2005/12/19, Michael Bayer <[EMAIL PROTECTED]>:
> SQLite itself stores the value as a string, as it has no "datetime"
> type. you can, in fact, specify whatever goofy type you want with
> SQLite and most of it just goes in as a string.
>
> when I run the DateTime unit test with sqlite3 (not 2):
I'm sorry, I also use sqlite3.
>
> python test/query.py QueryTest.testselectdate
>
> I get a DateTime back. this is because the SLDateTime type in
> SQLAlchemy is converting the string from SQLite into a date.
>
> Are you looking at the datetime value directly in the database? or
> are you selecting with SQLAlchemy and not getting a datetime back?
> What does that unit test give you?
>
> I also just checked in an assertion for it:
>
> self.assert_(l ==
> [(7, u'jack', datetime.datetime(2005, 11, 10, 0,
> 0)), (8, u'roy', datetime.datetime(2005, 11, 10, 11, 52, 35)), (9,
> u'foo', datetime.datetime(2005, 11, 10, 11, 52, 35, 54839)), (10,
> u'colber', None)]
> )
>
But in my test it's not the same, but sometimes may be correct. It's
very strange. First I create the table and insert a record into the
table, as below:
from sqlalchemy import *
import datetime
engine = create_engine('sqlite://filename=d:/test.db', echo=True)
RssData = Table('rss_data', engine,
Column('id', Integer, primary_key = True),
Column('title', Unicode),
Column('pubDate', DateTime)
)
RssData.create()
class Date(object):
def __init__(self, date=None, title=None):
self.pubDate = date
self.title = title
Date.mapper = mapper(Date, RssData)
a = Date(date=datetime.datetime.now(), title="Test")
objectstore.commit(a)
and I got
CREATE TABLE rss_data(
id INTEGER NOT NULL PRIMARY KEY,
title TEXT,
pubDate TIMESTAMP
)
{}
INSERT INTO rss_data (title, pubDate) VALUES (?, ?)
['Test', datetime.datetime(2005, 12, 19, 13, 53, 0, 71000)]
Second, I got it from database as below:
from sqlalchemy import *
import datetime
engine = create_engine('sqlite://filename=d:/test.db', echo=True)
RssData = Table('rss_data', engine,
Column('id', Integer, primary_key = True),
Column('title', Unicode),
Column('pubDate', DateTime)
)
#RssData.create()
class Date(object):
def __init__(self, date=None, title=None):
self.pubDate = date
self.title = title
Date.mapper = mapper(Date, RssData)
#a = Date(date=datetime.datetime.now(), title="Test")
#objectstore.commit(a)
r = Date.mapper.select()
for i in r:
print i.pubDate, type(i.pubDate)
But I got:
SELECT rss_data.id AS rss_data_id, rss_data.title AS rss_data_title,
rss_data.pubDate AS rss_data_pubDate
FROM rss_data ORDER BY rss_data.oid
[]
2005-12-19 13:53:00.071000 <type 'unicode'>
I don't know why I got the unicode type.
--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit
--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit
N�HY薜���X���'���u���[�����ê
蕈�k㈣!���W�~�楫��zk��C� [EMAIL PROTECTED],悍��a{���,�H蛟4�m���i�(辟堍o�v'