From: Mike Bayer Date: Thu, 22 Sep 2005 04:15:46 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rel_0_1_0~637 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb74b7a8bc524496d7de0923df843a093a235c6f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git --- diff --git a/lib/sqlalchemy/engine.py b/lib/sqlalchemy/engine.py index d177168c2d..9b55b5ab0d 100644 --- a/lib/sqlalchemy/engine.py +++ b/lib/sqlalchemy/engine.py @@ -24,6 +24,14 @@ import sqlalchemy.util as util import sqlalchemy.sql as sql import StringIO +class TypeDescriptor(object): + def get_col_spec(self): + raise NotImplementedError() + def convert_bind_param(self, value): + raise NotImplementedError() + def convert_result_value(self, value): + raise NotImplementedError() + class SchemaIterator(schema.SchemaVisitor): """a visitor that can gather text into a buffer and execute the contents of the buffer.""" @@ -58,6 +66,9 @@ class SQLEngine(schema.SchemaEngine): self.tables = {} self.notes = {} + def type_descriptor(self, type): + raise NotImplementedError() + def schemagenerator(self, proxy, **params): raise NotImplementedError() @@ -174,6 +185,7 @@ class SQLEngine(schema.SchemaEngine): c = connection.cursor() self.pre_exec(connection, c, statement, parameters, echo = echo, **kwargs) + # TODO: affix TypeDescriptors ehre to pre-process bind params if isinstance(parameters, list): c.executemany(statement, parameters) else: @@ -186,12 +198,14 @@ class SQLEngine(schema.SchemaEngine): class ResultProxy: - def __init__(self, cursor, echo = False): + def __init__(self, cursor, echo = False, engine = None): self.cursor = cursor self.echo = echo + self.engine = engine metadata = cursor.description self.props = {} i = 0 + # TODO: affix TypeDescriptors here to post-process results if metadata is not None: for item in metadata: self.props[item[0]] = i diff --git a/lib/sqlalchemy/mapper.py b/lib/sqlalchemy/mapper.py index dd943325b5..ab30319c58 100644 --- a/lib/sqlalchemy/mapper.py +++ b/lib/sqlalchemy/mapper.py @@ -163,9 +163,9 @@ class Mapper(object): # TODO: get some notion of "primary mapper" going so multiple mappers dont collide self.class_._mapper = self.hashkey - def instances(self, cursor, db = None): + def instances(self, cursor, db): result = util.HistoryArraySet() - cursor = engine.ResultProxy(cursor, echo = db and db.echo, engine = db) + cursor = engine.ResultProxy(cursor, db, echo = db.echo) imap = {} while True: row = cursor.fetchone() diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index fdce9cf8cc..c83ccddae7 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -20,36 +20,41 @@ import copy __ALL__ = ['Table', 'Column', 'Sequence', 'ForeignKey', 'INT', 'CHAR', 'VARCHAR', 'TEXT', 'FLOAT', 'DECIMAL', - 'TIMESTAMP', 'DATETIME', 'CLOB', 'BLOB', 'BOOLEAN' + 'TIMESTAMP', 'DATETIME', 'CLOB', 'BLOB', 'BOOLEAN', 'String', 'Integer', 'Numeric', 'DateTime', 'Binary', ] -class INT: - """integer datatype""" - pass - -INTEGER = INT -class CHAR: - """character datatype""" +class String: def __init__(self, length): self.length = length -class VARCHAR: - def __init__(self, length): - self.length = length +class Integer: + """integer datatype""" + pass class Numeric: def __init__(self, precision, length): self.precision = precision self.length = length + +class DateTime: + pass + +class Binary:pass +class Boolean:pass + class FLOAT(Numeric):pass -class TEXT: pass +class TEXT(String): pass class DECIMAL(Numeric):pass -class TIMESTAMP: pass -class DATETIME: pass -class CLOB: pass -class BLOB: pass -class BOOLEAN: pass +class INT(Integer):pass +INTEGER = INT +class TIMESTAMP(DateTime): pass +class DATETIME(DateTime): pass +class CLOB(String): pass +class VARCHAR(String): pass +class CHAR(String):pass +class BLOB(Binary): pass +class BOOLEAN(Boolean): pass class SchemaItem(object): diff --git a/test/mapper.py b/test/mapper.py index 9a31c00a7e..cf482dbe13 100644 --- a/test/mapper.py +++ b/test/mapper.py @@ -178,7 +178,7 @@ class EagerTest(AssertMixin): c = s.compile() print "\n" + str(c) + repr(c.get_params()) - l = m.instances(s.execute(emailad = 'jack@bean.com')) + l = m.instances(s.execute(emailad = 'jack@bean.com'), users.engine) print repr(l) def testmulti(self):