调用
[rs objectForColumnName:@"xxx"];
如果column xxx没有值,则上面代码返回的是NSNull,但是直接判断
if(NSNull){
}
会被判定为true,从而执行花括号中的代码。所以下面这段代码是错误的:
if([rs objectForColumnName:@"xxx"]){
// 当column xxx有值时的逻辑
}
即使column xxx没有值,也会走到花括号中。正确的写法应该是:
NSNumber *defInt1 = [rs objectForColumnName:@"def_int1"];
if(![defInt1 isEqual:[NSNull null]]){
// 当def_int1有值时的逻辑
}