Author: phd
Date: 2006-09-04 09:01:36 -0600 (Mon, 04 Sep 2006)
New Revision: 1897
Modified:
SQLObject/branches/0.7-bugfix/docs/News.txt
SQLObject/branches/0.7-bugfix/docs/SQLObject.txt
SQLObject/branches/0.7-bugfix/sqlobject/main.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_unicode.py
Log:
Extended unicode patch to the .byName() case where "name" is an alternateID.
Modified: SQLObject/branches/0.7-bugfix/docs/News.txt
===================================================================
--- SQLObject/branches/0.7-bugfix/docs/News.txt 2006-09-04 15:01:13 UTC (rev 1896)
+++ SQLObject/branches/0.7-bugfix/docs/News.txt 2006-09-04 15:01:36 UTC (rev 1897)
@@ -51,23 +51,10 @@
* Fixed a longstanding problem with UnicodeCol - at last you can use unicode
strings in .select() and .selectBy() queries. There are some limitations,
- though:
+ though; see the description of the UnicodeCol_.
- - only simple q-magic fields are supported; no expressions;
- - only == and <> operators are supported;
+.. _UnicodeCol: SQLObject.html#column-types
- The following code works::
-
- MyTable.select(u'value' == MyTable.q.name)
- MyTable.select(MyTable.q.name <> u'value')
- MyTable.select(OR(MyTable.q.col1 == u'value1', MyTable.q.col2 <> u'value2'))
- MyTable.selectBy(name = u'value')
- MyTable.selectBy(col1=u'value1', col2=u'value2')
-
- The following still does not work::
-
- MyTable.select((MyTable.q.name + MyTable.q.surname) == u'value')
-
* Cull patch (clear cache).
* .destroySelf() inside a transaction.
Modified: SQLObject/branches/0.7-bugfix/docs/SQLObject.txt
===================================================================
--- SQLObject/branches/0.7-bugfix/docs/SQLObject.txt 2006-09-04 15:01:13 UTC (rev 1896)
+++ SQLObject/branches/0.7-bugfix/docs/SQLObject.txt 2006-09-04 15:01:36 UTC (rev 1897)
@@ -1139,6 +1139,7 @@
MyTable.select(OR(MyTable.q.col1 == u'value1', MyTable.q.col2 <> u'value2'))
MyTable.selectBy(name = u'value')
MyTable.selectBy(col1=u'value1', col2=u'value2')
+ MyTable.byCol1(u'value1') # if col1 is an alternateID
The following does not work::
Modified: SQLObject/branches/0.7-bugfix/sqlobject/main.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/main.py 2006-09-04 15:01:13 UTC (rev 1896)
+++ SQLObject/branches/0.7-bugfix/sqlobject/main.py 2006-09-04 15:01:36 UTC (rev 1897)
@@ -1255,10 +1255,14 @@
return getID(obj)
def _findAlternateID(cls, name, dbName, value, connection=None):
+ for key, column in cls.sqlmeta.columns.items():
+ if (key == name) and isinstance(column, col.SOUnicodeCol):
+ if isinstance(value, unicode):
+ value = value.encode(column.dbEncoding)
return (connection or cls._connection)._SO_selectOneAlt(
cls,
[cls.sqlmeta.idName] +
- [col.dbName for col in cls.sqlmeta.columnList],
+ [column.dbName for column in cls.sqlmeta.columnList],
dbName,
value), None
_findAlternateID = classmethod(_findAlternateID)
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_unicode.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_unicode.py 2006-09-04 15:01:13 UTC (rev 1896)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_unicode.py 2006-09-04 15:01:36 UTC (rev 1897)
@@ -7,7 +7,7 @@
class TestUnicode(SQLObject):
count = IntCol(alternateID=True)
- col1 = UnicodeCol()
+ col1 = UnicodeCol(alternateID=True)
col2 = UnicodeCol(dbEncoding='latin-1')
try:
@@ -44,7 +44,7 @@
def test_select():
setup()
- for value in data:
+ for i, value in enumerate(data):
rows = list(TestUnicode.select(TestUnicode.q.col1 == value))
assert len(rows) == 1
rows = list(TestUnicode.select(TestUnicode.q.col2 == value))
@@ -60,6 +60,8 @@
assert len(rows) == 1
rows = list(TestUnicode.selectBy(col1=value, col2=value))
assert len(rows) == 1
+ row = TestUnicode.byCol1(value)
+ assert row.count == i
rows = list(TestUnicode.select(OR(
TestUnicode.q.col1 == u'\u00f0',
TestUnicode.q.col2 == u'test'
|