thombashi / sqlitebiter

A CLI tool to convert CSV / Excel / HTML / JSON / Jupyter Notebook / LDJSON / LTSV / Markdown / SQLite / SSV / TSV / Google-Sheets to a SQLite database file.
https://sqlitebiter.rtfd.io/
MIT License
850 stars 50 forks source link

Conversion fails for Excel sheets that have a single quote in a table header #6

Closed VeryBueno closed 8 years ago

VeryBueno commented 8 years ago

I have a spreadsheet with a header that has a single quote in it:

Don't Do This
1 2 3
3 2 1

It fails like this:

> sqlitebiter file Woo.xlsx                                                                                                                      
convert 'Woo.xlsx' to 'Sheet1' table                                                                                                             
Traceback (most recent call last):                                                                                                               
  File "c:\python27\lib\runpy.py", line 162, in _run_module_as_main                                                                              
    "__main__", fname, loader, pkg_name)                                                                                                         
  File "c:\python27\lib\runpy.py", line 72, in _run_code                                                                                         
    exec code in run_globals                                                                                                                     
  File "C:\Python27\Scripts\sqlitebiter.exe\__main__.py", line 9, in <module>                                                                    
  File "c:\python27\lib\site-packages\click\core.py", line 716, in __call__                                                                      
    return self.main(*args, **kwargs)                                                                                                            
  File "c:\python27\lib\site-packages\click\core.py", line 696, in main                                                                          
    rv = self.invoke(ctx)                                                                                                                        
  File "c:\python27\lib\site-packages\click\core.py", line 1060, in invoke                                                                       
    return _process_result(sub_ctx.command.invoke(sub_ctx))                                                                                      
  File "c:\python27\lib\site-packages\click\core.py", line 889, in invoke                                                                        
    return ctx.invoke(self.callback, **ctx.params)                                                                                               
  File "c:\python27\lib\site-packages\click\core.py", line 534, in invoke                                                                        
    return callback(*args, **kwargs)                                                                                                             
  File "c:\python27\lib\site-packages\sqlitebiter\sqlitebiter.py", line 99, in file                                                              
    con.create_table_from_tabledata(tabledata)                                                                                                   
  File "c:\python27\lib\site-packages\simplesqlite\core.py", line 979, in create_table_from_tabledata                                            
    data_matrix=tabledata.record_list)                                                                                                           
  File "c:\python27\lib\site-packages\simplesqlite\core.py", line 960, in create_table_with_data                                                 
    self.create_table(table_name, attr_description_list)                                                                                         
  File "c:\python27\lib\site-packages\simplesqlite\core.py", line 874, in create_table                                                           
    if self.execute_query(query, logging.getLogger().findCaller()) is None:                                                                      
  File "c:\python27\lib\site-packages\simplesqlite\core.py", line 237, in execute_query                                                          
    raise sqlite3.OperationalError(os.linesep.join(message_list))                                                                                
sqlite3.OperationalError: failed to execute query at c:\python27\lib\site-packages\simplesqlite\core.py(979) create_table_from_tabledata         
  - query: CREATE TABLE IF NOT EXISTS 'Sheet1' ('Don't' REAL, 'Do ' REAL, 'This' REAL)                                                           
  - msg:   unrecognized token: "' REAL)"                                                                                                         
  - db:    C:\Users\me\Projects\import\out.sqlite        
thombashi commented 8 years ago

@VeryBueno Thank you for your report. I've fixed the problem with sqlitebiter 0.1.2. Would you update the package (pip install sqlitebiter --upgrade) and re-execute the command?

VeryBueno commented 8 years ago

@thombashi thanks for the update! The error has been fixed.

thombashi commented 8 years ago

I'm glad to hear that. Then, I will close the issue.