Project

General

Profile

« Previous | Next » 

Revision 3448

sql_gen.py: FunctionDef: Determine the lang from the body's Code object instead of receiving it as a parameter

View differences:

lib/sql_gen.py
449 449
#### Definitions
450 450

  
451 451
class FunctionDef(Code):
452
    def __init__(self, function, return_type, body, lang='sql'):
452
    def __init__(self, function, return_type, body):
453 453
        Code.__init__(self)
454 454
        
455 455
        body = as_Code(body)
......
457 457
        self.function = function
458 458
        self.return_type = return_type
459 459
        self.body = body
460
        self.lang = lang
461 460
    
462 461
    def to_str(self, db):
463 462
        str_ = '''\
464 463
CREATE FUNCTION '''+self.function.to_str(db)+'''()
465 464
RETURNS SETOF '''+self.return_type+'''
466
LANGUAGE '''+self.lang+'''
465
LANGUAGE '''+self.body.lang+'''
467 466
AS $$
468 467
'''+self.body.to_str(db)+'''
469 468
$$;
lib/sql.py
781 781
    return_type = 'unknown'
782 782
    if returning != None: return_type = returning.to_str(db)+'%TYPE'
783 783
    
784
    lang = 'sql'
785 784
    if ignore:
786 785
        # Always return something to set the correct rowcount
787 786
        if returning == None: returning = sql_gen.NamedCol('NULL', None)
788 787
        
789 788
        embeddable = True # must use function
790
        lang = 'plpgsql'
791 789
        
792 790
        if cols == None:
793 791
            row = [sql_gen.Col(sql_gen.all_cols, 'row')]
......
795 793
        else:
796 794
            row_vars = row = [sql_gen.Col(c.name, 'row') for c in cols]
797 795
        
798
        query = '''\
796
        query = sql_gen.CustomCode('''\
799 797
DECLARE
800 798
    row '''+table.to_str(db)+'''%ROWTYPE;
801 799
BEGIN
......
819 817
        END;
820 818
    END LOOP;
821 819
END;\
822
'''
820
''')
821
        query.lang = 'plpgsql'
823 822
    else: query = mk_insert(select_query)
824 823
    
825 824
    if embeddable:
......
829 828
        while True:
830 829
            try:
831 830
                function = db.TempFunction(function_name)
832
                def_ = sql_gen.FunctionDef(function, return_type, query, lang)
831
                def_ = sql_gen.FunctionDef(function, return_type, query)
833 832
                
834 833
                run_query(db, def_.to_str(db), recover=True, cacheable=True,
835 834
                    log_ignore_excs=(DuplicateException,))

Also available in: Unified diff