iphone - When to do finalize statement in sqlite in iOS? -


when using sqlite in ios, when finalize statement ?

do need finalize statement after every query ?

what difference between reset , finalize ?

if reset, need finalize ?

thanks.

you use sqlite3_finalize() function when finished statement, either because did one-off query following:

const char *sql = "select count(*) bonds molecule=? , structure=?"; sqlite3_stmt *bondcountingstatement;  unsigned int totalbondcount = 0;  if (sqlite3_prepare_v2(database, sql, -1, &bondcountingstatement, null) == sqlite_ok)  {     sqlite3_bind_int(bondcountingstatement, 1, databasekey);     sqlite3_bind_int(bondcountingstatement, 2, numberofstructurebeingdisplayed);      if (sqlite3_step(bondcountingstatement) == sqlite_row)     {         totalbondcount =  sqlite3_column_int(bondcountingstatement, 0);     }     else     {     } } sqlite3_finalize(bondcountingstatement); 

or if done prepared statement you'll never need again (possibly because you're cleaning on exiting application).

if you've created statement you'll want use on , on again (for performance reasons, because reasonably expensive prepare statement), use sqlite3_reset() reset query ready use again. don't want finalize in case until have decided you'll never want reuse statement (again, during teardown of application or particular object).

an example of query resets statement @ end follows:

sqlite3_bind_text(insertmoleculesqlstatement, 1, [filename utf8string], -1, sqlite_transient); int success = sqlite3_step(insertmoleculesqlstatement);  // because want reuse statement, reset instead of finalizing it. sqlite3_reset(insertmoleculesqlstatement); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -