From e5d041c94d0499a5cc88b1f6d0fd610606500686 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 22 Sep 2005 05:59:09 +0000 Subject: [PATCH] --- lib/sqlalchemy/types.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) 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): -- 2.47.2