我无法进行更新,但插入和选择工作正常。
笔记:
1)我使用的包装器来自:https ://github.com/misato/SQLiteManager4iOS
2) 相同的代码适用于 INSERT 语句,但不适用于更新
//NSString* sqlStr = (@"INSERT INTO sbu (sbuName) VALUES ( 'rrrr' );)"); //WORKS
3)这是代码:
与本次更新相关的代码如下:
我的内联代码
NSString* sqlStr = (@"UPDATE User SET Name = 'wweerr' WHERE Id = 19"); //using a direct sql to verify if it works - does not
SQLiteManager* dbManager =[[SQLiteManager alloc]initWithDatabaseNamed:@"data.db"];
NSError* error = [dbManager doQuery:sqlStr];
从图书馆:
- (NSError *)doQuery:(NSString *)sql {
NSError *openError = nil;
NSError *errorQuery = nil;
//Check if database is open and ready.
if (db == nil) {
openError = [self openDatabase];
}
if (openError == nil) {
sqlite3_stmt *statement;
const char *query = [sql UTF8String];
sqlite3_prepare_v2(db, query, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_ERROR) {
const char *errorMsg = sqlite3_errmsg(db);
errorQuery = [self createDBErrorWithDescription:[NSString stringWithCString:errorMsg encoding:NSUTF8StringEncoding]
andCode:kDBErrorQuery];
}
//NSLog(@"sql error: %@", error)
NSInteger result = sqlite3_finalize(statement);
errorQuery = [self closeDatabase];
}
else {
errorQuery = openError;
}