[sqlalchemy] Insert time/date into sqlite

2011-02-09 Thread anonymous
Hello,

I have the following table in sqlite:
date DATE
field1 VARCHAR(100)
field2 VARCHAR(100)

I'd like to insert the current date/time into this table:
result = DBSQLITE.execute (INS, date = strftime(%Y-%m-%d %H:%M:%S,
gmtime()), field1 = string1, field2 = string2)
But it doesn't work - I get an error:

TypeError: SQLite Date type only accepts Python date objects as input.

How should I convert the date/time to be able to insert it into this
table ?

Regards
Przemek

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Insert time/date into sqlite

2011-02-09 Thread Michael Bayer
SQLite doesn't have a DATE type specifically.  SQLAlchemy's Date() type expects 
Python datetime, i.e. import datetime; date = datetime.date(year, month day).

In this case if you want to put a date + time that would be Sqlalchemy 
DateTime(), you'd use datetime.datetime(), or if you want to deal with strings 
yourself, use String() for the column type. Its all the same to SQLite 
(SQLite doesn't actually have fixed column types and is unique in this regard).


On Feb 9, 2011, at 7:36 AM, anonymous wrote:

 Hello,
 
 I have the following table in sqlite:
 date DATE
 field1 VARCHAR(100)
 field2 VARCHAR(100)
 
 I'd like to insert the current date/time into this table:
 result = DBSQLITE.execute (INS, date = strftime(%Y-%m-%d %H:%M:%S,
 gmtime()), field1 = string1, field2 = string2)
 But it doesn't work - I get an error:
 
 TypeError: SQLite Date type only accepts Python date objects as input.
 
 How should I convert the date/time to be able to insert it into this
 table ?
 
 Regards
 Przemek
 
 -- 
 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 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.
 

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.