iphone - 如何从 iPhone 中的 sqlite 数据库获取整数值

标签 iphone xcode sqlite

如何从 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)];

餐厅位置和食品质量评级或 NSString 我有整数形式的调查 ID,我们如何从表中获取它。

最佳答案

如果 SurveyId 字段是表中食品质量之后的下一列,您将使用以下代码:

coffeeObj.surveyId = sqlite3_column_int(selectstmt, 3);

语句末尾的 3 是列索引

关于iphone - 如何从 iPhone 中的 sqlite 数据库获取整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11558769/

相关文章:

node.js - 使用 SQLite3 和 ExpressJs 时,如何确保 app.get() 在调用 db.each() 方法时不是异步的?

iphone - UIApplication 的 openURL 使我的应用程序崩溃

ios - 如何创建 UIView 弹跳动画?

iphone - 在 UItextView iPhone 中获取最大内容偏移量

ios - Swift 中的 NSAttributedString 问题

ios - 沿途发送的多点连接和数据

ios - 如何检测 NSUserDefault 的变化?

c++ - 使用 SQLite 在附加数据库中使用触发器的效率

ios - 未找到 ios 开发证书且未找到未过期的配置文件

c++ - 从 SQLite 获取 int 值