I am trying to save more than 500 records at once in sqlite, code that I have wrote so far is given below
The method name closeDatabase closes any open connection of the database the variable ContactID is nothing but an Array which is populated with ContactID of people present in my address book.
sqlite3_exec(databaseRefObj, "BEGIN TRANSACTION", 0, 0, 0); for (NSString *contactIDstr in contactID) { const char *insertintoGropsMember = "My insert query here"; NSString *groupIDstr = [NSString stringWithFormat:@"%d",grpID]; [self closeDatabase]; if(sqlite3_prepare_v2(databaseRefObj, insertintoGropsMember, -1, &sqlstatement, NULL)==SQLITE_OK) { sqlite3_bind_text(sqlstatement, 1, [groupIDstr UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(sqlstatement, 2, [contactIDstr UTF8String], -1, SQLITE_TRANSIENT); sqlite3_step(sqlstatement); } else { successFlag = NO; } sqlite3_finalize(sqlstatement); sqlite3_close(databaseRefObj); } sqlite3_exec(databaseRefObj, "END TRANSACTION", 0, 0, 0);
The process of data insertion is quite slow here and I would like to know where am I going wrong or what steps should I follow to optimize my sqlite performance.
Please note that I am not using any kind of index on the column on which I want to perform the insert.
[self closeDatabase];
??? – trojanfoeSQLITE_TRANSIENT
? Why prepare the same statement multiple times? – trojanfoe