]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [feature] Added "false()" and "true()" expression
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 18 Jan 2012 17:42:54 +0000 (12:42 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 18 Jan 2012 17:42:54 +0000 (12:42 -0500)
constructs to sqlalchemy.sql namespace, though
not part of __all__ as of yet.
- [bug] sql.false() and sql.true() compile to
0 and 1, respectively in sqlite [ticket:2368]

CHANGES
lib/sqlalchemy/dialects/sqlite/base.py
lib/sqlalchemy/sql/__init__.py
test/dialect/test_sqlite.py

diff --git a/CHANGES b/CHANGES
index 5df90019907a460ecb6604e72db43f31cb5d6e10..37b06a110885694c53998a93134d60496e1b38ef 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -32,6 +32,11 @@ CHANGES
   - [bug] ensure pickleability of all ORM exceptions
     for multiprocessing compatibility. [ticket:2371]
 
+- sql
+  - [feature] Added "false()" and "true()" expression
+    constructs to sqlalchemy.sql namespace, though
+    not part of __all__ as of yet.
+
 - engine
   - [bug] Added __reduce__ to StatementError, 
     DBAPIError, column errors so that exceptions 
@@ -47,6 +52,9 @@ CHANGES
     SQLite does not appear to support constraint
     naming in any case.
 
+  - [bug] sql.false() and sql.true() compile to
+    0 and 1, respectively in sqlite [ticket:2368]
+
 - mysql
   - [bug] fixed regexp that filters out warnings
     for non-reflected "PARTITION" directives,
index aea14485235f1793a1ef81cb10bc8a5ee58666cf..06c41b2eeff6c486f452468d07bd9d132484a0a3 100644 (file)
@@ -302,6 +302,12 @@ class SQLiteCompiler(compiler.SQLCompiler):
     def visit_now_func(self, fn, **kw):
         return "CURRENT_TIMESTAMP"
 
+    def visit_true(self, expr, **kw):
+        return '1'
+
+    def visit_false(self, expr, **kw):
+        return '0'
+
     def visit_char_length_func(self, fn, **kw):
         return "length%s" % self.function_argspec(fn)
 
index e82d072c115745d418221739aab6c075c59f42ac..eac845dcdbe9cdf9669cc20d1120b2cd074a7740 100644 (file)
@@ -34,6 +34,7 @@ from sqlalchemy.sql.expression import (
     except_all,
     exists,
     extract,
+    false,
     func,
     insert,
     intersect,
@@ -53,6 +54,7 @@ from sqlalchemy.sql.expression import (
     subquery,
     table,
     text,
+    true,
     tuple_,
     type_coerce,
     union,
index 7a5953654da3e4c4f95bca613ea222adf178eccb..4fe67fd2ea689ebe23b15f91176965c550cfcbee 100644 (file)
@@ -259,6 +259,18 @@ class DefaultsTest(fixtures.TestBase, AssertsCompiledSQL):
         finally:
             db.execute("DROP TABLE r_defaults")
 
+    @testing.provide_metadata
+    def test_boolean_default(self):
+        t= Table("t", self.metadata, 
+                Column("x", Boolean, server_default=sql.false()))
+        t.create(testing.db)
+        testing.db.execute(t.insert())
+        testing.db.execute(t.insert().values(x=True))
+        eq_(
+            testing.db.execute(t.select().order_by(t.c.x)).fetchall(),
+            [(False,), (True,)]
+        )
+
 
 class DialectTest(fixtures.TestBase, AssertsExecutionResults):
 
@@ -440,6 +452,15 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL):
                                 "SELECT CAST(STRFTIME('%s', t.col1) AS "
                                 "INTEGER) AS anon_1 FROM t" % subst)
 
+    def test_true_false(self):
+        self.assert_compile(
+            sql.false(), "0"
+        )
+        self.assert_compile(
+            sql.true(), 
+            "1"
+        )
+
     def test_constraints_with_schemas(self):
         metadata = MetaData()
         t1 = Table('t1', metadata,