在返回时存储Sqlite数据库中的值

时间:2012-07-24 06:32:37

标签: ios sqlite

所以,当我直接在sqlite中执行查询时,它会按顺序返回我所期望的值。但是当我在我的iOS应用程序上显示它时,它按升序对值进行排序,这是我不希望发生的。任何人都可以帮我解决这个问题吗?!

提前致谢!! : - )

2 个答案:

答案 0 :(得分:1)

您的查询是否有“按订单”声明?也许这种方式可以让你控制得到你想要的结果。

答案 1 :(得分:0)

你想要达到的目标应该不是问题:

  1. 进行SQL查询: 它可能看起来像select columname from yourtable order by asc asc将按字母顺序对结果进行排序,如果您想要对结果进行排序

  2. 逐行读取SQL查询的结果。以下是一些代码片段:

    NSString *SQLQuery  = @"your SQL query here" 
    
    // The SQL statement that you plan on executing against the database 
    const char *sql =  [SQLQuery UTF8String];
    
    // The SQLite statement object that will hold your result set 
    sqlite3_stmt *statement;
    
    // Prepare the statement to compile the SQL query into byte-code
    int sqlResult = sqlite3_prepare_v2(database, sql, -1, &statement, NULL);
    
    
    if (sqlResult== SQLITE_OK) {
    
        while (sqlite3_step(statement) == SQLITE_ROW) {
    
        // feed the result in a mutable array here
        // e.g [yourmutablearray addObj: yourObj];
    
        }
    
        // Finalize the statement to release its resources
        sqlite3_finalize(statement);
    }
    else // catch up any possible issue here
    {
        NSLog(@"Problem excuting SQL statement on the Database:"); 
        NSLog(@"%d",sqlResult);
    }