raise "Object " + object.__class__.__name__ + "/" + repr(id(object)) + " has no mapper specified"
class Mapper(object):
- def __init__(self, hashkey, class_, table, primarytable = None, scope = "thread", properties = None, primary_keys = None, **kwargs):
+ def __init__(self, hashkey, class_, table, primarytable = None, scope = "thread", properties = None, primary_keys = None, inherits = None, **kwargs):
self.hashkey = hashkey
self.class_ = class_
self.scope = scope
+ if inherits is not None:
+ table = table.join(inherits.table)
self.table = table
tf = TableFinder()
self.table.accept_visitor(tf)
# arguments, for caching purposes
self.properties = properties
+ if inherits is not None and inherits.properties is not None:
+ if self.properties is None:
+ self.properties = {}
+ for key in inherits.properties.keys():
+ self.properties.setdefault(key, inherits.properties[key])
+
# load custom properties
if self.properties is not None:
for key, prop in self.properties.iteritems():
visitor.visit_fromclause(self)
class BindParamClause(ClauseElement):
- def __init__(self, key, value, shortname = None):
+ def __init__(self, key, value, shortname = None, typeengine = None):
self.key = key
self.value = value
self.shortname = shortname
+ self.typeengine = typeengine
def accept_visitor(self, visitor):
visitor.visit_bindparam(self)
def hash_key(self):
return "BindParam(%s, %s, %s)" % (repr(self.key), repr(self.value), repr(self.shortname))
-
+
+ def typeprocess(self, value):
+ if self.typeengine is not None:
+ return self.typeengine.convert_bind_param(value)
+ else:
+ return value
+
class TextClause(ClauseElement):
"""represents any plain text WHERE clause or full SQL statement"""
self.column = column
self.name = column.name
self.columns = [self.column]
-
+ self.typeengine = column.table.engine.type_descriptor(self.column.type)
+
if column.table.name:
self.label = column.table.name + "_" + self.column.name
self.fullname = column.table.name + "." + self.column.name
def _compare(self, operator, obj):
if _is_literal(obj):
if self.column.table.name is None:
- obj = BindParamClause(self.name, obj, shortname = self.name)
+ obj = BindParamClause(self.name, obj, shortname = self.name, typeengine = self.typeengine)
else:
- obj = BindParamClause(self.column.table.name + "_" + self.name, obj, shortname = self.name)
+ obj = BindParamClause(self.column.table.name + "_" + self.name, obj, shortname = self.name, typeengine = self.typeengine)
return BinaryClause(self.column, obj, operator)