Author: phd
Date: 2007-10-09 09:54:47 -0600 (Tue, 09 Oct 2007)
New Revision: 3030
Modified:
SQLObject/branches/0.8/docs/News.txt
SQLObject/branches/0.8/sqlobject/sqlbuilder.py
SQLObject/branches/0.8/sqlobject/tests/test_unicode.py
Log:
Fixed startswith/endswith/contains for UnicodeCol.
Modified: SQLObject/branches/0.8/docs/News.txt
===================================================================
--- SQLObject/branches/0.8/docs/News.txt 2007-10-09 15:53:21 UTC (rev 3029)
+++ SQLObject/branches/0.8/docs/News.txt 2007-10-09 15:54:47 UTC (rev 3030)
@@ -201,6 +201,8 @@
* Fixed StringCol and UnicodeCol: use sqlType with MSSQL.
+* Fixed startswith/endswith/contains for UnicodeCol.
+
Other Changes
-------------
Modified: SQLObject/branches/0.8/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/0.8/sqlobject/sqlbuilder.py 2007-10-09 15:53:21 UTC (rev 3029)
+++ SQLObject/branches/0.8/sqlobject/sqlbuilder.py 2007-10-09 15:54:47 UTC (rev 3030)
@@ -343,7 +343,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)
Modified: SQLObject/branches/0.8/sqlobject/tests/test_unicode.py
===================================================================
--- SQLObject/branches/0.8/sqlobject/tests/test_unicode.py 2007-10-09 15:53:21 UTC (rev 3029)
+++ SQLObject/branches/0.8/sqlobject/tests/test_unicode.py 2007-10-09 15:54:47 UTC (rev 3030)
@@ -69,3 +69,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
|