]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added support for string date passthru in sqlite (merge of r3322 from trunk)
authorJason Kirtland <jek@discorporate.us>
Mon, 10 Sep 2007 22:32:11 +0000 (22:32 +0000)
committerJason Kirtland <jek@discorporate.us>
Mon, 10 Sep 2007 22:32:11 +0000 (22:32 +0000)
CHANGES
lib/sqlalchemy/databases/sqlite.py
test/sql/testtypes.py

diff --git a/CHANGES b/CHANGES
index ef50caf4ee3324941a13a991a94fba28595e1a90..3379008b2bf4e71dfdf0ace0de2e30fb527aea49 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -34,6 +34,8 @@
       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
index 816b1b76a9abfe5204bdc7865dac7788a5e2536d..965799a224da5c56c23236d29fb23476790405b3 100644 (file)
@@ -31,7 +31,10 @@ class SLSmallInteger(sqltypes.Smallinteger):
 
 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:
index 00f382e209e286a80c14b5f6500f92f540fb3541..46069013e66d6bea5d4c3cba775f9806982e9e7d 100644 (file)
@@ -336,6 +336,23 @@ class DateTest(AssertMixin):
         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()