Esempio n. 1
0
                        valias = v['valias']
            else:
                valias = fspec['valias']
            if valias:
                valias_dict = dict((str(i[0]).lower(), i[1]) if isinstance(i[0], str)
                    else (i[0], i[1]) for i in valias.items())
                # print valias_dict
                # print value
                if value in valias_dict:
                    value = valias_dict[value]
                if value == 'NULL':
                    value = None
                # print value
                # raw_input()

        success, result = myspot.sql_2mysql(value, sqltype, sqllen, format='iso')
        if not success:
            print "WARNING: for %s failed to parse %s as %s" % (
                fname, value, sqltype)
        # print result
        clean_values.append(result)

    # CHANGED: 2012-12-21 - row index added if tab_serial does not already exist
    #  ... helps b/c index_table expects to find tab_serial
    if tab_serial_missing:
        clean_values.append(index + 1)
    stmt_out = myspot.sql_prepare_insert(
        table_out, target_fields_found, clean_values)
    # print stmt_out
    try:
        cursor_out.execute(stmt_out)
Esempio n. 2
0
                corr_item, pkeys)
            field_name = corr_aliases[corr_item['field']]
            corr_pkey = derive_pkey_for_correction_fr(corr_item, pkeys)
            corr_pkey_hash = hash(corr_pkey)
            print "NOTE: sorted primary key for correction item is %s" % str(
                corr_pkey)
            fspec = fdict_lookup[field_name]
            sqltype = fspec['sqltype']
            if 'sqllen' in fspec:
                sqllen = fspec['sqllen']
            else:
                sqllen = 255
            print "NOTE: Try to parse proposed replacement value %s for field %s" % (
                corr_item['new_response_value'], field_name)
            success, corr_clean = sql_2mysql(corr_item['new_response_value'],
                                             sqltype,
                                             sqllen,
                                             format='iso')
            print "NOTE: Parsed to %s" % corr_clean

        if corr_pkey_hash not in row_hashes:
            print "WARNING: Could not apply correction for %s" % str(corr_pkey)
            continue

        row_index = row_hashes.index(corr_pkey_hash)
        field_index = field_names.index(field_name)
        print "NOTE: Row to update is %s" % rows[row_index]
        print "NOTE: Field to update is %s" % rows[row_index][field_index]
        rows[row_index][field_index] = corr_clean
        print "NOTE: Field UPDATED is %s" % rows[row_index][field_index]

# Rebuild hashes now you have updated the values
Esempio n. 3
0
            continue
        else:
            print "NOTE: %s refers to primary key (%s) - will update" % (corr_item, pkeys)
            field_name = corr_aliases[corr_item['field']]
            corr_pkey = derive_pkey_for_correction_fr(corr_item, pkeys)
            corr_pkey_hash = hash(corr_pkey)
            print "NOTE: sorted primary key for correction item is %s" % str(corr_pkey)
            fspec = fdict_lookup[field_name]
            sqltype = fspec['sqltype']
            if 'sqllen' in fspec:
                sqllen = fspec['sqllen']
            else:
                sqllen = 255
            print "NOTE: Try to parse proposed replacement value %s for field %s" % (
                corr_item['new_response_value'], field_name)
            success, corr_clean = sql_2mysql(corr_item['new_response_value'],
                sqltype, sqllen, format='iso')
            print "NOTE: Parsed to %s" % corr_clean

        if corr_pkey_hash not in row_hashes:
            print "WARNING: Could not apply correction for %s" % str(corr_pkey)
            continue

        row_index = row_hashes.index(corr_pkey_hash)
        field_index = field_names.index(field_name)
        print "NOTE: Row to update is %s" % rows[row_index]
        print "NOTE: Field to update is %s" %  rows[row_index][field_index]
        rows[row_index][field_index] = corr_clean
        print "NOTE: Field UPDATED is %s" %  rows[row_index][field_index]


# Rebuild hashes now you have updated the values
Esempio n. 4
0
            if valias:
                valias_dict = dict(
                    (str(i[0]).lower(),
                     i[1]) if isinstance(i[0], str) else (i[0], i[1])
                    for i in valias.items())
                # print valias_dict
                # print value
                if value in valias_dict:
                    value = valias_dict[value]
                if value == 'NULL':
                    value = None
                # print value
                # raw_input()

        success, result = myspot.sql_2mysql(value,
                                            sqltype,
                                            sqllen,
                                            format='iso')
        if not success:
            print "WARNING: for %s failed to parse %s as %s" % (fname, value,
                                                                sqltype)
        # print result
        clean_values.append(result)

    # CHANGED: 2012-12-21 - row index added if tab_serial does not already exist
    #  ... helps b/c index_table expects to find tab_serial
    if tab_serial_missing:
        clean_values.append(index + 1)
    stmt_out = myspot.sql_prepare_insert(table_out, target_fields_found,
                                         clean_values)
    # print stmt_out
    try:
Esempio n. 5
0
                        vallab_dict_reverse = {
                            str(i[1]).lower(): i[0]
                            for i in fspec['vallab'].items()
                        }
                        # print dvr_value, vallab_dict_reverse
                        if str(dvr_value).lower() in vallab_dict_reverse:
                            dvr_value = vallab_dict_reverse[str(
                                dvr_value).lower()]
                            if sqltype in ['int', 'tinyint', 'smallint']:
                                dvr_value = int(dvr_value)
                            elif sqltype == 'char':
                                dvr_value = str(dvr_value)
                        # print dvr_value, type(dvr_value)

                    success, cleaned_response = sql_2mysql(dvr_value,
                                                           sqltype,
                                                           sqllen,
                                                           format='iso')
                    thisfield['raw'] = cleaned_response

                elif corr_dict['new_response_code'] == 2:
                    # returned response is 2 hence delete current val
                    thisfield['raw'] = None
                    success = True
                else:
                    pass

                if corr_dict['new_response_code'] in [2, 3]:
                    print "OK: In response to ... %s" % corr_dict[
                        'validation_message']
                    if not success and cleaned_response is None:
                        print "WARNING: ?failed to update %s from %s to %s for %s" % (
Esempio n. 6
0
                    # CHANGED: 2012-09-14 -
                    # now assume the response will be the label not the value then back convert
                    if 'vallab' in fspec:
                        vallab_dict_reverse = {str(i[1]).lower(): i[0]
                            for i in fspec['vallab'].items()}
                        # print dvr_value, vallab_dict_reverse
                        if str(dvr_value).lower() in vallab_dict_reverse:
                            dvr_value = vallab_dict_reverse[str(dvr_value).lower()]
                            if sqltype in ['int', 'tinyint', 'smallint']:
                                dvr_value = int(dvr_value)
                            elif sqltype == 'char':
                                dvr_value = str(dvr_value)
                        # print dvr_value, type(dvr_value)

                    success, cleaned_response = sql_2mysql(
                        dvr_value, sqltype, sqllen, format='iso')
                    thisfield['raw'] = cleaned_response

                elif corr_dict['new_response_code'] == 2:
                    # returned response is 2 hence delete current val
                    thisfield['raw'] = None
                    success = True
                else:
                    pass

                if corr_dict['new_response_code'] in [2,3]:
                    print "OK: In response to ... %s" % corr_dict['validation_message']
                    if not success and cleaned_response is None:
                        print "WARNING: ?failed to update %s from %s to %s for %s" % (
                            field_name, thisfield['raw_pre_dvr'],
                            dvr_value, corr_pkey)