non-ambiguous.
- sql:
- added "fetchmany()" support to ResultProxy
+ - added support for column "key" attribute to be useable in row[<key>]/row.<key>
- changed "BooleanExpression" to subclass from "BinaryExpression", so that boolean
expressions can also follow column-clause behaviors (i.e. label(), etc).
- trailing underscores are trimmed from func.<xxx> calls, such as func.if_()
# which will be passed to a ResultProxy and used for resultset-level value conversion
self.typemap = {}
+ # a dictionary of select columns mapped to their name or key
+ self.columns = {}
+
# True if this compiled represents an INSERT
self.isinsert = False
# if we are within a visit to a Select, set up the "typemap"
# for this column which is used to translate result set values
self.typemap.setdefault(column.name.lower(), column.type)
+ self.columns.setdefault(column.key, column)
if column.table is None or not column.table.named_with_column():
self.strings[column] = self.preparer.format_column(column)
else:
context.pre_exec(self.__engine, proxy, compiled, parameters)
proxy(str(compiled), parameters)
context.post_exec(self.__engine, proxy, compiled, parameters)
- return ResultProxy(self.__engine, self, cursor, context, typemap=compiled.typemap)
+ return ResultProxy(self.__engine, self, cursor, context, typemap=compiled.typemap, columns=compiled.columns)
# poor man's multimethod/generic function thingy
executors = {
def convert_result_value(self, arg, engine):
raise exceptions.InvalidRequestError("Ambiguous column name '%s' in result set! try 'use_labels' option on select statement." % (self.key))
- def __init__(self, engine, connection, cursor, executioncontext=None, typemap=None):
+ def __init__(self, engine, connection, cursor, executioncontext=None, typemap=None, columns=None):
"""ResultProxy objects are constructed via the execute() method on SQLEngine."""
self.connection = connection
self.dialect = engine.dialect
self.cursor = cursor
self.engine = engine
self.closed = False
+ self.columns = columns
if executioncontext is not None:
self.__executioncontext = executioncontext
self.rowcount = executioncontext.get_rowcount(cursor)
try:
rec = self.props[key.key.lower()]
except KeyError:
-# rec = self.props[key.name.lower()]
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):
- rec = self.props[key.lower()]
+ 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:
- rec = self.props[key]
+ try:
+ rec = self.props[key]
+ except KeyError:
+ raise exceptions.NoSuchColumnError("Could not locate column in row for column '%s'" % str(key))
self.__key_cache[key] = rec
return rec