]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fixes half of [ticket:192], query.load()/get() with a unicode argument was failing...
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 1 Jun 2006 15:49:58 +0000 (15:49 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 1 Jun 2006 15:49:58 +0000 (15:49 +0000)
lib/sqlalchemy/orm/query.py
test/mapper.py

index 64484e4fcbf398d87f901ac16858378394873b66..3af55b739022cadcaba4e126ca9568213f6d6088 100644 (file)
@@ -24,7 +24,7 @@ class Query(object):
         if not hasattr(mapper, '_get_clause'):
             _get_clause = sql.and_()
             for primary_key in self.mapper.pks_by_table[self.table]:
-                _get_clause.clauses.append(primary_key == sql.bindparam("pk_"+primary_key._label))
+                _get_clause.clauses.append(primary_key == sql.bindparam("pk_"+primary_key._label, type=primary_key.type))
             self.mapper._get_clause = _get_clause
         self._get_clause = self.mapper._get_clause
     def _get_session(self):
index 7e331288e428aaa3532c629895c44a6e42984433..10025397abb99aef5806851dc1a55e5b33f99a52 100644 (file)
@@ -84,6 +84,22 @@ class MapperTest(MapperSuperTest):
         u2 = s.get(User, 7)
         self.assert_(u is not u2)
 
+    def testunicodeget(self):
+        """tests that Query.get properly sets up the type for the bind parameter.  using unicode would normally fail 
+        on postgres, mysql and oracle unless it is converted to an encoded string"""
+        table = Table('foo', db, 
+            Column('id', Unicode(10), primary_key=True),
+            Column('data', Unicode(40)))
+        try:
+            table.create()
+            class LocalFoo(object):pass
+            mapper(LocalFoo, table)
+            crit = 'petit voix m\xe2\x80\x99a '.decode('utf-8')
+            print repr(crit)
+            create_session().query(LocalFoo).get(crit)
+        finally:
+            table.drop()
+
     def testrefresh(self):
         mapper(User, users, properties={'addresses':relation(mapper(Address, addresses))})
         s = create_session()