好诡异的bug,fmdb创建表不成功。。。各位帮忙看看!

sam 发布于 2013年09月24日
无人欣赏。
        for (int i=1; i<arr.count; i ++) {
            NSString * schame = [diclistData objectForKey:[arr objectAtIndex:i]];
            NSString * table = [arr objectAtIndex:i];

        NSString *successDropTable = [[NSUserDefaults standardUserDefaults] objectForKey:
                                      [NSString stringWithFormat:@"%@%d_%@_successDrop",App_Version,enterpriseno,table]];
        if (!successDropTable ) {
            successDropTable = @"";
        }

        NSLog(@"the successDropTable :%@_%di:%d",successDropTable,enterpriseno,i);
      //  if ([successDropTable isEqualToString:@"yes"]) {
      //      continue;
      //  }
      //  else{
            [DBConnection updateTheTableStructureWith:table WithSchame:schame success:^(BOOL issuccess) {
                if (issuccess) {
                    NSLog(@"creattable success");
                     [[NSUserDefaults standardUserDefaults] setObject:@"yes" forKey:[NSString stringWithFormat:@"%@%d_%@_successDrop",App_Version,enterpriseno,table]];
                }

            } failure:^(NSError *error) {

            }];
      //  }

    }

for里面的if判断如果注释掉,直接执行创建表的方法,则可以成功新建表,反之加if判断,同样执行了if里面的方法,新建表不成功(有输出creattable success,实际数据库里没有新表)。。。

fmdb的建表方法:

+ (void)updateTheTableStructureWith:(NSString *)table
                     WithSchame:(NSString *)schame
                        success:(void(^)(BOOL issuccess))success
                        failure:(void(^)(NSError *error))failure{

FMDatabase *db = [DBConnection getSharedDatabase];
[db open];

if ([db tableExists:table]){
    NSString *sql = [NSString stringWithFormat:@"DROP TABLE  IF EXISTS %@ ",table];
    BOOL dropsuccess  =  [db executeUpdate:sql];
        NSLog(@"Error %d : %@",[db lastErrorCode],[db lastErrorMessage]);
    if (dropsuccess) {
        NSLog(@"DROP tablbe secceuful->-> %@",table);
        NSLog(@"Error %d : %@",[db lastErrorCode],[db lastErrorMessage]);
    }


    NSString *creatTablesql = [NSString stringWithFormat:@"%@",schame];
    BOOL creatsuccess  =  [db executeUpdate:creatTablesql];
    //if (creatsuccess) {
        NSLog(@"update Error %d : %@",[db lastErrorCode],[db lastErrorMessage]);
        NSLog(@"Creat tablbe secceuful ->->%@-->%@",table,schame);
        success(creatsuccess);
   // }

}
else{
    NSString *creatTablesql = [NSString stringWithFormat:@"%@",schame];
    BOOL csuccess  =  [db executeUpdate:creatTablesql];
   // if (csuccess) {
        NSLog(@"update Error %d : %@",[db lastErrorCode],[db lastErrorMessage]);
        NSLog(@"Creat tablbe secceuful ->->%@-->%@",table,schame);
   // }
    success(csuccess);
}

[db close];

}

共3条回复
tinyfool 回复于 2013年09月24日

有没有什么错误信息和提示?

sam 回复于 2013年09月24日
updateTheTableStructureWith 

这个方法里的输出,提示没有错误,输出 update Error 0 : not an error

sam 回复于 2013年09月24日

1楼 @tinyfool 诡异的是注释那个if判断后,就成功新建表。。。加个判断,两样是执行了建表方法,倒不成功了。。。updateTheTableStructureWith 这个方法输出提示也是 update Error 0 : not an error ,就是数据库没有新添的表

登录 或者 注册
相关帖子