Reputation: 229
I've used the following method in my app,
-(int) getMax:(NSString *)subItemName second :(int) tableID
{
int count1=0;
sqlite3_stmt *statement;
NSString *query = [NSString stringWithFormat:@"Select MAX(NoOfItems) from billTable where SubItemName='%@' AND TableID='%d'",subItemName,tableID];
if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, nil)== SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
count1 = [[NSString stringWithUTF8String:(char *) sqlite3_column_text(statement, 0)]intValue];
}
sqlite3_step (statement);
}
return count1;
}
As you can see that the my query will return the no of rows (an integer), suppose if my query returns a NULL
value(if there is no such exists for the where clause condition in my database it returns NULL
value. How to check it returns NULL
after the query has been executed?
Upvotes: 0
Views: 1169
Reputation: 180030
You can call sqlite3_column_type() to find out what type a column value has:
if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, nil)== SQLITE_OK) {
if (sqlite3_step(statement) == SQLITE_ROW) {
if (sqlite3_column_type(statement, 0) == SQLITE_NULL)
count1 = -1; // or whatever
else
count1 = sqlite3_column_int(statement, 0);
}
sqlite3_finalize(statement);
}
Upvotes: 1