summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2005-12-21 02:36:54 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2005-12-21 02:36:54 +0000
commitaf281888089933ab4c909862b9a41f9ada2dc1a6 (patch)
treec93e8308d8a17091018e56b637d7c766bc60c575 /lib/sqlalchemy
parent3c62b09c5c795bb30f47cc6850bdfefa709d0a94 (diff)
downloadsqlalchemy-af281888089933ab4c909862b9a41f9ada2dc1a6.tar.gz
added "late WHERE" compilation to SELECT, adds where criterion based on extra bind parameters specified
at compilation/execution time
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/ansisql.py17
-rw-r--r--lib/sqlalchemy/sql.py13
2 files changed, 28 insertions, 2 deletions
diff --git a/lib/sqlalchemy/ansisql.py b/lib/sqlalchemy/ansisql.py
index 795a2545b..d8d2662ba 100644
--- a/lib/sqlalchemy/ansisql.py
+++ b/lib/sqlalchemy/ansisql.py
@@ -269,11 +269,24 @@ class ANSICompiler(sql.Compiled):
whereclause = select.whereclause
- # TODO: look at our own parameters, see if they
+ # look at our own parameters, see if they
# are all present in the form of BindParamClauses. if
# not, then append to the above whereclause column conditions
# matching those keys
-
+ if self.parameters is not None:
+ revisit = False
+ for c in inner_columns:
+ if self.parameters.has_key(c.key) and not self.binds.has_key(c.key):
+ value = self.parameters[c.key]
+ elif self.parameters.has_key(c.label) and not self.binds.has_key(c.label):
+ value = self.parameters[c.label]
+ else:
+ continue
+ clause = c==value
+ clause.accept_visitor(self)
+ whereclause = sql.and_(clause, whereclause)
+ self.visit_compound(whereclause)
+
froms = []
for f in select.froms:
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py
index ab762cb39..a634767ea 100644
--- a/lib/sqlalchemy/sql.py
+++ b/lib/sqlalchemy/sql.py
@@ -1155,6 +1155,19 @@ class UpdateBase(ClauseElement):
return parameters
def get_colparams(self, parameters):
+ """this is used by the ANSICompiler to determine the VALUES or SET clause based on the arguments
+ specified to the execute() or compile() method of the INSERT or UPDATE clause:
+
+ insert(mytable).execute(col1='foo', col2='bar')
+ mytable.update().execute(col2='foo', col3='bar')
+
+ in the above examples, the insert() and update() methods have no "values" sent to them
+ at all, so compiling them with no arguments would yield an insert for all table columns,
+ or an update with no SET clauses. but the parameters sent indicate a set of per-compilation
+ arguments that result in a differently compiled INSERT or UPDATE object compared to the
+ original. The "values" parameter to the insert/update is figured as well if present,
+ but the incoming "parameters" sent here take precedence.
+ """
# case one: no parameters in the statement, no parameters in the
# compiled params - just return binds for all the table columns
if parameters is None and self.parameters is None: