我是 xcode 的新手,我在更新 sqlite 时遇到问题。
读取BioViewController.h
@interface readBioViewController : UIViewController {
NSString *fav;
}
读取BioViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
fav = @"1";
}
- (IBAction)addFavorito:(id)sender {
DataDAO *dbCrud = [[DataDAO alloc] init];
NSLog(@"addFavorito favid '%@'.", fav);
[dbCrud addFavorito:fav];
}
数据DAO.m
-(void)addFavorito:(NSString *)fav {
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dirPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"versos.sqlite"];
BOOL success = [fileMgr fileExistsAtPath:dirPath];
if(!success) {
NSLog(@"Cannot locate database file '%@'.", dirPath);
}
if(!(sqlite3_open([dirPath UTF8String], &db) == SQLITE_OK)) {
NSLog(@"An error has occured.");
}
NSString *sql = @"update Versos set favorito = 1 Where id = 2";
char *err;
if(sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
sqlite3_close(db);
NSLog(@"erro no update");
} else
NSLog(@"fez o update");
}
我有一个按钮(IBOutlet - addFavorito),我想执行 sql 来更新 ID(2)。我在 NSLog 中看到了结果 "NSLog(@"fez o update");" 但是当我打开 versos.sqlite 时,ID 2 中的结果是 favourito=0 而没有 favourito=1。