]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- the text() construct, if placed in a column
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 3 Aug 2010 18:06:41 +0000 (14:06 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 3 Aug 2010 18:06:41 +0000 (14:06 -0400)
oriented situation, will at least return NULLTYPE
for its type instead of None, allowing it to
be used a little more freely for ad-hoc column
expressions than before.   literal_column()
is still the better choice, however.

CHANGES
lib/sqlalchemy/sql/expression.py
test/sql/test_case_statement.py

diff --git a/CHANGES b/CHANGES
index 13d6e0f63939e4a34c9271ce288da36db3a9768d..b44edcede6be3b38471b8c39fd2a765128f9f954 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -88,7 +88,14 @@ CHANGES
     ResourceClosedError for all "this
     connection/transaction/result is closed" types of
     errors.
-        
+
+  - the text() construct, if placed in a column
+    oriented situation, will at least return NULLTYPE
+    for its type instead of None, allowing it to 
+    be used a little more freely for ad-hoc column
+    expressions than before.   literal_column()
+    is still the better choice, however.
+    
 - declarative
   - if @classproperty is used with a regular class-bound
     mapper property attribute, it will be called to get the
index 8a92dba0ddbd03d7b9ac4f950a0b195381dc304c..4b8df74c6e38463835d4a6b326138ab8627858d0 100644 (file)
@@ -428,8 +428,8 @@ def case(whens, value=None, else_=None):
     The expressions used for THEN and ELSE,
     when specified as strings, will be interpreted
     as bound values. To specify textual SQL expressions
-    for these, use the literal_column(<string>) or 
-    text(<string>) construct. 
+    for these, use the :func:`literal_column`
+    construct. 
 
     The expressions used for the WHEN criterion
     may only be literal strings when "value" is
@@ -2436,7 +2436,7 @@ class _TextClause(Executable, ClauseElement):
         if self.typemap is not None and len(self.typemap) == 1:
             return list(self.typemap)[0]
         else:
-            return None
+            return sqltypes.NULLTYPE
 
     def self_group(self, against=None):
         if against is operators.in_op:
index 3f3abe7e1900b743bafe572bfa567f8ec946d9b8..645822fa7094092a7de694145abe27e889bbf281 100644 (file)
@@ -1,4 +1,4 @@
-from sqlalchemy.test.testing import assert_raises, assert_raises_message
+from sqlalchemy.test.testing import assert_raises, assert_raises_message, eq_
 import sys
 from sqlalchemy import *
 from sqlalchemy.test import *
@@ -99,7 +99,25 @@ class CaseTest(TestBase, AssertsCompiledSQL):
         
         self.assert_compile(case([("x", "y")], value=t.c.col1), "CASE test.col1 WHEN :param_1 THEN :param_2 END")
         self.assert_compile(case([(t.c.col1==7, "y")], else_="z"), "CASE WHEN (test.col1 = :col1_1) THEN :param_1 ELSE :param_2 END")
-
+        
+    def test_text_doesnt_explode(self):
+
+        for s in [
+            select([case([(info_table.c.info == 'pk_4_data',
+                   text("'yes'"))], else_=text("'no'"
+                   ))]).order_by(info_table.c.info),
+                   
+           select([case([(info_table.c.info == 'pk_4_data',
+                  literal_column("'yes'"))], else_=literal_column("'no'"
+                  ))]).order_by(info_table.c.info),
+                   
+        ]:
+            eq_(s.execute().fetchall(), [
+                (u'no', ), (u'no', ), (u'no', ), (u'yes', ),
+                (u'no', ), (u'no', ),
+                ])
+        
+        
         
     @testing.fails_on('firebird', 'FIXME: unknown')
     @testing.fails_on('maxdb', 'FIXME: unknown')