Project

General

Profile

« Previous | Next » 

Revision 3467

Autogenerated SQL code: Use new strings.indent() where needed

View differences:

lib/sql_gen.py
486 486
    def to_str(self, db, body):
487 487
        body = as_Code(body)
488 488
        
489
        if self.handler != None: handler_str = '\n'+self.handler.to_str(db)
489
        if self.handler != None:
490
            handler_str = '\n'+strings.indent(self.handler.to_str(db), 2)
490 491
        else: handler_str = ' NULL;\n'
491 492
        
492 493
        str_ = '''\
493 494
BEGIN
494
'''+body.to_str(db)+'''\
495
'''+strings.indent(body.to_str(db))+'''\
495 496
EXCEPTION
496 497
    WHEN '''+self.exc+''' THEN'''+handler_str+'''\
497 498
END;\
......
526 527
DECLARE
527 528
    '''+self.row_var.to_str(db)+''' '''+self.row_type+''';
528 529
BEGIN
529
    /* Need an EXCEPTION block for each individual row because "When an error is
530
    caught by an EXCEPTION clause, [...] all changes to persistent database
531
    state within the block are rolled back."
532
    This is unfortunate because "A block containing an EXCEPTION clause is
533
    significantly more expensive to enter and exit than a block without one."
530
    /* Need an EXCEPTION block for each individual row because "When
531
    an error is caught by an EXCEPTION clause, [...] all changes to
532
    persistent database state within the block are rolled back."
533
    This is unfortunate because "A block containing an EXCEPTION
534
    clause is significantly more expensive to enter and exit than a
535
    block without one."
534 536
    (http://www.postgresql.org/docs/8.3/static/plpgsql-control-structures.html\
535 537
#PLPGSQL-ERROR-TRAPPING)
536 538
    */
537 539
    FOR '''+(', '.join((v.to_str(db) for v in row_vars)))+''' IN
538
'''+self.select_query.to_str(db)+'''
540
'''+strings.indent(self.select_query.to_str(db), 2)+'''\
539 541
    LOOP
540
'''+self.exc_handler.to_str(db, self.with_row)+'''
542
'''+strings.indent(self.exc_handler.to_str(db, self.with_row), 2)+'''\
541 543
    END LOOP;
542 544
END;\
543 545
'''
lib/sql.py
793 793
        query = sql_gen.RowExcIgnore(table.to_str(db)+'%ROWTYPE', select_query,
794 794
'''\
795 795
RETURN QUERY
796
'''+mk_insert(sql_gen.Values(row).to_str(db))+'''
797
;
796
'''+strings.indent(mk_insert(sql_gen.Values(row).to_str(db)))+''';
798 797
'''
799 798
            , cols)
800 799
    else: query = mk_insert(select_query)
lib/sql_io.py
59 59
    error text := SQLERRM;
60 60
BEGIN
61 61
    -- Insert the value and error for *each* source column.
62
'''+sql_gen.RowExcIgnore('text', col_names_query, insert_query,
63
    row_var=errors_table_cols[0]).to_str(db)+'''
62
'''+strings.indent(sql_gen.RowExcIgnore('text', col_names_query, insert_query,
63
    row_var=errors_table_cols[0]).to_str(db))+'''
64 64
END;
65 65
'''
66 66
    else:
......
100 100
    if not save_errors: modifiers = 'IMMUTABLE '+modifiers
101 101
    handler = data_exception_handler(db, srcs, errors_table)
102 102
    body = sql_gen.CustomCode(handler.to_str(db, '''\
103
    /* The explicit cast to the return type is needed to make the cast happen
104
    inside the try block. (Implicit casts to the return type happen at the end
105
    of the function, outside any block.) */
106
    RETURN value::'''+type_+''';
103
/* The explicit cast to the return type is needed to make the cast happen
104
inside the try block. (Implicit casts to the return type happen at the end
105
of the function, outside any block.) */
106
RETURN value::'''+type_+''';
107 107
'''))
108 108
    body.lang='plpgsql'
109 109
    def_ = sql_gen.FunctionDef(function, type_, body, ['value text'], modifiers)

Also available in: Unified diff