在寻找 SQLite 的语法帮助时,发生了一件非常奇怪的事情。我正在 iPhone 上运行查询。
这是失败的查询:(假设表是正确的,这在 firefox sqlite 插件中运行良好)
select tcodes.DisplayOrder, StatusText, StatusCode
from tcodes
join tcode_transitions on tcode_transitions.available = tcodes.UNID
where StatusCode = 'AAA'
order by tcodes.DisplayOrder
为了让它运行,我必须删除 order by 子句,这看起来有点奇怪。
这是电话:
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
int rtn = sqlite3_prepare_v2(database, [sql UTF8String], -1, &compiledStatement, nil);
if(rtn != SQLITE_OK) {
NSLog(@"SQL Error: %d",rtn);
sqlite3_close(database);
}
}
上面的rtn为==1,表示SQL错误。
同样,查询在手机之外运行得很好。 iPhone 上的 SQL 库是否可能有不同的 order by 语法?
最佳答案
使用
sqlite3_errmsg
(或sqlite3_errmsg16
)以获取有关错误的更多信息。尝试将 DisplayOrder 添加到 select 子句。 某些数据库要求 ORDER BY 子句中的所有列也出现在 SELECT 子句中。
关于iphone - SQLite 语法(按引起错误的顺序排列),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3097122/