-(BOOL)insertAttendees {
sqlite3_stmt *statement;
const char *insert_stmt = "INSERT INTO ATTENDEE (A_NAME,A_IMAGE,A_EMAIL,A_PHONE,A_BIO) VALUES (?,?,?,?,?)";
if (sqlite3_open(dbpath, &db) == SQLITE_OK)
{
if(sqlite3_prepare_v2(db, insert_stmt, -1, &statement, nil) != SQLITE_OK){
NSLog(@"[ERROR] SQLITE: Failed to prepare statement! :%s",sqlite3_errmsg(db));
return NO;
}
for (int i=0; i<[attendeeCount[0]integerValue];i++){
sqlite3_bind_text(statement, 1, [arrayOf_AName[0][i] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 2, [arrayOf_AImage[0][i] UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 3, [arrayOf_AEmail[0][i] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 4, [arrayOf_APhone[0][i] UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text(statement, 5, [arrayOf_ABio[0][i] UTF8String], -1, SQLITE_TRANSIENT);
}
if (sqlite3_step(statement) == SQLITE_ERROR) {
NSLog(@"[ERROR] SQLITE: Failed to insert into database! Error: '%s' ", sqlite3_errmsg(db));
return NO;
}
sqlite3_finalize(statement);
}
else{
NSLog(@"[ERROR] SQLITE: Failed to open database! Error: '%s' ", sqlite3_errmsg(db));
return NO;
}
return YES;
}
答案 0 :(得分:0)
原因是您只拨打sqlite3_step
一次。
您必须将该调用移至for
循环。
(该代码的可怕缩进可能有助于引入此错误。)