Reputation: 121
How to get integer values from iPhone SQLite data base normally we use following was for varchar or string but how can we get NSInteger values?
const char *sql = "select * from questions";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
DataController *coffeeObj = [[DataController alloc] initWithPrimaryKey:primaryKey];
coffeeObj.restaurantLocation = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
coffeeObj.foodQualityRating = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
restaurantlocation and foodquality rating or NSString I have survey id in Integer how can we fetch that from table.
Upvotes: 2
Views: 4417
Reputation: 5399
If the surveyId field is the next column in the table after food quality you would use the following code:
coffeeObj.surveyId = sqlite3_column_int(selectstmt, 3);
The 3 at then end of the statement is the column index
Upvotes: 5
Reputation: 3908
I used the below code to get integer value from SQlite database
NSInteger i=sqlite3_column_int(statement, 0);
Upvotes: 1