配列要素を sqlite に挿入すると、正しく挿入されます。挿入中にエラーが表示されているため、配列の最初の要素のみが必要です。私のコードは次のとおりです。
NSString *path=[self getDBPath];
sqlite3_stmt *insert_statement = nil;
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
for (int i = 0; i < [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, &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);
sqlite3_finalize(insert_statement);
insert_statement = nil;
}
}
sqlite3_close(database);
}
1 つのレコードしか許可されないのはなぜですか?