diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-03-25 16:51:29 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-03-25 16:51:29 +0000 |
commit | 92a5df77538069efd9f8cfc14cf83807ce43c288 (patch) | |
tree | 3e5056cfae005a54d59c3c708df7b70d67f197f3 /lib/sqlalchemy/sql/functions.py | |
parent | df1000839ba2925031afa2e9769a482add9f404e (diff) | |
download | sqlalchemy-92a5df77538069efd9f8cfc14cf83807ce43c288.tar.gz |
- Added generic func.random (non-standard SQL)
Diffstat (limited to 'lib/sqlalchemy/sql/functions.py')
-rw-r--r-- | lib/sqlalchemy/sql/functions.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index be1d8eb61..66954168c 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -1,16 +1,18 @@ from sqlalchemy import types as sqltypes -from sqlalchemy.sql.expression import _Function, _literal_as_binds, ClauseList, _FigureVisitName +from sqlalchemy.sql.expression import _Function, _literal_as_binds, \ + ClauseList, _FigureVisitName from sqlalchemy.sql import operators + class _GenericMeta(_FigureVisitName): def __init__(cls, clsname, bases, dict): cls.__visit_name__ = 'function' type.__init__(cls, clsname, bases, dict) - + def __call__(self, *args, **kwargs): args = [_literal_as_binds(c) for c in args] return type.__call__(self, *args, **kwargs) - + class GenericFunction(_Function): __metaclass__ = _GenericMeta @@ -20,16 +22,21 @@ class GenericFunction(_Function): self.name = self.__class__.__name__ self._bind = kwargs.get('bind', None) if group: - self.clause_expr = ClauseList(operator=operators.comma_op, group_contents=True, *args).self_group() + self.clause_expr = ClauseList( + operator=operators.comma_op, + group_contents=True, *args).self_group() else: - self.clause_expr = ClauseList(operator=operators.comma_op, group_contents=True, *args) - self.type = sqltypes.to_instance(type_ or getattr(self, '__return_type__', None)) - + self.clause_expr = ClauseList( + operator=operators.comma_op, + group_contents=True, *args) + self.type = sqltypes.to_instance( + type_ or getattr(self, '__return_type__', None)) + class AnsiFunction(GenericFunction): def __init__(self, **kwargs): GenericFunction.__init__(self, **kwargs) - + class coalesce(GenericFunction): def __init__(self, *args, **kwargs): kwargs.setdefault('type_', _type_from_args(args)) @@ -37,7 +44,7 @@ class coalesce(GenericFunction): class now(GenericFunction): __return_type__ = sqltypes.DateTime - + class concat(GenericFunction): __return_type__ = sqltypes.String def __init__(self, *args, **kwargs): @@ -48,10 +55,15 @@ class char_length(GenericFunction): def __init__(self, arg, **kwargs): GenericFunction.__init__(self, args=[arg], **kwargs) - + +class random(GenericFunction): + def __init__(self, *args, **kwargs): + kwargs.setdefault('type_', None) + GenericFunction.__init__(self, args=args, **kwargs) + class current_date(AnsiFunction): __return_type__ = sqltypes.Date - + class current_time(AnsiFunction): __return_type__ = sqltypes.Time |