ios - Insert the Large Amount of Data in SQLite in iPhone -


i want inset 2000 rows in database table there way insert data fast.currenty using below code insert data in database.

code :-

+(nsstring* )getdatabasepath{     nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     nsstring *documentsdirectory = [paths objectatindex:0];     nsstring *writabledbpath = [documentsdirectory stringbyappendingpathcomponent:@"crocodilian"];     return writabledbpath;  }  +(nsmutablearray *)executequery:(nsstring*)str{      sqlite3_stmt *statement= nil;     sqlite3 *database;     nsstring *strpath = [self getdatabasepath];     nsmutablearray *alldataarray = [[nsmutablearray alloc] init];     if (sqlite3_open([strpath utf8string],&database) == sqlite_ok) {         if (sqlite3_prepare_v2(database, [str utf8string], -1, &statement, null) == sqlite_ok) {               while (sqlite3_step(statement) == sqlite_row) {                             nsinteger = 0;                 nsinteger icolumncount = sqlite3_column_count(statement);                 nsmutabledictionary *dict = [[nsmutabledictionary alloc] init];                 while (i< icolumncount) {                     nsstring *str = [self encodedstring:(const unsigned char*)sqlite3_column_text(statement, i)];                   nsstring *strfieldname = [self encodedstring:(const unsigned char*)sqlite3_column_name(statement, i)];                      [dict setobject:str forkey:strfieldname];                     i++;                 }                  [alldataarray addobject:dict];                 [dict release];             }         }          sqlite3_finalize(statement);     }      sqlite3_close(database);     return alldataarray; } 

thanks in advance.

your problem is, trying insert 1 row @ time. sqlite adds commit after every insert. had similar issue of performance while inserting large data. solved using batch insert.

first create query multiple inserts (don't need prepared statement in case) , fire query @ once. has major performance improvement. thing that, have validate data before creating multiple insert query.

happy coding ..


Comments

Popular posts from this blog

Need help in packaging app using TideSDK on Windows -

java - Why does my date parsing return a weird date? -

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -