diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-03-24 19:24:27 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-03-24 19:24:27 +0000 |
| commit | 748f9b9acfdccf614342aae71c33f4d28df0f471 (patch) | |
| tree | 347302f584a4855b44a218c2ce1e32b107ad86c6 /lib/sqlalchemy/engine | |
| parent | e07cf69deff7e2a9152b41385c4505f1acaa958b (diff) | |
| download | sqlalchemy-748f9b9acfdccf614342aae71c33f4d28df0f471.tar.gz | |
- column labels are now generated in the compilation phase, which
means their lengths are dialect-dependent. So on oracle a label
that gets truncated to 30 chars will go out to 63 characters
on postgres. Also, the true labelname is always attached as the
accessor on the parent Selectable so theres no need to be aware
of the genrerated label names [ticket:512].
- ResultProxy column targeting is greatly simplified, and relies
upon the ANSICompiler's column_labels map to translate the built-in
label on a _ColumnClause (which is now considered to be a unique
identifier of that column) to the label which was generated at compile
time.
- still need to put a baseline of ColumnClause targeting for
ResultProxy objects that originated from a textual query.
Diffstat (limited to 'lib/sqlalchemy/engine')
| -rw-r--r-- | lib/sqlalchemy/engine/base.py | 54 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/default.py | 5 |
2 files changed, 28 insertions, 31 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index 4c9595437..7f7bde81b 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -105,6 +105,12 @@ class Dialect(sql.AbstractDialect): raise NotImplementedError() + def max_identifier_length(self): + """Return the maximum length of identifier names. + + Return None if no limit.""" + return None + def supports_sane_rowcount(self): """Indicate whether the dialect properly implements statements rowcount. @@ -503,7 +509,7 @@ class Connection(Connectable): proxy(str(compiled), parameters) context.post_exec(self.__engine, proxy, compiled, parameters) rpargs = self.__engine.dialect.create_result_proxy_args(self, cursor) - return ResultProxy(self.__engine, self, cursor, context, typemap=compiled.typemap, columns=compiled.columns, **rpargs) + return ResultProxy(self.__engine, self, cursor, context, typemap=compiled.typemap, column_labels=compiled.column_labels, **rpargs) # poor man's multimethod/generic function thingy executors = { @@ -803,7 +809,7 @@ class ResultProxy(object): else: return object.__new__(cls, *args, **kwargs) - def __init__(self, engine, connection, cursor, executioncontext=None, typemap=None, columns=None, should_prefetch=None): + def __init__(self, engine, connection, cursor, executioncontext=None, typemap=None, column_labels=None, should_prefetch=None): """ResultProxy objects are constructed via the execute() method on SQLEngine.""" self.connection = connection @@ -811,7 +817,7 @@ class ResultProxy(object): self.cursor = cursor self.engine = engine self.closed = False - self.columns = columns + self.column_labels = column_labels if executioncontext is not None: self.__executioncontext = executioncontext self.rowcount = executioncontext.get_rowcount(cursor) @@ -823,6 +829,7 @@ class ResultProxy(object): self.props = {} self.keys = [] i = 0 + if metadata is not None: for item in metadata: # sqlite possibly prepending table name to colnames so strip @@ -874,36 +881,21 @@ class ResultProxy(object): try: return self.__key_cache[key] except KeyError: - # TODO: use has_key on these, too many potential KeyErrors being raised - if isinstance(key, sql.ColumnElement): - try: - rec = self.props[key._label.lower()] - except KeyError: - try: - rec = self.props[key.key.lower()] - except KeyError: - try: - rec = self.props[key.name.lower()] - except KeyError: - raise exceptions.NoSuchColumnError("Could not locate column in row for column '%s'" % str(key)) - elif isinstance(key, str): - try: - rec = self.props[key.lower()] - except KeyError: - try: - if self.columns is not None: - rec = self._convert_key(self.columns[key]) - else: - raise - except KeyError: - raise exceptions.NoSuchColumnError("Could not locate column in row for column '%s'" % str(key)) - else: - try: - rec = self.props[key] - except KeyError: - raise exceptions.NoSuchColumnError("Could not locate column in row for column '%s'" % str(key)) + if isinstance(key, int) and key in self.props: + rec = self.props[key] + elif isinstance(key, basestring) and key.lower() in self.props: + rec = self.props[key.lower()] + elif isinstance(key, sql.ColumnElement): + label = self.column_labels.get(key._label, key.name) + if label in self.props: + rec = self.props[label] + + if not "rec" in locals(): + raise exceptions.NoSuchColumnError("Could not locate column in row for column '%s'" % (repr(key))) + self.__key_cache[key] = rec return rec + def _has_key(self, row, key): try: diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index c6e0d9dc4..798d02d32 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -48,6 +48,11 @@ class DefaultDialect(base.Dialect): typeobj = typeobj() return typeobj + def max_identifier_length(self): + # TODO: probably raise this and fill out + # db modules better + return 30 + def oid_column_name(self, column): return None |
