Faster bulk inserts in sqlite3?

scubabbl picture scubabbl · Dec 12, 2008 · Viewed 46.5k times · Source

I have a file of about 30000 lines of data that I want to load into a sqlite3 database. Is there a faster way than generating insert statements for each line of data?

The data is space-delimited and maps directly to an sqlite3 table. Is there any sort of bulk insert method for adding volume data to a database?

Has anyone devised some deviously wonderful way of doing this if it's not built in?

I should preface this by asking, is there a C++ way to do it from the API?

Answer

Javier picture Javier · Dec 12, 2008
  • wrap all INSERTs in a transaction, even if there's a single user, it's far faster.
  • use prepared statements.