[SQL-CVS] r3032 - in SQLObject/trunk/sqlobject: . tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: <sub...@co...> - 2007-10-09 15:55:32
|
Author: phd
Date: 2007-10-09 09:55:28 -0600 (Tue, 09 Oct 2007)
New Revision: 3032
Modified:
SQLObject/trunk/sqlobject/sqlbuilder.py
SQLObject/trunk/sqlobject/tests/test_unicode.py
Log:
Fixed startswith/endswith/contains for UnicodeCol.
Modified: SQLObject/trunk/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/trunk/sqlobject/sqlbuilder.py 2007-10-09 15:55:04 UTC (rev 3031)
+++ SQLObject/trunk/sqlobject/sqlbuilder.py 2007-10-09 15:55:28 UTC (rev 3032)
@@ -344,7 +344,20 @@
if isinstance(other, unicode):
other = other.encode(self.column.dbEncoding)
return SQLOp('<>', self, other)
+ def startswith(self, s):
+ if isinstance(s, unicode):
+ s = s.encode(self.column.dbEncoding)
+ return STARTSWITH(self, s)
+ def endswith(self, s):
+ if isinstance(s, unicode):
+ s = s.encode(self.column.dbEncoding)
+ return ENDSWITH(self, s)
+ def contains(self, s):
+ if isinstance(s, unicode):
+ s = s.encode(self.column.dbEncoding)
+ return CONTAINSSTRING(self, s)
+
registerConverter(UnicodeField, SQLExprConverter)
class Table(SQLExpression):
Modified: SQLObject/trunk/sqlobject/tests/test_unicode.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_unicode.py 2007-10-09 15:55:04 UTC (rev 3031)
+++ SQLObject/trunk/sqlobject/tests/test_unicode.py 2007-10-09 15:55:28 UTC (rev 3032)
@@ -63,3 +63,17 @@
assert len(rows) == 2
rows = list(TestUnicode.selectBy(col1=u'\u00f0', col2=u'test'))
assert len(rows) == 0
+
+ # starts/endswith/contains
+ rows = list(TestUnicode.select(TestUnicode.q.col1.startswith("test")))
+ assert len(rows) == 1
+ rows = list(TestUnicode.select(TestUnicode.q.col1.endswith("test")))
+ assert len(rows) == 2
+ rows = list(TestUnicode.select(TestUnicode.q.col1.contains("test")))
+ assert len(rows) == 2
+ rows = list(TestUnicode.select(TestUnicode.q.col1.startswith(u"\u00f0")))
+ assert len(rows) == 1
+ rows = list(TestUnicode.select(TestUnicode.q.col1.endswith(u"\u00f0")))
+ assert len(rows) == 1
+ rows = list(TestUnicode.select(TestUnicode.q.col1.contains(u"\u00f0")))
+ assert len(rows) == 1
|