webkit 中的 sqlite 支持 RANDOM() 函数吗?
我正在为 iOS 编写一个基于 Phonegap 的应用程序,并尝试通过 Javascript 从我的 Safari webkit 数据库中返回 10 个随机行。我的查询是:
queryString = "SELECT * FROM SBA_TABLE
WHERE (cat_gastrointestinal = 1)
AND (answered_correctly = 0 OR answered_correctly = 1 OR answered_correctly = 2)
ORDER BY RANDOM() LIMIT 10";
tx.executeSql(queryString, [], querySuccess5, errorCB);
如果我省略“ORDER BY RANDOM()”语句,这会起作用,这让我相信这不受支持。是否有我可以使用的 RANDOM 方法,或者我必须生成 10 个随机数并进行 10 次数据库调用?!谢谢,尼克
I'm coding a Phonegap based app for iOS, and am trying to return 10 random rows from my Safari webkit database via Javascript. My query is:
queryString = "SELECT * FROM SBA_TABLE
WHERE (cat_gastrointestinal = 1)
AND (answered_correctly = 0 OR answered_correctly = 1 OR answered_correctly = 2)
ORDER BY RANDOM() LIMIT 10";
tx.executeSql(queryString, [], querySuccess5, errorCB);
This works if I omit the 'ORDER BY RANDOM()' statement which leads me to believe this is not supported. Is there a RANDOM method I could use, or do I have to generate 10 random numbers and make 10 database calls?! Thanks, Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚遇到了同样的问题,我用这样的解决方法解决了它:
使用 Javascript Math.random() 函数和查询中表 ROWID 的模数。
I just had the same problem, I solved it with such workaround:
Using the Javascript Math.random() function and a modulo on the table ROWID in the query.
暂定解决方法,以防
ORDER BY RANDOM()
在该版本上特别不起作用:Tentative workaround, in case
ORDER BY RANDOM()
specifically isn't functional on that version: