[SQL-CVS] r3963 - in SQLObject/trunk: docs sqlobject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2009-08-19 15:57:18
|
Author: phd Date: 2009-08-19 09:57:09 -0600 (Wed, 19 Aug 2009) New Revision: 3963 Modified: SQLObject/trunk/docs/News.txt SQLObject/trunk/sqlobject/dbconnection.py SQLObject/trunk/sqlobject/main.py Log: .selectBy(), .deleteBy() and .by*() methods pass all values through .from_python(), not only unicode. Modified: SQLObject/trunk/docs/News.txt =================================================================== --- SQLObject/trunk/docs/News.txt 2009-08-18 16:47:32 UTC (rev 3962) +++ SQLObject/trunk/docs/News.txt 2009-08-19 15:57:09 UTC (rev 3963) @@ -21,6 +21,9 @@ * alternateMethodName defined for all unique fields, not only alternateID; this makes SQLObject create by*() methods for all unique fields. +* .selectBy(), .deleteBy() and .by*() methods pass all values through + .from_python(), not only unicode. + SQLObject 0.11 ============== Modified: SQLObject/trunk/sqlobject/dbconnection.py =================================================================== --- SQLObject/trunk/sqlobject/dbconnection.py 2009-08-18 16:47:32 UTC (rev 3962) +++ SQLObject/trunk/sqlobject/dbconnection.py 2009-08-19 15:57:09 UTC (rev 3963) @@ -574,7 +574,10 @@ data[soClass.sqlmeta.idName] = kw.pop('id') for key, col in soClass.sqlmeta.columns.items(): if key in kw: - data[col.dbName] = kw.pop(key) + value = kw.pop(key) + if col.from_python: + value = col.from_python(value, soClass) + data[col.dbName] = value elif col.foreignName in kw: obj = kw.pop(col.foreignName) if isinstance(obj, main.SQLObject): Modified: SQLObject/trunk/sqlobject/main.py =================================================================== --- SQLObject/trunk/sqlobject/main.py 2009-08-18 16:47:32 UTC (rev 3962) +++ SQLObject/trunk/sqlobject/main.py 2009-08-19 15:57:09 UTC (rev 3963) @@ -1306,16 +1306,18 @@ return getID(obj) def _findAlternateID(cls, name, dbName, value, connection=None): - if isinstance(value, unicode): - column = cls.sqlmeta.columns[name] - if isinstance(column, col.SOUnicodeCol): - value = value.encode(column.dbEncoding) if isinstance(name, str): name = (name,) value = (value,) if len(name) != len(value): raise ValueError, "'column' and 'value' tuples must be of the same size" - condition = sqlbuilder.AND(*[getattr(cls.q, n)==v for n,v in zip(name, value)]) + new_value = [] + for n, v in zip(name, value): + from_python = getattr(cls, '_SO_from_python_' + n) + if from_python: + v = from_python(v, cls) + new_value.append(v) + condition = sqlbuilder.AND(*[getattr(cls.q, n)==v for n,v in zip(name, new_value)]) return (connection or cls._connection)._SO_selectOneAlt( cls, [cls.sqlmeta.idName] + @@ -1364,11 +1366,6 @@ select = classmethod(select) def selectBy(cls, connection=None, **kw): - for key, column in cls.sqlmeta.columns.items(): - if (key in kw) and isinstance(column, col.SOUnicodeCol): - value = kw[key] - if isinstance(value, unicode): - kw[key] = value.encode(column.dbEncoding) conn = connection or cls._connection return cls.SelectResultsClass(cls, conn._SO_columnClause(cls, kw), |