SportyMe
SportyMe

Reputation: 31

Syntax error in SQLite query

I am trying to insert a large number of records into a SQLite database. I get the above error if I try to use the sqlite3_exec C-API.

The code looks like this:

ret = sqlite_exec(db_p,".import file.txt table", NULL, NULL, NULL);

I know that the .import is command line, but can there be any way that you can do a extremely large insert of records that takes minimal time. I have read through previous bulk insert code and attempted to make changes but these are not providing the desired results.

Is there not a way to directly insert the string into the tables without having intermediate API's being called?

Upvotes: 1

Views: 585

Answers (2)

Andreas Gohr
Andreas Gohr

Reputation: 4945

.import is most probably not available via the API. However there's one crucial thing to speed up inserts: wrap them in a transaction.

BEGIN;
lots of insert statements here;
COMMIT;

Without this, sqlite will need to write to the file after each insert to keep the ACID principle. The transaction let's it write to file later in bulk.

Upvotes: 3

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

The answer to the syntax error could well be, that your strings are not enclosed in quotes in your SQL statement.

Upvotes: 0

Related Questions