Project

General

Profile

« Previous | Next » 

Revision 2941

sql_gen.py: Added NamedArg. FunctionCall: Support named arguments (http://www.postgresql.org/docs/9.0/static/sql-syntax-calling-funcs.html).

View differences:

lib/sql_gen.py
315 315

  
316 316
class InternalFunction(CustomCode): pass
317 317

  
318
class NamedArg(NamedCol):
319
    def __init__(self, name, value):
320
        NamedCol.__init__(self, name, value)
321
    
322
    def to_str(self, db):
323
        return Col.to_str(self, db)+' := '+self.code.to_str(db)
324

  
318 325
class FunctionCall(Code):
319
    def __init__(self, function, *args):
326
    def __init__(self, function, *args, **kw_args):
320 327
        '''
321 328
        @param args [Code|literal-value...] The function's arguments
322 329
        '''
323 330
        if not isinstance(function, Code): function = Function(function)
324
        args = map(remove_col_rename, map(as_Value, args))
331
        def filter_(arg): return remove_col_rename(as_Value(arg))
332
        args = map(filter_, args)
333
        args += [NamedArg(k, filter_(v)) for k, v in kw_args.iteritems()]
325 334
        
326 335
        self.function = function
327 336
        self.args = args

Also available in: Unified diff