429 # Iterate over the different columns and the different values |
430 # Iterate over the different columns and the different values |
430 # and try to convert them to a correct datatype. |
431 # and try to convert them to a correct datatype. |
431 # If an error is raised, do not continue. |
432 # If an error is raised, do not continue. |
432 formatted_row = [] |
433 formatted_row = [] |
433 for col in columns: |
434 for col in columns: |
434 if isinstance(row, dict): |
435 try: |
435 value = row.get(col) |
|
436 elif isinstance(row, (tuple, list)): |
|
437 value = row[col] |
436 value = row[col] |
438 else: |
437 except KeyError: |
439 raise ValueError("Input data of improper type: %s; " |
438 warnings.warn(u"Column %s is not accessible in row %s" |
440 "expected tuple, list or dict." |
439 % (col, row), RuntimeWarning) |
441 % type(row).__name__) |
440 # XXX 'value' set to None so that the import does not end in |
|
441 # error. |
|
442 # Instead, the extra keys are set to NULL from the |
|
443 # database point of view. |
|
444 value = None |
442 if value is None: |
445 if value is None: |
443 value = 'NULL' |
446 value = 'NULL' |
444 elif isinstance(value, (long, int, float)): |
447 elif isinstance(value, (long, int, float)): |
445 value = str(value) |
448 value = str(value) |
446 elif isinstance(value, (str, unicode)): |
449 elif isinstance(value, (str, unicode)): |