]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Test for partial index support in sqlite dialects.
authorKai Groner <kai@gronr.com>
Mon, 26 Jan 2015 19:48:23 +0000 (14:48 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 10 Mar 2015 18:20:43 +0000 (14:20 -0400)
(cherry picked from commit 4a42bd5a2cba23782df7b6f98cadb7382d22498e)

test/dialect/test_sqlite.py

index 72a7ee152df0d475f0a9cfeb74ba732259f3208a..43e9e2b1f58891c22643153b23d09e5bd873475e 100644 (file)
@@ -8,7 +8,7 @@ from sqlalchemy.testing import eq_, assert_raises, \
     assert_raises_message, is_
 from sqlalchemy import Table, select, bindparam, Column,\
     MetaData, func, extract, ForeignKey, text, DefaultClause, and_, \
-    create_engine, UniqueConstraint
+    create_engine, UniqueConstraint, Index
 from sqlalchemy.types import Integer, String, Boolean, DateTime, Date, Time
 from sqlalchemy import types as sqltypes
 from sqlalchemy import event, inspect
@@ -753,6 +753,27 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL):
             ")"
         )
 
+    def test_create_partial_index(self):
+        m = MetaData()
+        tbl = Table('testtbl', m, Column('data', Integer))
+        idx = Index('test_idx1', tbl.c.data,
+                    sqlite_where=and_(tbl.c.data > 5, tbl.c.data < 10))
+
+        # test quoting and all that
+
+        idx2 = Index('test_idx2', tbl.c.data,
+                     sqlite_where=and_(tbl.c.data > 'a', tbl.c.data
+                                           < "b's"))
+        self.assert_compile(schema.CreateIndex(idx),
+                            'CREATE INDEX test_idx1 ON testtbl (data) '
+                            'WHERE data > 5 AND data < 10',
+                            dialect=sqlite.dialect())
+        self.assert_compile(schema.CreateIndex(idx2),
+                            "CREATE INDEX test_idx2 ON testtbl (data) "
+                            "WHERE data > 'a' AND data < 'b''s'",
+                            dialect=sqlite.dialect())
+
+
 
 class InsertTest(fixtures.TestBase, AssertsExecutionResults):