comparison 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
comparison
equal deleted inserted replaced
8:5a4ae7678bc5 9:4678715f7147
174 return 'TEXT' 174 return 'TEXT'
175 return None 175 return None
176 176
177 177
178 def get_column_def(file_path, table_name, skip=0, comment_char='#', 178 def get_column_def(file_path, table_name, skip=0, comment_char='#',
179 column_names=None, max_lines=100, load_named_columns=False, 179 column_names=None, max_lines=1000, load_named_columns=False,
180 firstlinenames=False, filters=None): 180 firstlinenames=False, filters=None):
181 col_pref = ['TEXT', 'REAL', 'INTEGER', None] 181 col_pref = ['TEXT', 'REAL', 'INTEGER', None]
182 col_types = [] 182 col_types = []
183 col_idx = None 183 col_idx = None
184 col_names = [] 184 col_names = []
270 try: 270 try:
271 vals = [col_func[i](x) 271 vals = [col_func[i](x)
272 if x else None for i, x in enumerate(fields)] 272 if x else None for i, x in enumerate(fields)]
273 c.execute(insert_stmt, vals) 273 c.execute(insert_stmt, vals)
274 except Exception as e: 274 except Exception as e:
275 print('Failed at line: %d err: %s' % (linenum, e), 275 print('Load %s Failed line: %d err: %s' % (file_path, linenum, e),
276 file=sys.stderr) 276 file=sys.stderr)
277 for i, val in enumerate(fields):
278 try:
279 col_func[i](val)
280 except Exception:
281 colType = getValueType(val)
282 col_func[i] = float if colType == 'REAL' else int if colType == 'INTEGER' else str
283 print('Changing %s from %s to %s' % (col_names[i], col_types[i], colType),
284 file=sys.stderr)
285 col_types[i] = colType
286 vals = [col_func[i](x)
287 if x else None for i, x in enumerate(fields)]
288 print('%s %s' % (insert_stmt, vals),
289 file=sys.stderr)
290 try:
291 c.execute(insert_stmt, vals)
292 except Exception as e:
293 print('Insert %s line: %d Failed err: %s' % (file_path, linenum, e),
294 file=sys.stderr)
277 conn.commit() 295 conn.commit()
278 c.close() 296 c.close()
279 for i, index in enumerate(unique_indexes): 297 for i, index in enumerate(unique_indexes):
280 index_name = 'idx_uniq_%s_%d' % (table_name, i) 298 index_name = 'idx_uniq_%s_%d' % (table_name, i)
281 index_columns = index.split(',') 299 index_columns = index.split(',')