Revision 2769
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
772 | 772 |
|
773 | 773 |
def cast(db, type_, col, errors_table=None): |
774 | 774 |
'''Casts an (unrenamed) column or value. |
775 |
If a column, converts any errors to warnings. |
|
775 |
If errors_table set and col has srcs, saves errors in errors_table (using |
|
776 |
col's srcs attr as the source columns) and converts errors to warnings. |
|
776 | 777 |
@param col sql_gen.Col|sql_gen.Literal |
777 | 778 |
@param errors_table None|sql_gen.Table|str |
778 |
If set and col is a column with srcs, saves any errors in this table, |
|
779 |
using column's srcs attr as the source columns. |
|
780 | 779 |
''' |
781 |
if isinstance(col, sql_gen.Literal): # literal value, so just cast |
|
782 |
return sql_gen.CustomCode(col.to_str(db)+'::'+type_) |
|
780 |
save_errors = (errors_table != None and isinstance(col, sql_gen.Col) |
|
781 |
and col.srcs != ()) |
|
782 |
if not save_errors: # can't save errors |
|
783 |
return sql_gen.CustomCode(col.to_str(db)+'::'+type_) # just cast |
|
783 | 784 |
|
784 |
assert isinstance(col, sql_gen.Col) |
|
785 | 785 |
assert not isinstance(col, sql_gen.NamedCol) |
786 | 786 |
|
787 |
save_errors = errors_table != None and col.srcs != () |
|
788 | 787 |
if save_errors: |
789 | 788 |
errors_table = sql_gen.as_Table(errors_table) |
790 | 789 |
srcs = map(sql_gen.to_name_only_col, col.srcs) |
Also available in: Unified diff
sql.py: cast(): Only convert errors to warnings if errors will be saved in errors_table, so that import will always be aborted if user supplied invalid values in the mappings, even if these values are passed through a relational function