ios - Getting unable to open database file while inserting bulk data in sqlite db -
i using following code insert rows more 5000 in ios app. if not using line sqlite3_close(dbv); statement got error unable open database. , if use statement sqlite3_close(dbv) data insertion taking around 10-15 mins. can insert record faster without getting error.
-(void)insertrecordintotable:(nsstring*)sqlstatement { nsstring *sqlstr=sqlstatement; const char *sql=[sqlstr utf8string]; const char* key = [@"strongpassword" utf8string]; sqlite3_stmt *statement1; @try { int res = sqlite3_open([[self.databaseurl path] utf8string], &dbv); if (res != sqlite_ok) sqlite3_open([[self.databaseurl path] utf8string], &dbv); sqlite3_key(dbv, key, (int)strlen(key)); if(sqlite3_prepare_v2(dbv, sql, -1, &statement1, nil)==sqlite_ok) { nslog(@"done"); } else { nslog(@"the error occurred here %s ",sqlite3_errmsg(dbv)); } res =sqlite3_step(statement1); if(res !=sqlite_done) nslog(@"error upadating table"); sqlite3_finalize(statement1); sqlite3_close(dbv); } @catch (nsexception *exception) { } @finally { sql=null; sqlstr=null; sqlstatement=null; } }
after opening database add code
sqlite3_exec(mdb, "begin transaction", null, null, &errormessage); and, before closing database add code
sqlite3_exec(mdb, "commit transaction", null, null, &errormessage); for more details check link-
Comments
Post a Comment