Then use "t" as the type on the Column.
[ticket:1090]
+
+ - SQLite Date, DateTime, and Time types only accept Python
+ datetime objects now, not strings. If you'd like to format
+ dates as strings yourself with SQLite, use a String type.
+ If you'd like them to return datetime objects anyway despite
+ their accepting strings as input, make a TypeDecorator around
+ String - SQLA doesn't encourage this pattern.
0.5beta1
========
import sqlalchemy.types as sqltypes
import sqlalchemy.util as util
from sqlalchemy.sql import compiler, functions as sql_functions
-
+from types import NoneType
SELECT_REGEXP = re.compile(r'\s*(?:SELECT|PRAGMA)', re.I | re.UNICODE)
def bind_processor(self, dialect):
def process(value):
- if isinstance(value, basestring):
- # pass string values thru
- return value
+ if not isinstance(value, (NoneType, datetime.date, datetime.datetime, datetime.time)):
+ raise TypeError("SQLite Date, Time, and DateTime types only accept Python datetime objects as input.r")
elif value is not None:
if self.__microsecond__ and getattr(value, 'microsecond', None) is not None:
if self.__legacy_microseconds__:
class TestTypes(TestBase, AssertsExecutionResults):
__only_on__ = 'sqlite'
- def test_date(self):
- meta = MetaData(testing.db)
- t = Table('testdate', meta,
- Column('id', Integer, primary_key=True),
- Column('adate', Date),
- Column('adatetime', DateTime))
- meta.create_all()
- try:
- d1 = datetime.date(2007, 10, 30)
- d2 = datetime.datetime(2007, 10, 30)
-
- t.insert().execute(adate=str(d1), adatetime=str(d2))
-
- self.assert_(t.select().execute().fetchall()[0] ==
- (1, datetime.date(2007, 10, 30),
- datetime.datetime(2007, 10, 30)))
-
- finally:
- meta.drop_all()
+ def test_string_dates_raise(self):
+ self.assertRaises(TypeError, testing.db.execute, select([1]).where(bindparam("date", type_=Date)), date=str(datetime.date(2007, 10, 30)))
def test_time_microseconds(self):
dt = datetime.datetime(2008, 6, 27, 12, 0, 0, 125) # 125 usec