Igor Tandetnik wrote:
Mario Figueiredo wrote:
I'm a tad bit confused with sqlite3_finalize() usage when the query
fails. As it is, I'm assuming it releases resources and I use it in
this context:

--------------------------------
rc = sqlite3_prepare_v2(/* ... */);
if (rc != SQLITE_OK)
{
  sqlite3_finalize(stmt);
  /* ... */
}

This doesn't make any sense. If prepare fails, you do not have a valid statement handle to call finalize on.

Igor Tandetnik

Are you sure about that? The documentation for sqlite3_prepare_v2 says:

*ppStmt is left pointing to a compiled SQL statement structure that can be executed using sqlite3_step(). Or if there is an error, *ppStmt may be set to NULL. If the input text contained no SQL (if the input is and empty string or a comment) then *ppStmt is set to NULL. The calling procedure is responsible for deleting the compiled SQL statement using sqlite3_finalize() after it has finished with it.

I also thought this means the statement has to be deleted with sqlite3_finalize, even when sqlite3_prepare_v2 failed (except for the case where NULL is returned). Notice the "may be set to NULL" in the documentation. Doesn't a non-NULL value indicate some memory was allocated and thus need to be freed?



-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to