0 sqlite xcode objective-c ios
I'm writing some code here, and I'm having a had time.
I have a value in my Database that can be null as its an average of other data, if that data hasn't been populated there is nothing to take the average of.
In my query there will return a null value at times. The value that would be there normally is a double. SO i have
NSNumber *num = [NSNumber numberWithDouble:sqlite3_column_double(compiledStatement,7)];
if (num == nil) {
do something
}
else {
do something else
}
Run Code Online (Sandbox Code Playgroud)
For some reason it is defualting to 0. When i NSLog it, it is 0, But using terminal, i'm able to be certain that my query (through terminal) is returning null for that value.
Any help would be greatly appreciated!
Thanks Guys!
By calling [NSNumber numberWithDouble:] you are guaranteeing that you get an NSNumber back. If you want to check for null, you have to do it separately, perhaps by calling sqlite3_column_type() and checking for SQLITE_NULL. Something like:
if ( sqlite3_column_type(compiledStatement, 7) != SQLITE_NULL )
{
NSNumber *num = [NSNumber numberWithDouble:sqlite3_column_double(compiledStatement,7)];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2864 次 |
| 最近记录: |