Should I use sqlite3_finalize after executing a query with sqlite3_exec?

I use Sqlite3 in my application for iPhone, I get some unwanted rollbacks, apparently randomly. However, I do not know if this is due to the fact that I am not completing the statements with help sqlite3_finalize, since, as far as I know, it sqlite3_execwill take care of this.

I also found several SELECT s sqlite3_prepare_v2that I did not complete, so I know I have to complete them, but should I do the same with the tags in sqlite3_exec?

One of my statements:

NSString *query=@"UPDATE books SET title='newName' WHERE id='21';";
if ((result=sqlite3_open([database UTF8String], &_database))==SQLITE_OK) {
    result=sqlite3_exec(_database, [query UTF8String],NULL,NULL,&errorMsg);
    if (result!=SQLITE_OK) {
        printf("\n%s",errorMsg);
        sqlite3_free(errorMsg);
    }
    sqlite3_close(_database);
}

Do I have sqlite3_finalize(result)to close the database?

+3
source share
2 answers

. , sqlite3_finalize() , , sqlite3_prepare_v2() .

+10

sqlite3_finalize() sqlite3_exec. , sqlite3_exec :

  • sqlite3_prepare_v2()
  • sqlite3_step()
  • sqlite3_finalize()

sqlite : http://www.iosdevelopment.be/sqlite-tutorial/

+1

Source: https://habr.com/ru/post/1722633/


All Articles