如何从iPhone SQLite数据库中获取整数值通常我们使用以下内容用于varchar或string但是我们如何获得NSInteger值?
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和foodquality rating或NSString我在Integer中有调查ID,我们如何从表中获取。
答案 0 :(得分:5)
如果surveyId字段是食品质量后表格中的下一列,您将使用以下代码:
coffeeObj.surveyId = sqlite3_column_int(selectstmt, 3);
语句结尾处的3是列索引
答案 1 :(得分:1)
我使用下面的代码从SQlite数据库中获取整数值
NSInteger i=sqlite3_column_int(statement, 0);
答案 2 :(得分:0)
使用它 NSInteger i = sqlite3_column_int(statement,0);