Project

General

Profile

« Previous | Next » 

Revision 3718

db_xml.py: put(): Raise an error if there are multiple fields with the same name, instead of silently overwriting the first with the second. This generally indicates the need to use `:[@merge=1]` on the fields in question.

View differences:

lib/db_xml.py
4 4
import re
5 5
from xml.dom import Node
6 6

  
7
import dicts
7 8
import exc
8 9
import Parser
9 10
import sql
......
67 68
        augment_error(e)
68 69
        on_error(e)
69 70
    
71
    def wrap_e(e): raise xml_func.SyntaxError(e)
72
    
70 73
    is_func = xml_func.is_func(node)
71 74
    out_table = name_of(node)
72 75
    
73 76
    # Divide children into fields and children with fkeys to parent
74
    row = {}
77
    row = dicts.OnceOnlyDict()
75 78
    children = []
76
    for child in xml_dom.NodeElemIter(node):
77
        child_name = name_of(child)
78
        if xml_dom.is_empty(child): row[child_name] = None
79
        elif xml_dom.is_text(child):
80
            row[child_name] = strings.to_unicode(xml_dom.value(child))
81
        else:
82
            child_value = xml_dom.value_node(child)
83
            if is_func or is_ptr(child_name) or xml_func.is_func(child_value):
84
                row[child_name] = child_value
85
            else: children.append(child)
79
    try:
80
        for child in xml_dom.NodeElemIter(node):
81
            child_name = name_of(child)
82
            if xml_dom.is_empty(child): row[child_name] = None
83
            elif xml_dom.is_text(child):
84
                row[child_name] = strings.to_unicode(xml_dom.value(child))
85
            else:
86
                child_value = xml_dom.value_node(child)
87
                if (is_func or is_ptr(child_name)
88
                    or xml_func.is_func(child_value)):
89
                    row[child_name] = child_value
90
                else: children.append(child)
91
    except dicts.KeyExistsError, e: wrap_e(e)
86 92
    
87 93
    # Special handling for structural XML functions
88 94
    if out_table == '_simplifyPath':
89 95
        # Parse args
90
        def wrap_e(e): raise xml_func.SyntaxError(e)
91 96
        try:
92 97
            next = row['next'] # modifies outer next var used by put_()
93 98
            require = row['require']
......
119 124
    
120 125
    # Divide fields into input columns and literal values
121 126
    parent_ids_loc = None # applies to this section
127
    row = row.inner # now allow keys to be overwritten
122 128
    for out_col, value in row.iteritems():
123 129
        # Handle forward pointers
124 130
        if xml_dom.is_node(value): row[out_col] = value = put_(value)

Also available in: Unified diff