Revision 2770
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
784 | 784 |
|
785 | 785 |
assert not isinstance(col, sql_gen.NamedCol) |
786 | 786 |
|
787 |
if save_errors: |
|
788 |
errors_table = sql_gen.as_Table(errors_table) |
|
789 |
srcs = map(sql_gen.to_name_only_col, col.srcs) |
|
790 |
function_name = str(sql_gen.FunctionCall(type_, *srcs)) |
|
791 |
else: function_name = type_ |
|
787 |
errors_table = sql_gen.as_Table(errors_table) |
|
788 |
srcs = map(sql_gen.to_name_only_col, col.srcs) |
|
789 |
function_name = str(sql_gen.FunctionCall(type_, *srcs)) |
|
792 | 790 |
function = sql_gen.TempFunction(function_name, db.autocommit) |
793 | 791 |
|
794 | 792 |
while True: |
... | ... | |
797 | 795 |
CREATE FUNCTION '''+function.to_str(db)+'''(value text) |
798 | 796 |
RETURNS '''+type_+''' |
799 | 797 |
LANGUAGE plpgsql |
800 |
''' |
|
801 |
if not save_errors: query += 'IMMUTABLE\n' |
|
802 |
query += '''\ |
|
803 | 798 |
STRICT |
804 | 799 |
AS $$ |
805 | 800 |
BEGIN |
... | ... | |
809 | 804 |
RETURN value::'''+type_+'''; |
810 | 805 |
EXCEPTION |
811 | 806 |
WHEN data_exception THEN |
812 |
''' |
|
813 |
if save_errors: |
|
814 |
query += '''\ |
|
815 | 807 |
-- Save error in errors table. |
816 | 808 |
-- Insert the value and error for *each* source column. |
817 | 809 |
'''+mk_track_data_error(db, errors_table, srcs, |
818 | 810 |
*map(sql_gen.CustomCode, ['value', 'SQLSTATE', 'SQLERRM']))+'''; |
819 | 811 |
|
820 |
''' |
|
821 |
query += '''\ |
|
822 | 812 |
RAISE WARNING '%', SQLERRM; |
823 | 813 |
RETURN NULL; |
824 | 814 |
END; |
... | ... | |
831 | 821 |
log_ignore_excs=(DuplicateFunctionException,)) |
832 | 822 |
break # successful |
833 | 823 |
except DuplicateFunctionException: |
834 |
if save_errors: function.name = next_version(function.name) |
|
835 |
# try again with next version of name |
|
836 |
else: break # plain cast function, so only need one version |
|
824 |
function.name = next_version(function.name) |
|
825 |
# try again with next version of name |
|
837 | 826 |
|
838 | 827 |
return sql_gen.FunctionCall(function, col) |
839 | 828 |
|
Also available in: Unified diff
sql.py: cast(): Removed conditional checks for save_errors, since it's now always true if the function got passed the `not save_errors` special case