Sql查询在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;
}非常感谢您的反馈。
发布于 2016-12-05 17:36:25
据我所知,递归关键字是在Sqlite 3.8.3版本中引入的。因此,iOS 8.0 8.1可能运行的是较旧的sqlite版本,因此出现错误。
相关帖子:
How to fix "near 'with': syntax error" in recursive CTE query (flask/sqlalchemy)
发布于 2016-12-05 17:59:48
在旧版本的iOS 8.2中不支持递归查询。这是你的要求,如果你想要递归,那么你必须将操作系统的最低版本设置为8.2。
在Android中,递归也不支持比棒棒糖更老的版本...
https://stackoverflow.com/questions/40970282
复制相似问题