From: Mike Bayer Date: Thu, 22 Sep 2005 05:59:09 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rel_0_1_0~626 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5d041c94d0499a5cc88b1f6d0fd610606500686;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git --- diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index a138eb4c8c..e0860c83a3 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -1,26 +1,29 @@ __ALL__ = [ 'INT', 'CHAR', 'VARCHAR', 'TEXT', 'FLOAT', 'DECIMAL', - 'TIMESTAMP', 'DATETIME', 'CLOB', 'BLOB', 'BOOLEAN', 'String', 'Integer', 'Numeric', 'DateTime', 'Binary', + 'TIMESTAMP', 'DATETIME', 'CLOB', 'BLOB', 'BOOLEAN', 'String', 'Integer', 'Numeric', 'DateTime', 'Binary', 'Boolean' ] class TypeEngineMeta(type): - def convert_bind_param(cls, value): - return cls.singleton.convert_bind_param(value) - def convert_result_value(cls, value): - return cls.singleton.convert_result_value(value) - + typeself = property(lambda cls:cls.singleton) + typeclass = property(lambda cls: cls) + class TypeEngine(object): __metaclass__ = TypeEngineMeta - def get_col_spec(self): + def get_col_spec(self, typeobj): raise NotImplementedError() def convert_bind_param(self, value): raise NotImplementedError() def convert_result_value(self, value): raise NotImplementedError() + def adapt(self, typeobj): + return typeobj() + typeclass = property(lambda s: s.__class__) + typeself = property(lambda s:s) + class NullTypeEngine(TypeEngine): - def get_col_spec(self): + def get_col_spec(self, typeobj): raise NotImplementedError() def convert_bind_param(self, value): return value @@ -30,6 +33,8 @@ class NullTypeEngine(TypeEngine): class String(TypeEngine): def __init__(self, length): self.length = length + def adapt(self, typeobj): + return typeobj(self.length) String.singleton = String(-1) class Integer(TypeEngine): @@ -41,6 +46,8 @@ class Numeric(TypeEngine): def __init__(self, precision, length): self.precision = precision self.length = length + def adapt(self, typeobj): + return typeobj(self.precision, self.length) Numeric.singleton = Numeric(10, 2) class DateTime(TypeEngine):