Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Its occured due to finalize statement in loop every time. So it wont let insert other objects after the first object.</p> <p>Just remove <code>"sqlite3_finalize(insert_statement);"</code> from the loop and set <code>nil</code> to the insert statement <code>"insert_statement = nil;"</code> </p> <p>After done with loop. Make sure place the <code>"sqlite3_reset(insert_statement);"</code> for each object in the loop. It reset the statement and there is no need to set <code>nil</code> to the statement in loop.</p> <p>Try this snatch of code it works for me:</p> <pre><code>if (sqlite3_open([path UTF8String], &amp;database) == SQLITE_OK) { for (int i = 0; i &lt; [array count]; i++) { NSLog(@"Array Count is %d",[array count]); NSString *name=[[array objectAtIndex:i]objectForKey:@"name"]; NSString *add=[[array objectAtIndex:i]objectForKey:@"address"]; if (insert_statement == nil) { NSString *statement1 = [NSString stringWithFormat:@"insert into tableName (name,address) Values( ?,?)",name,add]; const char *insertSql = [statement1 UTF8String]; if(sqlite3_prepare_v2(database, insertSql, -1, &amp;insert_statement, NULL) != SQLITE_OK){ NSLog(@"Error while creating insert statement."); insert_statement = nil; continue; } sqlite3_bind_text(insert_statement, 1, [name UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_text(insert_statement, 2, [add UTF8String], -1, SQLITE_TRANSIENT); if(SQLITE_DONE != sqlite3_step(insert_statement)){ //NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database)); NSLog(@"Error while inserting data."); insert_statement = nil; continue; } else{ sqlite3_reset(insert_statement); } } } insert_statement = nil; sqlite3_finalize(insert_statement); sqlite3_close(database); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload