PDA

View Full Version : Segmentation fault when importing data from csv to sqllite database



SIFE
4th January 2012, 21:36
I am trying to insert big csv file(about ~35Mb) into sqlite database. So, when ever I press processButton I got segmentation fault, I can't figure out the cause of error.
CSV format:
xxxx, xxxxx, xxxxx, xxxxx with out double quote.
7235

ChrisW67
4th January 2012, 22:09
I cannot reproduce the error with simple valid input. Check your input for lines with fewer than four columns especially the last/blank lines: your code assumes at least four columns in the input. Run the program in a debugger and determine where the error is originating.

You should not build SQL statements as strings; they are prone to error, open to exploitation, and hard to maintain. Prepare a query and using bindValue() (See Approaches to Binding Values.

SIFE
4th January 2012, 22:29
I found the csv file I tried to import have some blank lines and line more then four columns. There is also another method to import csv data to sqlite database via sqlite shell:
sqlite3 test.db
sqlite>.mode csv
sqlite>.import file.csv TableToInsertTo
TableToInsertTo should have the some number of columns, like file.csv have. And that is how I figure my csv not correctly structured.