Hi guys,
I ran into a strange problem. I have 2 prepared sqlite3_stmt, each inserting
to different tables in a sqlite database:

sqlite3_stmt* insertA;
std::string sql = "insert into tablea(col1) values(?)";
int rc = sqlite3_prepare(db_, sql.c_str(), sql.size(), &insertA, NULL);

sqlite3_stmt* insertB;
std::string sql = "insert into tableb(col1) values(?)";
int rc = sqlite3_prepare(db_, sql.c_str(), sql.size(), &insertB, NULL);

I intended to keep insertA and insertB through the lifetime of my
application/database. I use sqlite3_reset(insertA) before and after each
$sqlite3_step() call:

sqlite3_reset(insertA);
sqlite3_bind_int(insertA, ...);
rc1 = sqlite3_step(insertA);
sqlite3_reset(insertA);

sqlite3_reset(insertB);
sqlite3_bind_int(insertB, ...);
rc2 = sqlite3_step(insertB);
sqlite3_reset(insertB);

The strange thing is rc2 will returns SQLITE_ERROR if sqlite3_step(insertA)
is executed. The error message from sqlite3_errmsg() is even stranger. It
returns "not an error"!

If I don't execute sqlite3_step(insertA) then rc2 will return SQLITE_OK.

Does it seem like I cannot keep 2 prepared statement which is going to do
INSERT alive at the same time?! If the insertA prepare statement is just a
SELECT, rc2 returns SQLITE_OK.

If I use sqlite3_exec() to insert into tableb, then it will work, too.
strange!

I have tried this on sqlite 3.2.7 and 3.3.8 and the same thing happens.

Can anyone shed some light?
Thanks,
Eric

Reply via email to