diff options
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 29 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/util.py | 101 |
2 files changed, 10 insertions, 120 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 43b6fb15b..fa4ac5a9f 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -182,27 +182,18 @@ class DefaultCompiler(engine.Compiled, visitors.ClauseVisitor): return None def construct_params(self, params=None): - """Return a sql.util.ClauseParameters object. + """return a dictionary of bind parameter keys and values""" - Combines the given bind parameter dictionary (string keys to object values) - with the _BindParamClause objects stored within this Compiled object - to produce a ClauseParameters structure, representing the bind arguments - for a single statement execution, or one element of an executemany execution. - """ - - d = sql_util.ClauseParameters(self.dialect, self.positiontup) - - pd = params or {} - - bind_names = self.bind_names - for key, bind in self.binds.iteritems(): - # the following is an inlined ClauseParameters.set_parameter() - name = bind_names[bind] - d._binds[name] = [bind, name, pd.get(key, bind.value)] - return d + if params: + pd = {} + for key, bindparam in self.binds.iteritems(): + name = self.bind_names[bindparam] + pd[name] = params.get(key, bindparam.value) + return pd + else: + return dict([(self.bind_names[bindparam], bindparam.value) for bindparam in self.bind_names]) - params = property(lambda self:self.construct_params(), doc="""Return the `ClauseParameters` corresponding to this compiled object. - A shortcut for `construct_params()`.""") + params = property(lambda self:self.construct_params(), doc="""return a dictionary of bind parameter keys and values""") def default_from(self): """Called when a SELECT statement has no froms, and no FROM clause is to be appended. diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 48996fe7b..8876f42ba 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -3,107 +3,6 @@ from sqlalchemy.sql import expression, visitors """Utility functions that build upon SQL and Schema constructs.""" -class ClauseParameters(object): - """Represent a dictionary/iterator of bind parameter key names/values. - - Tracks the original [sqlalchemy.sql#_BindParamClause] objects as well as the - keys/position of each parameter, and can return parameters as a - dictionary or a list. Will process parameter values according to - the ``TypeEngine`` objects present in the ``_BindParamClause`` instances. - """ - - __slots__ = 'dialect', '_binds', 'positional' - - def __init__(self, dialect, positional=None): - self.dialect = dialect - self._binds = {} - if positional is None: - self.positional = [] - else: - self.positional = positional - - def get_parameter(self, key): - return self._binds[key] - - def set_parameter(self, bindparam, value, name): - self._binds[name] = [bindparam, name, value] - - def get_original(self, key): - return self._binds[key][2] - - def get_type(self, key): - return self._binds[key][0].type - - def get_processors(self): - """return a dictionary of bind 'processing' functions""" - return dict([ - (key, value) for key, value in - [( - key, - self._binds[key][0].bind_processor(self.dialect) - ) for key in self._binds] - if value is not None - ]) - - def get_processed(self, key, processors): - if key in processors: - return processors[key](self._binds[key][2]) - else: - return self._binds[key][2] - - def keys(self): - return self._binds.keys() - - def __iter__(self): - return iter(self.keys()) - - def __getitem__(self, key): - (bind, name, value) = self._binds[key] - processor = bind.bind_processor(self.dialect) - if processor is not None: - return processor(value) - else: - return value - - def __contains__(self, key): - return key in self._binds - - def set_value(self, key, value): - self._binds[key][2] = value - - def get_original_dict(self): - return dict([(name, value) for (b, name, value) in self._binds.values()]) - - def get_raw_list(self, processors): - binds, res = self._binds, [] - for key in self.positional: - if key in processors: - res.append(processors[key](binds[key][2])) - else: - res.append(binds[key][2]) - return res - - def get_raw_dict(self, processors, encode_keys=False): - binds, res = self._binds, {} - if encode_keys: - encoding = self.dialect.encoding - for key in self.keys(): - if key in processors: - res[key.encode(encoding)] = processors[key](binds[key][2]) - else: - res[key.encode(encoding)] = binds[key][2] - else: - for key in self.keys(): - if key in processors: - res[key] = processors[key](binds[key][2]) - else: - res[key] = binds[key][2] - return res - - def __repr__(self): - return self.__class__.__name__ + ":" + repr(self.get_original_dict()) - - class TableCollection(object): def __init__(self, tables=None): |