Hello John,
why do you malloc() your DB- and Statement handle?
I declare a
sqlite3* pDB;
sqlite3_stmt* pStmnt;
then open the database with
int nRet = sqlite3_open("MyDatabaseName", &pDB);
and prepare a statement using
nRet = sqlite3_prepare_v2(pDB, "insert .....", -1, &pStmnt, &szTail);
no need to malloc (or free) anything, and passing pDB or pStmnt to
functions is easy.
Martin
Am 11.10.2011 11:27, schrieb enjoythe...@hushmail.com:
hello list,
I have a question regarding prepared statements. I'm fairly new to
sqlite3 and it's already pretty late, so if I'm overlooking
something obvious please forgive me :) I'm on Windows 7 x64 and
using sqlite-3070800 (amalgamation).
I'm trying to prepare an insert statement, that I will reuse many
times using bound parameters. In a short test application, if I
prepare the statement within the main function everything is fine:
CODE
...
int rc=0;
pDb = (sqlite3*) malloc (sizeof(sqlite3*));
stmt = (sqlite3_stmt*) malloc (sizeof(sqlite3_stmt*));
...
if((rc=sqlite3_prepare_v2(pDb, INSERT_STMT , -1,&stmt, NULL)) !=
SQLITE_OK){
/* ... error ... */
}
sqlite3_step(stmt);
...
\CODE
However, if I try throw this code in a separate function like this,
CODE
int prepareStatement(sqlite3_stmt* stmt, sqlite3* pDb){
int rc=0;
if((rc=sqlite3_prepare_v2(pDb, INSERT_STMT , -1,&stmt, NULL)) !=
SQLITE_OK){
/* ... error ... */
}
return 0;
}
\CODE
it fails as soon as I call sqlite3_step(stmt) afterwards. The
debugger stops at:
sqlite3_mutex_enter(db->mutex);
At first I thought I was doing smthg wrong during memory
allocation, but everything seems to be fine there. I'm sure I'm
overlooking an obvious mistake. Maybe somebody can give me a hint!
thanks,
John
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users