diff load_db.py @ 9:4678715f7147 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/query_tabular commit daa9af57fe07ee83a45ddc9f855716f9d14a8e12"
author iuc
date Sat, 12 Sep 2020 01:22:24 +0000
parents b722161a845a
children dfe38b7c34ed
line wrap: on
line diff
--- a/load_db.py	Thu Jan 23 07:36:57 2020 -0500
+++ b/load_db.py	Sat Sep 12 01:22:24 2020 +0000
@@ -176,7 +176,7 @@
 
 
 def get_column_def(file_path, table_name, skip=0, comment_char='#',
-                   column_names=None, max_lines=100, load_named_columns=False,
+                   column_names=None, max_lines=1000, load_named_columns=False,
                    firstlinenames=False, filters=None):
     col_pref = ['TEXT', 'REAL', 'INTEGER', None]
     col_types = []
@@ -272,8 +272,26 @@
                         if x else None for i, x in enumerate(fields)]
                 c.execute(insert_stmt, vals)
             except Exception as e:
-                print('Failed at line: %d err: %s' % (linenum, e),
+                print('Load %s Failed line: %d err: %s' % (file_path, linenum, e),
                       file=sys.stderr)
+                for i, val in enumerate(fields):
+                    try:
+                        col_func[i](val)
+                    except Exception:
+                        colType = getValueType(val)
+                        col_func[i] = float if colType == 'REAL' else int if colType == 'INTEGER' else str
+                        print('Changing %s from %s to %s' % (col_names[i], col_types[i], colType),
+                              file=sys.stderr)
+                        col_types[i] = colType
+                vals = [col_func[i](x)
+                        if x else None for i, x in enumerate(fields)]
+                print('%s  %s' % (insert_stmt, vals),
+                      file=sys.stderr)
+                try:
+                    c.execute(insert_stmt, vals)
+                except Exception as e:
+                    print('Insert %s line: %d Failed err: %s' % (file_path, linenum, e),
+                          file=sys.stderr)
         conn.commit()
         c.close()
         for i, index in enumerate(unique_indexes):