2

I know that there is a command line ".import" which can do this. But if I want to do the same thing in C programs, what should I do? And we are using the SQLite main memory database. It means we have to do all things in one program. Otherwise, the database is cancelled after the connection is closed. Thank you.

2

1 Answer 1

1

The SQLite 3 C - API can be used to import csv into an Sqlite3 database.

  • Your C code needs to open the CSV file, read in each line of the CSV file, making sure to store the column values (in the current row) in an appropriate container (i.e. column boundaries determined by comma separator).
  • These column values can be bound to parameters in a prepared statement and then committed to the database. Here is a useful link: http://blog.quibb.org/2010/08/fast-bulk-inserts-into-sqlite/
Sign up to request clarification or add additional context in comments.

2 Comments

Tokenizing CVS input is non-trivial. Simple cases are simple, but I don't think there's even a universally recognized standard for, for example, how to represent fields that contain commas. See en.wikipedia.org/wiki/Comma-separated_values

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.