From: Mike Bayer Date: Tue, 5 Sep 2006 15:39:59 +0000 (+0000) Subject: - unicode fix for startswith()/endswith() [ticket:296] X-Git-Tag: rel_0_2_8~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3d72a71871180f6b7ea8f7a09094d9e22aa84fd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - unicode fix for startswith()/endswith() [ticket:296] --- diff --git a/CHANGES b/CHANGES index c011c6285b..8ec7f60e9f 100644 --- a/CHANGES +++ b/CHANGES @@ -67,6 +67,7 @@ against datetimes that dont). count() [ticket:287] - deregister Table from MetaData when autoload fails; [ticket:289] - import of py2.5s sqlite3 [ticket:293] +- unicode fix for startswith()/endswith() [ticket:296] 0.2.7 - quoting facilities set up so that database-specific quoting can be diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index d2e270c32c..ab371dcb91 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -554,9 +554,9 @@ class CompareMixin(object): # statement out of it. return self._compare('IN', union(parens=True, *other)) def startswith(self, other): - return self._compare('LIKE', str(other) + "%") + return self._compare('LIKE', other + "%") def endswith(self, other): - return self._compare('LIKE', "%" + str(other)) + return self._compare('LIKE', "%" + other) def label(self, name): return Label(name, self, self.type) def distinct(self): diff --git a/test/sql/select.py b/test/sql/select.py index 7711e2908b..6eeef27040 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -212,6 +212,14 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A literal("a") + literal("b") * literal("c"), ":literal + (:liter_1 * :liter_2)" ) + def testunicodestartswith(self): + string = u"hi \xf6 \xf5" + self.runtest( + table1.select(table1.c.name.startswith(string)), + "SELECT mytable.myid, mytable.name, mytable.description FROM mytable WHERE mytable.name LIKE :mytable_name", + checkparams = {'mytable_name': u'hi \xf6 \xf5%'}, + ) + def testmultiparam(self): self.runtest( select(["*"], or_(table1.c.myid == 12, table1.c.myid=='asdf', table1.c.myid == 'foo')),