データベースにデータを追加するのに問題があり、これはとても奇妙な問題です
以下のように2つの引数だけでデータを追加する場合
for(int i=0; i<_birthdateincontects.count; i++){
sqlite3_stmt *stmt;
int x;
char *update = "insert into PersonNamesAndBirthDates (Names,Birthdates) values(?,?);";
x = sqlite3_prepare_v2(database1, update, -1, &stmt, nil);
if (x == SQLITE_OK)
{
NSLog(@"%@",[NSString stringWithFormat:@"%@",[_namesincontects objectAtIndex:i]]);
NSLog(@"%@",[NSString stringWithFormat:@"%@",[_birthdateincontects objectAtIndex:i]]);
sqlite3_bind_text(stmt, 1, [[NSString stringWithFormat:@"%@",[_namesincontects objectAtIndex:i]] UTF8String],-1, NULL);
sqlite3_bind_text(stmt, 2, [[NSString stringWithFormat:@"%@",[_birthdateincontects objectAtIndex:i]] UTF8String],-1, NULL);
if (sqlite3_step(stmt) != SQLITE_DONE){}
sqlite3_finalize(stmt);
}
その後、完全に機能し、追加ループが3回発生し、データが追加されます
しかし、私がこのように追加しようとすると
for(int i=0; i<_birthdateincontects.count; i++){
sqlite3_stmt *stmt;
int x;
char *update = "insert into PersonNamesAndBirthDates (Names,Birthdates,Profilepic) values(?,?,?);";
x = sqlite3_prepare_v2(database1, update, -1, &stmt, nil);
if (x == SQLITE_OK)
{
NSLog(@"%@",[NSString stringWithFormat:@"%@",[_namesincontects objectAtIndex:i]]);
NSLog(@"%@",[NSString stringWithFormat:@"%@",[_birthdateincontects objectAtIndex:i]]);
NSLog(@"%@",[NSString stringWithFormat:@"%@",@"No Image"]);
sqlite3_bind_text(stmt, 1, [[NSString stringWithFormat:@"%@",[_namesincontects objectAtIndex:i]] UTF8String],-1, NULL);
sqlite3_bind_text(stmt, 2, [[NSString stringWithFormat:@"%@",[_birthdateincontects objectAtIndex:i]] UTF8String],-1, NULL);
sqlite3_bind_text(stmt, 3, [[NSString stringWithFormat:@"%@",@"No Image"] UTF8String],-1, NULL);
if (sqlite3_step(stmt) != SQLITE_DONE){}
sqlite3_finalize(stmt);
}
次に、上記のループと同じように3回実行されますが、データベースでは最初のrawループが追加され、他の時間ループが実行されますが、これが発生する理由は何も追加されません。plzは何かを提案し、この混乱から私を解放します
注:nslogは値を完全に出力します