Reputation: 133
I have a problem in the creation of a one table in sqlite3. Basically, the code (language c) that I use in the creation is the following:
do{
sprintf(buffer, "CREATE TABLE new_tab AS SELECT * FROM fileslog WHERE file_owner='%s' AND state='%s';", file_owner, state);
rc = sqlite3_prepare(db, buffer, -1, &result, NULL);
}while((rc == SQLITE_BUSY) || (rc == SQLITE_LOCKED));
My problem is that no any table is created when I execute this code. I have printed the rc variable to see the possible errors, but its value is 0 (SQLITE_OK). I don't know that it's happening neither where is the error.
Upvotes: 0
Views: 87
Reputation: 152827
sqlite_prepare_v2()
followed by sqlite3_step()
s and `sqlite3_finalizer() as suggested by Lasse V. Karlsen is one way to run the SQL.
sqlite3_exec()
is a simpler way for CREATE TABLE
and other non-SELECT
queries where you don't need to get result rows. As a side effect, you can't use variable binding (that can be useful for e.g. UPDATE
and DELETE
queries).
Upvotes: 1
Reputation: 391396
You are only preparing the SQL statement for execution.
To actually execute it, call sqlite3_step.
The steps involved according to the the SQL Statement Object documentation are:
(above list and links lifted from the official documentation.)
Upvotes: 3