[SQL-CVS] r4119 - SQLObject/trunk/sqlobject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: <sub...@co...> - 2010-03-03 18:38:05
|
Author: phd
Date: 2010-03-03 11:37:57 -0700 (Wed, 03 Mar 2010)
New Revision: 4119
Modified:
SQLObject/trunk/sqlobject/col.py
Log:
Test connection-specific Binary type and buffer type.
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2010-03-03 17:51:12 UTC (rev 4118)
+++ SQLObject/trunk/sqlobject/col.py 2010-03-03 18:37:57 UTC (rev 4119)
@@ -507,6 +507,9 @@
return self._sqlType()
+# Special marker to test the dataType is a backend-specific Binary
+testDataTypeBinary = object()
+
class StringValidator(validators.Validator):
def to_python(self, value, state):
@@ -516,20 +519,32 @@
connection = state.soObject._connection
dbEncoding = getattr(connection, "dbEncoding", None) or "ascii"
return value.encode(dbEncoding)
- if isinstance(value, (str, sqlbuilder.SQLExpression)):
+ if isinstance(value, (str, buffer, sqlbuilder.SQLExpression)):
return value
- if self.dataType and isinstance(value, self.dataType):
- return value
+ if self.dataType:
+ if self.dataType is testDataTypeBinary:
+ connection = state.soObject._connection
+ dataType = connection._binaryType
+ else:
+ dataType = self.dataType
+ if isinstance(value, dataType):
+ return value
raise validators.Invalid("expected a str in the StringCol '%s', got %s %r instead" % \
(self.name, type(value), value), value, state)
def from_python(self, value, state):
if value is None:
return None
- if isinstance(value, (str, sqlbuilder.SQLExpression)):
+ if isinstance(value, (str, buffer, sqlbuilder.SQLExpression)):
return value
- if self.dataType and isinstance(value, self.dataType):
- return value
+ if self.dataType:
+ if self.dataType is testDataTypeBinary:
+ connection = state.soObject._connection
+ dataType = connection._binaryType
+ else:
+ dataType = self.dataType
+ if isinstance(value, dataType):
+ return value
if isinstance(value, unicode):
connection = state.soObject._connection
dbEncoding = getattr(connection, "dbEncoding", None) or "ascii"
@@ -1469,7 +1484,7 @@
def createValidators(self):
return [BinaryValidator(name=self.name)] + \
- super(SOBLOBCol, self).createValidators(dataType=buffer)
+ super(SOBLOBCol, self).createValidators(dataType=testDataTypeBinary)
def _mysqlType(self):
length = self.length
|