SQLite CSV import

I am using SQLite build-in import command for importing records from text files.

The code being follows:

$ sqlite3 dbname.db
SQLite version 3.1.3
Enter ".help" for instructions
sqlite> .separator "\t"

Once I have set the field separator, I do import:

sqlite> .import filename.txt tablename

This solves my purpose but have any one tried on any user-defined function to import data to sqlite.

 #

I have come across a CSV reading module in Tcllib, u can give it a try, it will take care of the quotes and other nastiness.

 
 #

You can use tksqlite application available for download at:

http://reddog.s35.xrea.com/wiki/TkSQLite.html

It is the best free tool for working with sqlite.

 
 #

For sqlite I use the mode command, the codes is like this:

sqlite> .mode csv
sqlite> .import ./filename.csv tablename

The mode command automatically choose the default separator.

 
 #

I hope you are going in right way, but instead you can fire a
system call to execute the same command:

$ sqlite3 -separator , dbname.db ".import filename.csv tablename"

this one line is enough then any user-defined function.

 

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Cumulus Tag Cloud

Kiran Says

I love work environment which is:

Informal yet professional
Demanding yet rewarding
Challenging yet inspiring
Mediocrity is not an option
Having fun is serious business
Making mistakes is human
Forgiveness is Company Policy

Travelling Sucks