我在我的网络服务中获取数据后尝试更新我的数据库,但它不起作用,我不知道为什么......这里我的代码..
- (void) getCurrentVersion {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:@"http://www.sample.com/api/getdata"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject){
NSDictionary *versionJson = (NSDictionary *)responseObject;
networkBase = [versionJson objectForKey:@"NetworkBase"];
baseVersion = [versionJson objectForKey:@"Version"];
[db insertData:networkBase withVersion:baseVersion];
NSLog(@"getCurrentVersion %@ %@",networkBase,baseVersion);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSString *errorMessage = [error localizedDescription];
NSLog(@"%@",errorMessage);
}];
}
这里是db
的代码 - (void)insertData:(NSString *)networkBase withVersion:(NSString *)version{
const char *dbpath = [self.databasePath UTF8String];
sqlite3_stmt *statement2;
if (sqlite3_open(dbpath, &_contactDB) == SQLITE_OK) {
NSString *insertSQL = [NSString stringWithFormat:@"UPDATE version SET message = '%@', storeversion = '%@' WHERE id = 1",networkBase,version];
const char *insert_stmt = [insertSQL UTF8String];
if (sqlite3_prepare_v2(_contactDB, insert_stmt, -1, &statement2, NULL) == SQLITE_OK) {
if (sqlite3_step(statement2) == SQLITE_DONE ) {
NSLog(@"Inserting Success!");
}
else{
NSLog(@"%s",sqlite3_errmsg(_contactDB));
}
}
}
sqlite3_finalize(statement2);
sqlite3_close(_contactDB);
}
所以我的问题在于这一行
[db insertData:networkBase withVersion:baseVersion];
NSLog(@"getCurrentVersion %@ %@",networkBase,baseVersion);
它执行NSLog但不执行[db insertdata]