Commits

wilsaj  committed 5fb3327

add unit test for sqlite datetime comparison

  • Participants
  • Parent commits 488f1cd
  • Branches sqlite-datetime-comparison-fix

Comments (0)

Files changed (1)

File test/dialect/test_sqlite.py

         rp = sldt.result_processor(None, None)
         eq_(rp(bp(dt)), dt)
 
+    def test_datetime_comparison(self):
+        meta = MetaData(testing.db)
+        t = Table('datetime_table', meta, Column('id', Integer,
+                  primary_key=True), Column('dt',
+                  DateTime()))
+        try:
+            meta.create_all()
+            testing.db.execute("INSERT INTO datetime_table (id, dt) "
+                               "VALUES (1, '2011-12-31 19:20:15');")
+            testing.db.execute("INSERT INTO datetime_table (id, dt) "
+                               "VALUES (2, '2011-12-31 19:20:16');")
+            testing.db.execute("INSERT INTO datetime_table (id, dt) "
+                               "VALUES (3, '2011-12-31 19:20:17.000125');")
+            eq_(t.select(t.c.dt).where(
+                    t.c.dt == datetime.datetime(2011, 12, 31, 19, 20, 17, 125)
+                    ).execute().fetchall(),
+                [(3, datetime.datetime(2011, 12, 31, 19, 20, 17, 125))])
+            eq_(t.select(t.c.dt).where(
+                    t.c.dt == datetime.datetime(2011, 12, 31, 19, 20, 16)
+                    ).execute().fetchall(),
+                [(2, datetime.datetime(2011, 12, 31, 19, 20, 16))])
+            eq_(t.select(t.c.dt).where(
+                    t.c.dt >= datetime.datetime(2011, 12, 31, 19, 20, 16)
+                    ).order_by(t.c.dt).execute().fetchall(),
+                [(2, datetime.datetime(2011, 12, 31, 19, 20, 16)),
+                 (3, datetime.datetime(2011, 12, 31, 19, 20, 17, 125))])
+        finally:
+            meta.drop_all()
+
     def test_native_datetime(self):
         dbapi = testing.db.dialect.dbapi
         connect_args = {'detect_types': dbapi.PARSE_DECLTYPES \