querycsv-redux
querycsv-redux copied to clipboard
Error when file name contains dashes.
I got the following exception trace when doing:
./querycsv.py -i injectorLog-23894-eager.csv -o failures-23894-eager.log "SELECT * FROM injectorLog-23894-eager WHERE status == \\"FAILURE\\""
Traceback (most recent call last):
File "./querycsv.py", line 307, in <module>
qcsv(csvfiles, outfile, file_db, keep_db, sqlcmd)
File "./querycsv.py", line 211, in qcsv
csv_to_sqldb(conn, csvfile, tablename)
File "./querycsv.py", line 156, in csv_to_sqldb
sqldb.execute("create table %s (%s);" % (table_name, colstr))
sqlite3.OperationalError: near "-": syntax error
The issue went away when after I replaced the dashes with underscores. Perhaps a warning can be included, or at least some comment in the documentation?
Thanks for the cool tool!
Good idea. I have run into this problem before when file names do not represent valid SQL table names. Thanks!
Perhaps it is even better to handle this issue in a way transparent to the user. That is, perform a "normalization" step for the names of the file/table so from the client point of view you don't have to care about special cases.