Hello.

I am not sure if it should go here or to devel list, so please bear with me.


I was about to use sqlite3_exe with not null errmsg parameter and became a bit 
confused.

Documentation says:
---------------------------

If an error occurs while evaluating the SQL statements passed into
sqlite3_exec(), then execution of the current statement stops and
subsequent statements are skipped.  If the 5th parameter to sqlite3_exec()
is not NULL then any error message is written into memory obtained
from sqlite3_malloc() and passed back through the 5th parameter.
To avoid memory leaks, the application should invoke sqlite3_free() on error 
message strings returned through the 5th parameter of
of sqlite3_exec() after the error message string is no longer needed.
If the 5th parameter to sqlite3_exec() is not NULL and no errors
occur, then sqlite3_exec() sets the pointer in its 5th parameter to
NULL before returning.
-------------------------


I was planing to use this function like following:

-------------------------------

int res;
char *errmsg;

res = sqlite3_exec( db,  zSql, NULL, NULL, &errmsg );

if ( res !=  SQLITE_OK) {
fprintf( stderr, "%s", errmsg)
sqlite3_free( errmsg )

}

-----------------------------------

But then I looked at sqlite3_exec code and saw following
-----------------------------------
*/
SQLITE_API int sqlite3_exec(
sqlite3 *db,                /* The database on which the SQL executes */
const char *zSql,          /* The SQL to be executed */
sqlite3_callback xCallback, /* Invoke this callback routine */
void *pArg,                /* First argument to xCallback() */
char **pzErrMsg            /* Write error messages here */
){
int rc = SQLITE_OK;        /* Return code */
const char *zLeftover;      /* Tail of unprocessed SQL */
sqlite3_stmt *pStmt = 0;    /* The current SQL statement */
char **azCols = 0;          /* Names of result columns */
int callbackIsInit;        /* True if callback data is initialized */

if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
....
-----------------------------------------------------------------

i.e if sqlite3SafetyCheckOk failed, then returned value is not SQLITE_OK on one 
side
and pzErrMsg will be left untouched.

Of course I can check myself for SQLITE_MISUSE_BKPT and in this cases give 
error message myself,
but it is  ugly.


Anyway looks to me as either bug in the code or in the documentation.

Or I am missing something?

Valery.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to