OK, most databases dont even store dates as a string value, instead using
an internal object format that is translated by the DBAPI layer into
datetime objects.  the string date thing is a "feature" of SQLite.  So for
SQLite, we just make a guess as to a decent date format.  If you are
storing dates in arbitrary character formats, I would recommend just
subclassing the sqlalchemy.databases.sqlite.SLDate object date type
yourself and modifying the guts to work with your specific format....that
type can be used directly in table definitions.

Im not sure yet if I want to get into that whole "theres three different
date objects, with/without date, with/without time" thing, on the Python
side...mostly because I am not sure if DBAPIs really deal with the "date"
and "time" objects separately instead of just the "datetime"...but I will
examine this further.  The type objects would then become types.Date,
types.Time, and types.DateTime.  The "caps" datetime types I think need a
little work since some of them seem redundant...I just threw them in there
to start with.


limodou wrote:
> In sqlalchemy there are TIMESTAMP and DATETIME, but I saw these types
> will using time.strptime(value, "%Y-%m-%d %H:%M:%S") to convert the
> string date. However I had a legacy database, and the date field is
> save just like '%Y-%m-%d', so if I use DATETIME it'll be raise
> exception:
>
> File
> "c:\python24\lib\site-packages\SQLAlchemy-0.91alpha-py2.4.egg\sqlalchemy\databases\sqlite.py",
> line 41, in convert_result_value
>     tup = time.strptime(value, "%Y-%m-%d %H:%M:%S")
>   File "C:\python24\lib\_strptime.py", line 293, in strptime
>     raise ValueError("time data did not match format:  data=%s  fmt=%s" %
> ValueError: time data did not match format:  data=2005-01-01
> fmt=%Y-%m-%d %H:%M:%S
>
> So I want there should be a DATE type. And if I can define the
> datetime format is more better.
>
> If I need use user-defined Type to extend that?
> --
> I like python!
> My Blog: http://www.donews.net/limodou
> NewEdit Maillist: http://groups.google.com/group/NewEdit
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
> _______________________________________________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
>



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to