Reputation: 8151
I am trying to take the data from one table and move it over to another table. First I select all the records from the Items table in the db_data database. Then for every record that is in that table it should insert it into the Items table in the db_information database. I am only getting one record written into my Items table in the db_information database. I have 8 records in the Items table in the db_data database. So why is it not inserting all my records?
strSQL = @"SELECT GID FROM Items";
chrStmt = [strSQL UTF8String];
if(sqlite3_prepare_v2(db_data, chrStmt, -1, &cmpStmt, NULL) == SQLITE_OK){
while(sqlite3_step(cmpStmt) == SQLITE_ROW){
char *val = (char *)sqlite3_column_text(cmpStmt, 0);
NSString *strVal = [NSString stringWithUTF8String:val];
strSQL = [NSString stringWithFormat:@"INSERT INTO Items (GID) VALUES ('%@')", strVal];
chrStmt = [strSQL UTF8String];
if(sqlite3_prepare_v2(db_information, chrStmt, -1, &cmpStmt, NULL) == SQLITE_OK){
sqlite3_step(cmpStmt);
}
}
}
Upvotes: 0
Views: 90
Reputation: 80265
I think that maybe you are falsely reusing your variables strSQL
, chrStmt
and especially cmpStmt
. This is both used in the while
loop condition and main body.
Try using separate variables for the other database.
Upvotes: 1