1. diana clarke
  2. sqlalchemy-2450

Commits

jason kirtland  committed 0d25def

added support for string date passthru in sqlite (merge of r3322 from trunk)

  • Participants
  • Parent commits 9a1034b
  • Branches rel_0_3

Comments (0)

Files changed (3)

File CHANGES

View file
  • Ignore whitespace
       unconditionally quoted, so that schema names which need quoting are fine.
       its slightly unnecessary for schema names which don't need quoting
       but not harmful.
+- sqlite
+   - passthrough for stringified dates
       
 0.3.10
 - general

File lib/sqlalchemy/databases/sqlite.py

View file
  • Ignore whitespace
 
 class DateTimeMixin(object):
     def convert_bind_param(self, value, dialect):
-        if value is not None:
+        if isinstance(value, basestring): 
+            # pass string values thru 
+            return value 
+        elif value is not None:
             if getattr(value, 'microsecond', None) is not None:
                 return value.strftime(self.__format__ + "." + str(value.microsecond))
             else:

File test/sql/testtypes.py

View file
  • Ignore whitespace
         l = map(list, users_with_date.select().execute().fetchall())
         self.assert_(l == insert_data, 'DateTest mismatch: got:%s expected:%s' % (l, insert_data))
 
+    @testbase.supported('sqlite') 
+    def test_sqlite_date(self): 
+        meta = MetaData(testbase.db) 
+        t = Table('testdate', meta, 
+                  Column('id', Integer, primary_key=True), 
+                  Column('adate', Date),  
+                  Column('adatetime', DateTime)) 
+        t.create(checkfirst=True) 
+        try: 
+            d1 = datetime.date(2007, 10, 30) 
+            d2 = datetime.datetime(2007, 10, 30) 
+
+            t.insert().execute(adate=str(d1), adatetime=str(d2)) 
+	             
+            assert t.select().execute().fetchall()[0] == (1, datetime.date(2007, 10, 30), datetime.datetime(2007, 10, 30)) 
+        finally: 
+            t.drop(checkfirst=True) 
 
     def testtextdate(self):     
         x = db.text("select user_datetime from query_users_with_date", typemap={'user_datetime':DateTime}).execute().fetchall()