root/galaxy-central/eggs/SQLAlchemy-0.5.6_dev_r6498-py2.6.egg/sqlalchemy/sql/functions.py

リビジョン 3, 3.1 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1from sqlalchemy import types as sqltypes
2from sqlalchemy.sql.expression import (
3    ClauseList, Function, _literal_as_binds, text
4    )
5from sqlalchemy.sql import operators
6from sqlalchemy.sql.visitors import VisitableType
7
8class _GenericMeta(VisitableType):
9    def __call__(self, *args, **kwargs):
10        args = [_literal_as_binds(c) for c in args]
11        return type.__call__(self, *args, **kwargs)
12
13class GenericFunction(Function):
14    __metaclass__ = _GenericMeta
15
16    def __init__(self, type_=None, args=(), **kwargs):
17        self.packagenames = []
18        self.name = self.__class__.__name__
19        self._bind = kwargs.get('bind', None)
20        self.clause_expr = ClauseList(
21                operator=operators.comma_op,
22                group_contents=True, *args).self_group()
23        self.type = sqltypes.to_instance(
24            type_ or getattr(self, '__return_type__', None))
25
26class AnsiFunction(GenericFunction):
27    def __init__(self, **kwargs):
28        GenericFunction.__init__(self, **kwargs)
29
30class ReturnTypeFromArgs(GenericFunction):
31    """Define a function whose return type is the same as its arguments."""
32   
33    def __init__(self, *args, **kwargs):
34        kwargs.setdefault('type_', _type_from_args(args))
35        GenericFunction.__init__(self, args=args, **kwargs)
36
37class coalesce(ReturnTypeFromArgs):
38    pass
39
40class max(ReturnTypeFromArgs):
41    pass
42
43class min(ReturnTypeFromArgs):
44    pass
45
46class sum(ReturnTypeFromArgs):
47    pass
48
49class now(GenericFunction):
50    __return_type__ = sqltypes.DateTime
51
52class concat(GenericFunction):
53    __return_type__ = sqltypes.String
54    def __init__(self, *args, **kwargs):
55        GenericFunction.__init__(self, args=args, **kwargs)
56
57class char_length(GenericFunction):
58    __return_type__ = sqltypes.Integer
59
60    def __init__(self, arg, **kwargs):
61        GenericFunction.__init__(self, args=[arg], **kwargs)
62
63class random(GenericFunction):
64    def __init__(self, *args, **kwargs):
65        kwargs.setdefault('type_', None)
66        GenericFunction.__init__(self, args=args, **kwargs)
67
68class count(GenericFunction):
69    """The ANSI COUNT aggregate function.  With no arguments, emits COUNT \*."""
70
71    __return_type__ = sqltypes.Integer
72
73    def __init__(self, expression=None, **kwargs):
74        if expression is None:
75            expression = text('*')
76        GenericFunction.__init__(self, args=(expression,), **kwargs)
77
78class current_date(AnsiFunction):
79    __return_type__ = sqltypes.Date
80
81class current_time(AnsiFunction):
82    __return_type__ = sqltypes.Time
83
84class current_timestamp(AnsiFunction):
85    __return_type__ = sqltypes.DateTime
86
87class current_user(AnsiFunction):
88    __return_type__ = sqltypes.String
89
90class localtime(AnsiFunction):
91    __return_type__ = sqltypes.DateTime
92
93class localtimestamp(AnsiFunction):
94    __return_type__ = sqltypes.DateTime
95
96class session_user(AnsiFunction):
97    __return_type__ = sqltypes.String
98
99class sysdate(AnsiFunction):
100    __return_type__ = sqltypes.DateTime
101
102class user(AnsiFunction):
103    __return_type__ = sqltypes.String
104
105def _type_from_args(args):
106    for a in args:
107        if not isinstance(a.type, sqltypes.NullType):
108            return a.type
109    else:
110        return sqltypes.NullType
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。