Beispiel #1
0
 def result_processor(self, dialect, coltype=None):
     chemical_dialect = DialectManager.get_chemical_dialect(dialect)
     def process(value):
         if value is not None:
             return chemical_dialect.process_result(value, self)
         else:
             return value
     return process
Beispiel #2
0
def _get_function(element, compiler, params, within_column_clause):
    """For elements of type BaseFunction, the database specific function data 
    is looked up and a executable sqlalchemy.sql.expression.Function object 
    is returned.
    """
    from razi.dialect import DialectManager 
    chemical_dialect = DialectManager.get_chemical_dialect(compiler.dialect)
    function_data = chemical_dialect.get_function(element.__class__)
    
    if isinstance(function_data, list):
        """if we have a list of function names, create cascaded Function objects
        for all function names in the list::
        
            ['FUNC2', 'PKG1.FUNC1'] --> FUNC2(PKG1.FUNC1(..))
        """
        function = None
        for name in reversed(function_data):
            packages = name.split('.')
            
            if function is None:
                """for the innermost function use the passed-in parameters as argument,
                otherwise use the prior created function
                """
                args = params
            else:
                args = [function]
                
            function = Function(packages.pop(-1), 
                        packagenames=packages,
                        *args
                        )
        
        return function
    
    elif isinstance(function_data, types.FunctionType):
        """if we have a function, call this function with the parameters and 
        return the created Function object
        """
        if hasattr(element, 'flags'):
            # when element is a BaseFunction
            flags = element.flags
        else:
            flags = {}
            
        return function_data(params, within_column_clause, **flags)
    
    else:
        packages = function_data.split('.')
        
        return Function(packages.pop(-1), 
                        packagenames=packages, 
                        *params
                        )
Beispiel #3
0
def __compile_base_function(element, compiler, **kw):
    
    params = [parse_clause(argument, compiler) 
              for argument in element.arguments]
    
    from razi.dialect import DialectManager 
    chemical_dialect = DialectManager.get_chemical_dialect(compiler.dialect)
    
    if chemical_dialect.is_member_function(element.__class__):
        chemical = params.pop(0)
        function_name = chemical_dialect.get_function(element.__class__)
        
        if isinstance(function_name, str):
            """If the function is defined as String (e.g. 
            "oracle_functions.dims : 'Get_Dims'"), we construct the function 
            call in the query ourselves. This is because SQLAlchemy, 
            at this point of the compile process, does not add parenthesis for 
            functions without arguments when using Oracle.
            Otherwise let SQLAlchemy build the query. Note that this won't work
            for Oracle with functions without parameters."""
            
            return "%s.%s(%s)" % (
                        compiler.process(chemical),
                        function_name,
                        ", ".join([compiler.process(e) for e in params]) 
                        )
        else:
            function = _get_function(element, compiler, params,
                                     kw.get('within_columns_clause', False))
            
            return "%s.%s" % (
                compiler.process(chemical), compiler.process(function)      
                )
            
    elif chemical_dialect.is_property(element.__class__):
        chemical = params.pop(0)
        function_name = chemical_dialect.get_function(element.__class__)
        
        return "%s.%s" % (compiler.process(chemical), function_name)
        
    else:
        function = _get_function(element, compiler, params, 
                                 kw.get('within_columns_clause', False))
        return compiler.process(function)
Beispiel #4
0
def __compile_dialect_specific_function(element, compiler, **kw):
    from razi.dialect import DialectManager 
    chemical_dialect = DialectManager.get_chemical_dialect(compiler.dialect)
    function = chemical_dialect.get_function(element.__class__)
    args = list(element.arguments)
    return compiler.process(function(compiler, element, *args))
Beispiel #5
0
def _compile_chemtype(type_, compiler, **kwargs):
    chemical_dialect = DialectManager.get_chemical_dialect(compiler.dialect)
    return chemical_dialect.db_column_type(type_)