Re: [sqlite] statement prepares OK but step returns SQLITE_NOTADB
Thanks for the clarification. Adam On Sat, Oct 27, 2012 at 12:13 PM, Simon Slavinwrote: > > On 27 Oct 2012, at 6:36am, Dan Kennedy wrote: > >> On 10/27/2012 07:06 AM, Simon Slavin wrote: >>> >>> On 26 Oct 2012, at 11:05pm, Clemens Ladisch >>> wrote: >>> Yes; sqlite3_finalize _always_ frees the statement. >>> >>> And if the statement is already finalized (due to an earlier error, >>> perhaps) then it is a harmless noop. So you can do it near the end >>> of your routine harmlessly. >> >> That's a bit deceptive. Passing the same pointer to sqlite3_finalize() >> twice is undefined behavior. You might get an SQLITE_MISUSE error, but >> you also might get a segfault. > > Oh, right. It releases the memory the statement was using. Sorry. > > Simon. > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users -- VerifEye Technologies Inc. 905-948-0015x245 151 Whitehall Dr, Unit 2 Markham ON, L3R 9T1 Canada ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] statement prepares OK but step returns SQLITE_NOTADB
On 27 Oct 2012, at 6:36am, Dan Kennedywrote: > On 10/27/2012 07:06 AM, Simon Slavin wrote: >> >> On 26 Oct 2012, at 11:05pm, Clemens Ladisch >> wrote: >> >>> Yes; sqlite3_finalize _always_ frees the statement. >> >> And if the statement is already finalized (due to an earlier error, >> perhaps) then it is a harmless noop. So you can do it near the end >> of your routine harmlessly. > > That's a bit deceptive. Passing the same pointer to sqlite3_finalize() > twice is undefined behavior. You might get an SQLITE_MISUSE error, but > you also might get a segfault. Oh, right. It releases the memory the statement was using. Sorry. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] statement prepares OK but step returns SQLITE_NOTADB
On 10/27/2012 07:06 AM, Simon Slavin wrote: On 26 Oct 2012, at 11:05pm, Clemens Ladischwrote: Yes; sqlite3_finalize _always_ frees the statement. And if the statement is already finalized (due to an earlier error, perhaps) then it is a harmless noop. So you can do it near the end of your routine harmlessly. That's a bit deceptive. Passing the same pointer to sqlite3_finalize() twice is undefined behavior. You might get an SQLITE_MISUSE error, but you also might get a segfault. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] statement prepares OK but step returns SQLITE_NOTADB
On 26 Oct 2012, at 11:05pm, Clemens Ladischwrote: > Yes; sqlite3_finalize _always_ frees the statement. And if the statement is already finalized (due to an earlier error, perhaps) then it is a harmless noop. So you can do it near the end of your routine harmlessly. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] statement prepares OK but step returns SQLITE_NOTADB
Adam DeVita wrote: > As an error check, I've got a program opening an encrypted file. > > sqlite3_prepare_v2 returns SQLITE_OK > > and ppStmt is not null. > > When I run sqlite3_step(ppStmt) it returns SQLITE_NOTADB. sqlite3_prepare_v2 does not yet start a transaction (to allow keeping cached prepared statements around), and only inside a transaction can the database file be locked and accessed. > Recognizing an error at this point I'd like to clean up properly. > sqlite3_finalize(ppStmt) returns SQLITE_NOTADB. > At this point, has it actually cleared the prepared statement Yes; sqlite3_finalize _always_ frees the statement. > http://www.sqlite.org/capi3ref.html#sqlite3_finalize is a bit brief on > the success of finalizing the statement given that it returned an > error. | 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 | or extended error code. Or in the words of the source code: | The following routine destroys a virtual machine that is created by | the sqlite3_compile() routine. The integer returned is an SQLITE_ | success/failure code that describes the result of executing the virtual | machine. In other words, _any_ error returned by this function applies not to what sqlite3_finalize did itself, but to the result of other functions. Regards, Clemens ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] statement prepares OK but step returns SQLITE_NOTADB
Good day, As an error check, I've got a program opening an encrypted file. sqlite3_prepare_v2 returns SQLITE_OK and ppStmt is not null. When I run sqlite3_step(ppStmt) it returns SQLITE_NOTADB. Recognizing an error at this point I'd like to clean up properly. sqlite3_finalize(ppStmt) returns SQLITE_NOTADB. At this point, has it actually cleared the prepared statement, so I can set ppStmt = NULL and carry on to close the db and tell the user they shouldn't have opened that file? http://www.sqlite.org/capi3ref.html#sqlite3_finalize is a bit brief on the success of finalizing the statement given that it returned an error. I'm using the basic amalgamation c file SQLite version 3.7.4. regards, Adam DeVita ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users