Just want to ask a basic question about SQLite3's REPLACE INTO usage. All my other database code is working, but the REPLACE INTO statement seems to work, but isn't there. I EXPECT to the REPLACE INTO to REPLACE the data in the specified row ID, id, held in variable dbRow.
insertSQL = [NSString stringWithFormat: @"REPLACE INTO script ( id, nrec, url ) VALUES ( \"%d\", \"%d\", \"%@\" )", dbRow, recN, fileLoc ];
insert_stmt = [insertSQL UTF8String];
if( sqlite3_exec(scriptDB, [insertSQL UTF8String], NULL, NULL, &errorSQL ) == SQLITE_OK) {
NSLog( @"dB updated at row=%d with nrec=%d and URL=%@.", dbRow, recN, fileLoc );
} else {
NSLog(@"Line Not replaced. Error: %s", errorSQL );
}
The above works: The OK condition shows exactly what I want to see. No errors. Later, when I need to use this data, it did NOT replace the original. So, just to test things, I do a SELECT right away, in the same method:
querySQL = [NSString stringWithFormat: @"SELECT id, nrec, url FROM script WHERE title=\"%@\" AND nline=\"%d\"", myTitle, myLineN ];
query_stmt = [querySQL UTF8String];
if( sqlite3_prepare_v2(scriptDB, query_stmt, -1, &statement, NULL) == SQLITE_OK) {
NSLog(@"Just Replaced Query prepared");
while( sqlite3_step(statement) == SQLITE_ROW ) {
myID = sqlite3_column_int(statement, 0);
myNRec = sqlite3_column_int(statement, 1);
myURL = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 4)];
}
sqlite3_finalize(statement);
NSLog( @"Line %d of %@ has: recN=%d in row=%d at url: %@", myLineN, myTitle, myNRec, myID, myURL );
} else {
NSLog( @"Error: %s", errMsg );
}
I expect to see the same thing that I REPLACE INTO'd the database. I don't. I see the original data, before the REPLACE. Why does it say it's there when it isn't?