调用executeUpdate,屏蔽Could not find index for XXX信息

来源:互联网 发布:java多线程并发测试 编辑:程序博客网 时间:2024/05/16 08:10

我们的app使用FMDatabase操作sqlite3,其中有段代码:

NSString *sql = @"update tb_users set baseInfo_name = :baseInfo_name, contact_email = :contact_email, baseInfo_image = :baseInfo_image;NSDictionary *data = [datas objectAtIndex:0];    BOOL result = [db executeUpdate:sql withParameterDictionary:mutable];       

这句sql执行的时候,控制台报了很多Could not find index for XXX。发现如果执行的是insert语句则没有这个现象,只有update语句才会出现

查看了一下FMDatabase的源码:

    // If dictionaryArgs is passed in, that means we are using sqlite's named parameter support    if (dictionaryArgs) {                for (NSString *dictionaryKey in [dictionaryArgs allKeys]) {                        // Prefix the key with a colon.            NSString *parameterName = [[NSString alloc] initWithFormat:@":%@", dictionaryKey];                        // Get the index for the parameter name.            int namedIdx = sqlite3_bind_parameter_index(pStmt, [parameterName UTF8String]);                        FMDBRelease(parameterName);                        if (namedIdx > 0) {                // Standard binding from here.                [self bindObject:[dictionaryArgs objectForKey:dictionaryKey] toColumn:namedIdx inStatement:pStmt];                                // increment the binding count, so our check below works out                idx++;            }            else {                NSLog(@"Could not find index for %@", dictionaryKey);            }        }    }

调用executeUpdate:WithParameterDictionary:方法时,会查找索引,没找到则会打印日志



0 0