]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Columns of _Binary type (i.e. LargeBinary, BLOB, etc.)
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 May 2010 23:08:48 +0000 (19:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 22 May 2010 23:08:48 +0000 (19:08 -0400)
will coerce a "basestring" on the right side into a
_Binary as well so that required DBAPI processing
takes place.

CHANGES
lib/sqlalchemy/types.py
test/sql/test_types.py

diff --git a/CHANGES b/CHANGES
index 17ede848de3d8f83f4b968b9cfd9d5de83bab169..997e046c10445a17212d85df52b15d0483360655 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -30,6 +30,11 @@ CHANGES
     is like `col.in_(text("select id from table"))`.
     [ticket:1793]
 
+  - Columns of _Binary type (i.e. LargeBinary, BLOB, etc.)
+    will coerce a "basestring" on the right side into a 
+    _Binary as well so that required DBAPI processing 
+    takes place.
+    
   - Added table.add_is_dependent_on(othertable), allows manual
     placement of dependency rules between two Table objects
     for use within create_all(), drop_all(), sorted_tables.
index 4d86dc3625424fd92fa166aafc4627f47704f97c..9a9f2d1cdf85d47c80efc19a38d37593151d4bbe 100644 (file)
@@ -1191,6 +1191,12 @@ class _Binary(TypeEngine):
             process = processors.to_str
         return process
     # end Py2K
+
+    def _coerce_compared_value(self, op, value):
+        if isinstance(value, basestring):
+            return self
+        else:
+            return super(_Binary, self)._coerce_compared_value(op, value)
     
     def adapt(self, impltype):
         return impltype(length=self.length)
index 5bdaca6c73f1042b93d605ca4d6760b5ab446f6e..88875d1393a09f82888bbd29eb7779cc5a7f9ef6 100644 (file)
@@ -663,7 +663,18 @@ class BinaryTest(TestBase, AssertsExecutionResults):
             eq_(testobj2, l[1]['pickled'])
             eq_(testobj3.moredata, l[0]['mypickle'].moredata)
             eq_(l[0]['mypickle'].stuff, 'this is the right stuff')
-
+    
+    def test_comparison(self):
+        """test that type coercion occurs on comparison for binary"""
+        
+        expr = binary_table.c.data == 'foo'
+        assert isinstance(expr.right.type, LargeBinary)
+        
+        data = os.urandom(32)
+        binary_table.insert().execute(data=data)
+        eq_(binary_table.select().where(binary_table.c.data==data).count().scalar(), 1)
+        
+        
     def load_stream(self, name):
         f = os.path.join(os.path.dirname(__file__), "..", name)
         return open(f, mode='rb').read()