Project

General

Profile

« Previous | Next » 

Revision 2104

sql.py: put(): pkey param (now pkey_) defaults to table's pkey

View differences:

lib/sql.py
578 578
    return with_parsed_errors(db, lambda: insert(db, table, row, returning,
579 579
        recover=True))
580 580

  
581
def put(db, table, row, pkey, row_ct_ref=None):
581
def put(db, table, row, pkey_=None, row_ct_ref=None):
582 582
    '''Recovers from errors.
583 583
    Only works under PostgreSQL (uses INSERT RETURNING).
584 584
    '''
585
    if pkey_ == None: pkey_ = pkey(db, table, recover=True)
586
    
585 587
    try:
586
        cur = try_insert(db, table, row, pkey)
588
        cur = try_insert(db, table, row, pkey_)
587 589
        if row_ct_ref != None and cur.rowcount >= 0:
588 590
            row_ct_ref[0] += cur.rowcount
589 591
        return value(cur)
590 592
    except DuplicateKeyException, e:
591
        return value(select(db, table, [pkey],
593
        return value(select(db, table, [pkey_],
592 594
            util.dict_subset_right_join(row, e.cols), recover=True))
593 595

  
594 596
def get(db, table, row, pkey, row_ct_ref=None, create=False):

Also available in: Unified diff