【问题标题】:sqlite Query is not working in iOS 8.0 - 8.1 and working in IOS 8.2sqlite Query 在 iOS 8.0 - 8.1 中不工作,在 IOS 8.2 中工作
【发布时间】:2016-12-05 08:48:19
【问题描述】:

Sql Query 在 IOS 8.0 8.1 中不工作,在 IOS 8.2 中工作 请找到下面的 sqlite 查询。

-(BOOL)insertRecordsFromlastDateToCurrentDate{

    NSString *resultString = @"";
    if(database == nil)
    {
        NSString *dbPath = [DatabaseHandler getDBPath];

        if (sqlite3_open([dbPath UTF8String], &database) != SQLITE_OK) {

            NSAssert1(0, @"Error while opening Database. '%s'", sqlite3_errmsg(database));
            return nil;
        }

    }
    NSString *queryString = [NSString stringWithFormat:@"WITH RECURSIVE dates(category, points,diagonisePoints, date) AS (VALUES('Healthy Weight', '0','0', (select DATE(selectedDate, '+1 day') as selectedDate from glanceTable ORDER BY ROWID DESC LIMIT 1)),('Healthy Diet', '0','0',(select DATE(selectedDate, '+1 day') as selectedDate from glanceTable ORDER BY ROWID DESC LIMIT 1)),('Exercise', '0','0',(select DATE(selectedDate, '+1 day') as selectedDate from glanceTable ORDER BY ROWID DESC LIMIT 1)),('Smoking Cessation', '0','0',(select DATE(selectedDate, '+1 day') as selectedDate from glanceTable ORDER BY ROWID DESC LIMIT 1)) UNION ALL SELECT category, points,diagonisePoints, date(date, '+1 day') FROM dates WHERE date < date('now')) insert into glanceTable SELECT category, points,diagonisePoints, date  as selectDate FROM dates  WHERE date <= date('now')"];

    const char *sql = [queryString cStringUsingEncoding:NSASCIIStringEncoding];
    sqlite3_stmt *selectstmt;
    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {


        while(sqlite3_step(selectstmt) == SQLITE_ROW) {
            resultString = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)] ;
        }
    }
    return YES;
}

我们非常感谢您的反馈。

【问题讨论】:

  • 有任何错误、警告吗?
  • @Mr.Bista 错误消息:“WITH”语法错误。

标签: ios objective-c sqlite


【解决方案1】:

据我所见,RECURSIVE 关键字是在 Sqlite 3.8.3 版本中引入的。因此,iOS 8.0 8.1 可能使用旧版本的 sqlite 运行,因此会出现错误。

相关帖子:

How to fix "near 'with': syntax error" in recursive CTE query (flask/sqlalchemy)

basic recursive query on sqlite3?

【讨论】:

  • 我使用的 sqlite 3.13.0 版本在
  • 我想在 iOS 8.0 和 8.1 中解决上述问题
【解决方案2】:

iOS 8.2 支持的递归查询在旧版本中不存在。 如果你想要递归而不是你必须将最低操作系统版本设置为 8.2,这取决于你的要求。

在 Android 中,Recursive 也不支持比 Lollipop 更早的版本...

【讨论】:

  • 这意味着iOS
猜你喜欢
  • 1970-01-01
  • 2015-05-18
  • 2013-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-15
  • 1970-01-01
相关资源
最近更新 更多