Related to constraint violations, an error message returned by 
sqlite3_errmsg() changes to the better after calling sqlite3_reset() or 
sqlite3_finalize().

Example code is below, here is the output:

sqlite3_step:     19 constraint failed
sqlite3_reset:    19 t.c may not be NULL
sqlite3_finalize:  0 t.c may not be NULL

As can be seen, sqlite3_reset() "enhances" the error message returned by 
sqlite3_errmsg() by filling in the column name and reason why the 
constraint failed.

I would like to ask if this could be changed so that sqlite3_step() by 
itself generates the more meaningful error message, even without calling 
sqlite3_reset() or sqlite3_finalize()?

IIRC, having sqlite3_step() generate the "final" error codes and 
messages was one of the reasons that brought about sqlite3_prepare_v2(). 
I observe that the error message generated after sqlite3_prepare_v2() 
("constraint failed") is far better than that of sqlite3_prepare() ("SQL 
logic error or missing database"), but it is not as good as it gets 
after resetting the statement.

Ralf

---- Example code:

int main(int argc, char* argv[])
{
   sqlite3* db;
   sqlite3_stmt* stmt;
   int e;

   sqlite3_open("test.db3", &db);

   sqlite3_exec(db, "create table if not exists t (c text not null)",
                NULL, NULL, NULL);

   sqlite3_prepare_v2 (db, "insert into t values (null)", -1,
                       &stmt, NULL);

   e = sqlite3_step(stmt);
   printf("sqlite3_step:     %d %s\n", e, sqlite3_errmsg(db));

   e = sqlite3_reset(stmt);
   printf("sqlite3_reset:    %d %s\n", e, sqlite3_errmsg(db));

   e = sqlite3_finalize(stmt);
   printf("sqlite3_finalize:  %d %s\n", e, sqlite3_errmsg(db));

   sqlite3_close (db);

   printf ("\nDone");
   scanf ("*%s");

   return 0;
}
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to