Hi
This is to warn people working with sqlalchemy and sqlite and date/time
columns.
I know, the topic has already been discussed, but I found it difficult
to relate this topic with the error messages I got when trying the
following:
transactions_table = Table('transactions', metadata,
...
Column('enter_date', DateTime))
on a sqlite database created originaly by gnucash, a free accounting
application. This means, I don't use sqlalchemy to put data in but only
to take data out.
The above definition worked on mysql but failed on sqlite, with the
following exception:
Traceback (most recent call last):
File "/p/python/exp/of_sqlalchemy/minimal-gc.py", line 50, in <module>
filter(Transaction.description.like(unicode(desc))).all()
File
"/usr/local/python2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py",
line 1267, in all
return list(self)
File
"/usr/local/python2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py",
line 1422, in instances
rows = [process[0](context, row) for row in fetch]
File
"/usr/local/python2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/query.py",
line 2032, in main
return _instance(row, None)
File
"/usr/local/python2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/mapper.py",
line 1711, in _instance
populate_state(state, dict_, row, isnew, only_load_props)
File
"/usr/local/python2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/mapper.py",
line 1596, in populate_state
populator(state, dict_, row, isnew=isnew, **flags)
File
"/usr/local/python2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/orm/strategies.py",
line 120, in new_execute
dict_[key] = row[col]
File
"/usr/local/python2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py",
line 1348, in __getitem__
return self.__parent._get_col(self.__row, key)
File
"/usr/local/python2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/engine/base.py",
line 1620, in _get_col
return processor(row[index])
File
"/usr/local/python2.6/lib/python2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/sqlalchemy/databases/sqlite.py",
line 183, in process
return fn(*[int(x or 0) for x in regexp.match(value).groups()])
AttributeError: 'NoneType' object has no attribute 'groups'
I had difficulties relating this message to a datetime problem. It was
fixed by changing the column type to unicode ( sqlite stores dates as
strings ):
transactions_table = Table('transactions', metadata,
...
Column('enter_date', Unicode(50))
Conclusion: Be careful with dates and sqlite
Peter
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.