lundi 25 mai 2009

SQLite and CSV files

SQLite is really great !
I use it now in almost every application I do :-)

My way to work is to combine the shell script with it,
the result is amazingly fast and clean :-)

but I "recently" solved what I imagined as the weakness of the Sqlite command line:
it is the CSV import !

in real work life, we need to treat CSV files like:
my field 1,"my opinion, my view on it", my field 3

or simply a field on multiple lines like
"my
multi-lines
field",...

the .import does not manage this kind of CSV file....

I wrote a state machine (a big switch/case) to parse the CSV file.
I progress in my state machine by getting the next character until the end of the file.

The funny thing is that I always try to rely on ".import" when I know I am using simple files,
but I had to change it for one file, the day after I wrote my own parser :-)
funny isn't it?

long life to SQLite !













Aucun commentaire:

Enregistrer un commentaire