- exists() becomes useable as a standalone selectable, not just in a
WHERE clause
- correlated subqueries work inside of ORDER BY, GROUP BY
+ - fixed function execution with explicit connections, when you dont
+ explicitly say "select()" off the function, i.e.
+ conn.execute(func.dosomething())
- orm:
- a full select() construct can be passed to query.select() (which
worked anyway), but also query.selectfirst(), query.selectone() which
return self.execute(object, *multiparams, **params).scalar()
def execute(self, object, *multiparams, **params):
- return Connection.executors[type(object).__mro__[-2]](self, object, *multiparams, **params)
+ for c in type(object).__mro__:
+ if c in Connection.executors:
+ return Connection.executors[c](self, object, *multiparams, **params)
+ else:
+ raise exceptions.InvalidRequestError("Unexecuteable object type: " + str(type(object)))
def execute_default(self, default, **kwargs):
return default.accept_schema_visitor(self.__engine.dialect.defaultrunner(self.__engine, self.proxy, **kwargs))
return [multiparams[0]]
else:
return multiparams
-
+
+ def execute_function(self, func, *multiparams, **params):
+ return self.execute_clauseelement(func.select(), *multiparams, **params)
+
def execute_clauseelement(self, elem, *multiparams, **params):
executemany = len(multiparams) > 0
if executemany:
def execute_compiled(self, compiled, *multiparams, **params):
"""Execute a sql.Compiled object."""
-
if not compiled.can_execute:
raise exceptions.ArgumentError("Not an executeable clause: %s" % (str(compiled)))
cursor = self.__engine.dialect.create_cursor(self.connection)
# poor man's multimethod/generic function thingy
executors = {
+ sql._Function : execute_function,
sql.ClauseElement : execute_clauseelement,
sql.ClauseVisitor : execute_compiled,
schema.SchemaItem:execute_default,
z = testbase.db.func.current_date().scalar()
assert x == y == z
+ def test_conn_functions(self):
+ conn = testbase.db.connect()
+ try:
+ x = conn.execute(func.current_date()).scalar()
+ y = conn.execute(func.current_date().select()).scalar()
+ z = conn.scalar(func.current_date())
+ finally:
+ conn.close()
+ assert x == y == z
+
def test_update_functions(self):
"""test sending functions and SQL expressions to the VALUES and SET clauses of INSERT/UPDATE instances,
and that column-level defaults get overridden"""