Reputation: 79467
I'm trying to use SQLite's compiled statements to insert rows into a table:
rc = sqlite3_prepare(db, "INSERT INTO TABLE test VALUES (?,?,?,?)", -1, &stmt, 0);
if( rc!=SQLITE_OK )
printf("%s", sqlite3_errmsg(db));
sqlite3_prepare
returns 1, and sqlite3_errmsg
returns:
"near "TABLE": syntax error"
Upvotes: 0
Views: 669
Reputation: 263723
TABLE
is a reserved keyword. To avoid syntax error, it must be escaped by using brackets,
INSERT INTO test VALUES (?,?,?,?)
Upvotes: 2
Reputation: 6946
You shouldn't put "TABLE" in your query :
rc = sqlite3_prepare(db, "INSERT INTO test VALUES (?,?,?,?)", -1, &stmt, 0);
if( rc!=SQLITE_OK )
printf("%s", sqlite3_errmsg(db));
it is also a good practice to name the fields you're inserting in. So that if you add fields to your table, your queries won't be broken...
Upvotes: 3