simonw / csvs-to-sqlite

Convert CSV files into a SQLite database
Apache License 2.0
879 stars 69 forks source link

command fails if the filename has a square brackets #96

Open fgregg opened 1 year ago

fgregg commented 1 year ago
> echo "a,b" > [minimal_example].csv
> csvs-to-sqlite "[minimal_example].csv" out.db
/opt/homebrew/lib/python3.10/site-packages/csvs_to_sqlite/utils.py:38: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.

  return pd.read_csv(
Loaded 1 dataframes
/opt/homebrew/lib/python3.10/site-packages/csvs_to_sqlite/utils.py:287: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
  columns_and_types = df.dtypes.iteritems()
Traceback (most recent call last):
  File "/opt/homebrew/bin/csvs-to-sqlite", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/csvs_to_sqlite/cli.py", line 253, in cli
    to_sql_with_foreign_keys(
  File "/opt/homebrew/lib/python3.10/site-packages/csvs_to_sqlite/utils.py", line 330, in to_sql_with_foreign_keys
    create_sql, columns = get_create_table_sql(
  File "/opt/homebrew/lib/python3.10/site-packages/csvs_to_sqlite/utils.py", line 310, in get_create_table_sql
    row[1] for row in conn.execute("PRAGMA table_info([{}])".format(table_name))
sqlite3.OperationalError: unrecognized token: "]"