Ho dovuto cercare molti post su questi errori, ma ancora non riesco a risolvere il problema. Ecco il mio codice, qualcuno può aiutarmi a vedere cosa sta andando storto?Errore tabella non corrispondente
- (void) copyDatabaseIfNeeded {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"SQL.sqlite"];
if (sqlite3_open([path UTF8String], &newDBconnection) == SQLITE_OK)
{
NSLog(@"Database opened successfully");
if(updateStmt == nil) {
NSString *updStmt = [NSString stringWithFormat: @"UPDATE Coffee SET CoffeeName = '500 Plus', Price = '1.40' Where CoffeeID= '3'"];
const char *mupdate_stmt = [updStmt UTF8String];
if(sqlite3_prepare_v2(newDBconnection, mupdate_stmt, -1, &updateStmt, NULL) != SQLITE_OK){
NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(newDBconnection));
} else {
NSLog(@"Update successful");
}
}
if(SQLITE_DONE != sqlite3_step(updateStmt))
NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(newDBconnection));
else {
sqlite3_reset(updateStmt);
NSLog(@"Step successful");
}
}
else
{
NSLog(@"Error in opening database ");
}
}
Riesco a trovare il Coffee table eseguendo SQL "SELECT * FROM sqlite_master" e il database viene aperto correttamente, proprio quando si tratta di aggiornare, l'errore si verifica – Sunny
@Sunny Se lo stai controllando con il browser SQLite o il comando- strumento linea, potresti aprire un file diverso. Scarica il 'percorso' nel log e esegui una query' sqlite_master' con lo stesso codice subito prima di eseguire 'UPDATE'. – hamstergene
ok .. ora funziona :) grazie mille – Sunny