On Thu, May 08, 2008 at 11:39:17AM -0700, [EMAIL PROTECTED] scratched on the
wall:
> If I run the following code I get some unexpected results:
>
> sqlite3* db1_p = 0;
> const int open1Res = sqlite3_open16(L"test.db", &db1_p);
> sqlite3* db2_p = 0;
> const int open2Res = sqlite3_open16(L"test.db", &db2_p);
>
> sqlite3_stmt* stmt1_p;
> const int prep1Res = sqlite3_prepare16_v2(db1_p, L"SELECT
> * FROM test", -1, &stmt1_p, 0);
> sqlite3_stmt* stmt2_p;
> const int prep2Res =
> sqlite3_prepare16_v2(db2_p, L"INSERT INTO test VALUES
> (1, 1.1, 'q')", -2, &stmt2_p, 0);
>
> const int step1Res = sqlite3_step(stmt1_p);
> const int step2Res = sqlite3_step(stmt2_p);
>
> const int finalize2Res1 = sqlite3_finalize(stmt2_p);
> const int finalize2Res2 = sqlite3_finalize(stmt2_p);
>
> const int finalize1Res = sqlite3_finalize(stmt1_p);
> const int finalize2Res3 = sqlite3_finalize(stmt2_p);
>
> Everything works as expected up to the first call to sqlite3_finalize.
> I Get SQLITE_OK form the opens and prepares, SQLITE_ROW from the first
> step statement and SQLITE_BUSY form the second step statement. Then on
> the first call to finalize I get SQLITE_BUSY. I'm not sure if this
> means that the statement could not be finalized due to a database lock
> or that sqlite3_finalize is returning the result of executing the
> statement. The documentation confuses me a bit on this point.
The documentation seems pretty clear to me:
"If the most recent call to sqlite3_step(S) for the
prepared statement S returned an error, then
sqlite3_finalize(S) returns that same error."
http://www.sqlite.org/c3ref/finalize.html
So yes, sqlite3_finalize() is returning the result of executing the
statement.
> I'm leaning towards the latter since the subsequent calls to
> sqlite3_finalize for stmt2_p result in SQLITE_MISUSE. So I'm wondering
> if database locks can prevent sqlite3_finalize from running
> successfully, it seems strange if they do.
sqlite3_finalize() always does its job. It can return different
error codes depending on what it had to do to finalize the statement,
but it will always finalize the statement.
You're getting a MISUSE on the subsequent calls to _finalize() because
the statement is not valid after the first call to _finalize().
-j
--
Jay A. Kreibich < J A Y @ K R E I B I.C H >
"'People who live in bamboo houses should not throw pandas.' Jesus said that."
- "The Ninja", www.AskANinja.com, "Special Delivery 10: Pop!Tech 2006"
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users