Hi, I am new to sqlite and C. I have not been able to write a code which would read row by row using sqlite3_step.
Could anybody guide me please. Dan Kennedy-4 wrote: > > On Tue, 2007-06-19 at 10:58 +0530, anand chugh wrote: >> Hi >> >> I am having code like this: >> >> rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); >> if( rc!=SQLITE_OK ){ >> return rc; >> } >> sqlite3_bind_text(pStmt, 1, zKey, -1, SQLITE_STATIC); >> sqlite3_bind_blob(pStmt, 2, zBlob, nBlob, SQLITE_STATIC); >> >> while( sqlite3_step(pStmt)==SQLITE_ROW ) >> { >> *pnBlob = sqlite3_column_bytes(pStmt, 0); >> *pzBlob = (unsigned char *)malloc(*pnBlob); >> memcpy(*pzBlob, sqlite3_column_blob(pStmt, 0), *pnBlob); >> } >> >> sqlite3_finalize(pStmt); >> >> My question here is do I need to do sqlite3_finalize(pStmt); after >> every sqlite3_step() to free all memory allocated by >> sqlite3_step(). > > No. Exactly one sqlite3_finalize() for each sqlite3_prepare(). In > this respect the code above is fine. > > It's not SQLite related, but if the SQL statement returns more > than one row, the malloc() in the while loop will cause a memory > leak. > > Dan. > >> Does calling finalize at end will free all memory >> allocated by all steps statements? >> >> Example shown http://www.sqlite.org/cvstrac/wiki?p=BlobExample does >> same , it calls finalize after every step. >> >> My Program shows some Memory Leaks(Virtual Bytes). >> >> Please clarify. >> >> Anand >> >> ----------------------------------------------------------------------------- >> To unsubscribe, send email to sqlite-users-unsubscr...@sqlite.org >> ----------------------------------------------------------------------------- >> > > > ----------------------------------------------------------------------------- > To unsubscribe, send email to sqlite-users-unsubscr...@sqlite.org > ----------------------------------------------------------------------------- > > > -- View this message in context: http://www.nabble.com/Step-Query-tp11188705p22677241.html Sent from the SQLite mailing list archive at Nabble.com. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users