- sql
- Added math negation operator support, -x.
-
+
+ - FunctionElement subclasses are now directly executable the
+ same way any func.foo() construct is, with automatic
+ SELECT being applied when passed to execute().
+
+ - The "type" and "bind" keyword arguments of a func.foo()
+ construct are now local to "func." constructs and are
+ not part of the FunctionElement base class, allowing
+ a "type" to be handled in a custom constructor or
+ class-level variable.
+
- mssql
- Re-established initial support for pymssql.
# poor man's multimethod/generic function thingy
executors = {
- expression.Function: _execute_function,
+ expression.FunctionElement: _execute_function,
expression.ClauseElement: _execute_clauseelement,
Compiled: _execute_compiled,
schema.SchemaItem: _execute_default,
class FunctionElement(ColumnElement, FromClause):
"""Base for SQL function-oriented constructs."""
-
+
def __init__(self, *clauses, **kwargs):
- self._bind = kwargs.get('bind', None)
args = [_literal_as_binds(c, self.name) for c in clauses]
self.clause_expr = ClauseList(
operator=operators.comma_op,
group_contents=True, *args).\
self_group()
- self.type = sqltypes.to_instance(kwargs.get('type_', None))
@property
def columns(self):
def __init__(self, name, *clauses, **kw):
self.packagenames = kw.pop('packagenames', None) or []
self.name = name
+ self._bind = kw.get('bind', None)
+ self.type = sqltypes.to_instance(kw.get('type_', None))
+
FunctionElement.__init__(self, *clauses, **kw)
def _bind_param(self, obj):
assert isinstance(x.execute().scalar(), datetime.date)
def test_conn_execute(self):
+ from sqlalchemy.sql.expression import FunctionElement
+ from sqlalchemy.ext.compiler import compiles
+
+ class myfunc(FunctionElement):
+ type = DATE()
+
+ @compiles(myfunc)
+ def compile(elem, compiler, **kw):
+ return compiler.process(func.current_date())
+
conn = testing.db.connect()
try:
x = conn.execute(func.current_date()).scalar()
y = conn.execute(func.current_date().select()).scalar()
z = conn.scalar(func.current_date())
+ q = conn.scalar(myfunc())
finally:
conn.close()
- assert (x == y == z) is True
-
+ assert (x == y == z == q) is True
+
@engines.close_first
def test_update(self):
"""