Mike Bayer avatar Mike Bayer committed 1da8c6a

added support for string date passthru in sqlite

Comments (0)

Files changed (2)

lib/sqlalchemy/databases/sqlite.py

 class DateTimeMixin(object):
     def bind_processor(self, dialect):
         def process(value):
-            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:

test/sql/testtypes.py

         l = map(list, users_with_date.select().execute().fetchall())
         self.assert_(l == insert_data, 'DateTest mismatch: got:%s expected:%s' % (l, insert_data))
 
+    @testing.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 = testbase.db.text("select user_datetime from query_users_with_date", typemap={'user_datetime':DateTime}).execute().fetchall()
         
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.