Project

General

Profile

« Previous | Next » 

Revision 40

xml2db: Started refactoring xml2db() to support getting as well as inserting data

View differences:

xml_db.py
31 31
                elif child_name == name: return child
32 32
    return None
33 33

  
34
def xml2db(node, db):
35
    pkeys = {}
34
def get(db, node, create=False, store_ids=False, row_ct_ref=None, pkeys=None):
35
    # store_ids enables searching the tree for missing fields
36
    if pkeys == None: pkeys = {}
36 37
    def pkey(table):
37 38
        if table not in pkeys: pkeys[table] = db_util.pkey(db, table)
38 39
        return pkeys[table]
......
62 63
        # Insert node
63 64
        for try_num in range(2):
64 65
            try:
65
                id_ = db_util.insert_or_get(db, table, row, pkey_, row_ct_ref)
66
                xml_util.set_id(node, id_)
66
                id_ = db_util.get(db, table, row, pkey_, create, row_ct_ref)
67
                if store_ids: xml_util.set_id(node, id_)
67 68
                break
68 69
            except db_util.NullValueException, ex:
69 70
                if try_num > 0: raise # exception still raised after retry
......
77 78
        
78 79
        return id_
79 80
    
80
    row_ct_ref = [0]
81
    main(node)
82
    return row_ct_ref[0]
81
    return main(node)
82

  
83
def xml2db(db, node, row_ct_ref=None):
84
    return get(db, node, True, True, row_ct_ref)

Also available in: Unified diff