Revision 5050
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
869 | 869 |
|
870 | 870 |
def insert(db, table, row, *args, **kw_args): |
871 | 871 |
'''For params, see insert_select()''' |
872 |
ignore = kw_args.pop('ignore', False) |
|
873 |
|
|
872 | 874 |
if lists.is_seq(row): cols = None |
873 | 875 |
else: |
874 | 876 |
cols = row.keys() |
... | ... | |
878 | 880 |
if row == []: query = None |
879 | 881 |
else: query = sql_gen.Values(row).to_str(db) |
880 | 882 |
|
881 |
return insert_select(db, table, cols, query, *args, **kw_args) |
|
883 |
try: return insert_select(db, table, cols, query, *args, **kw_args) |
|
884 |
except DuplicateKeyException: |
|
885 |
if not ignore: raise |
|
882 | 886 |
|
883 | 887 |
def mk_update(db, table, changes=None, cond=None, in_place=False, |
884 | 888 |
cacheable_=True): |
Also available in: Unified diff
sql.py: insert(): Added ignore optimization that just suppresses any DuplicateKeyException on the client side, to avoid needing to create a wrapper function just to insert-ignore one row