On Wed, Aug 21, 2013 at 8:04 AM, Dmitry Pashkevich <dpa...@gmail.com> wrote:

> I think I found a bug, tested with SQLite v3.7.15.2 and v3.7.9.
> Looks like sqlite3_finalize() always returns SQLITE_OK, even if most recent
> execution of prepared statement failed, which contradicts the
> documentation<http://www.sqlite.org/c3ref/finalize.html>
> :
>
> If the most recent evaluation of the statement encountered no errors or if
> > the statement is never been evaluated, then sqlite3_finalize() returns
> > SQLITE_OK. If the most recent evaluation of statement S failed, then
> > sqlite3_finalize(S) returns the appropriate error code<
> http://www.sqlite.org/c3ref/c_abort.html>
> >  or extended error code<
> http://www.sqlite.org/c3ref/c_abort_rollback.html>
> > .
> >
>
> I'm using sqlite3 via lsqlite3 <http://lua.sqlite.org/> Lua wrapper
> library
> (so maybe the bug is there but I can't confirm).
>

I'm unable to reproduce the problem using C.  Maybe it is in lsqlite3.

My test case:

#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_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));
  rc = sqlite3_finalize(pStmt);
  printf("finalize returns %d\n", rc);
  sqlite3_close(db);
  return 0;
}

Output of the test program:

first step returns 101
second step returns 19
error message = column x is not unique
finalize returns 19

And this sort of thing is extensively checked in the SQLite test suites (
http://www.sqlite.org/testing.html), so it is difficult to imagine how
something like this could go unnoticed.

Hence, pending additional contrary evidence, I'm going to assume this is a
problem with the lua bindings.


>
> Here's some sample code:
>
> > require "lsqlite3"
> > db = sqlite3.open_memory()
> > =db
> sqlite database (0x238e858)
> > =db:exec("create table t(x unique)")  *-- create a table with a
> constraint
> *
> 0
> > stmt = db:prepare("insert into t(x) values(?)")
> > =stmt
> sqlite virtual machine (0x23a23e8)
> > =stmt:bind_values(123)
> 0
> > =stmt:step()
> 101
> > =sqlite3.DONE
> 101
> > =stmt:reset()
> 0
> > =stmt:step()  *-- intentionally execute statement with same values to
> violate the constraint*
> 19
> *> =sqlite3.CONSTRAINT  -- step() returns the expected error code*
> *19*
> > =db:errmsg()
> column x is not unique
> *> =stmt:finalize() -- finalize returns OK!*
> *0*
> *> =db:errmsg() -- error message is still persisted, though*
> *column x is not unique*
>
>
> Somebody please confirm this...
>
> --
> Dmitry Pashkevich
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to