> I'm unable to reproduce the problem using C. Maybe it is in lsqlite3.
Yes, lsqlite3 still uses the old sqlite3_prepare() API to maintain
compatibility with some legacy systems. It is long past time that it should
have changed to use sqlite3_prepare_v2().
Running Richard's example with sqlite3_prepare_v2 changed to sqlite3_prepare
gives this output:
first step returns 101
second step returns 1
error message = SQL logic error or missing database
finalize returns 19
This doesn't match the output of lsqlite3 because the wrapper tries to be
helpful, and when the second step fails, it calls sqlite_reset to get the error
code. The equivalent C code is:
#include <stdio.h>
#include "sqlite3.h"
int main(int argc, char **argv){
sqlite3 *db;
sqlite3_stmt *pStmt;
int rc;
sqlite3_open(":memory:", &db);
sqlite3_exec(db, "create table t(x unique);", 0, 0, 0);
//sqlite3_prepare_v2(db, "insert into t(x) values(?)", -1, &pStmt, 0);
sqlite3_prepare(db, "insert into t(x) values(?)", -1, &pStmt, 0);
sqlite3_bind_int(pStmt, 1, 123);
rc = sqlite3_step(pStmt);
printf("first step returns %d\n", rc);
sqlite3_reset(pStmt);
rc = sqlite3_step(pStmt);
printf("second step returns %d\n", rc);
printf("error message = %s\n", sqlite3_errmsg(db));
if (rc == SQLITE_ERROR)
{
rc = sqlite3_reset(pStmt);
printf("second step's reset returns %d\n", rc);
printf("error message = %s\n", sqlite3_errmsg(db));
}
rc = sqlite3_finalize(pStmt);
printf("finalize returns %d\n", rc);
sqlite3_close(db);
return 0;
}
That prints
first step returns 101
second step returns 1
error message = SQL logic error or missing database
second step's reset returns 19
error message = column x is not unique
finalize returns 0
which matches the output from the Lua script.
The next version of lsqlite3 will use the recommended sqlite3_prepare_v2() API.
e
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users