Android:Sqlite rawQuery 超出范围
我正在尝试使用带有 simpleCursorAdapter 的 rawQuery 来显示到列表视图,但它一直向我抛出错误
04-29 13:36:36.453:错误/AndroidRuntime(29539):java.lang.RuntimeException:无法启动活动ComponentInfo {com.QuoteMachine / com.QuoteMachine.Quote}:android.database.sqlite.SQLiteException:绑定或列索引超出范围:句柄 0x2f65e0
我有一个名为 Quotes 的表,其中包含 _id、auth_name、quote、category 列,我的查询如下所示
return qmDB.rawQuery("SELECT _id as _id, auth_name, quote, category FROM Quotes",
new String[]{"WHERE auth_name = 'Robert Anton Wilson'"});
有人知道解决此问题的建议吗?我最初的计划是使用基本查询语句,但 _id 列有问题,建议我采用这种方法。
I am trying to use a rawQuery with a simpleCursorAdapter to display to a listview, but it keeps throwing me an error
04-29 13:36:36.453: ERROR/AndroidRuntime(29539): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.QuoteMachine/com.QuoteMachine.Quote}: android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x2f65e0
I have a table called Quotes with columns _id, auth_name, quote, category and my query looks as follows
return qmDB.rawQuery("SELECT _id as _id, auth_name, quote, category FROM Quotes",
new String[]{"WHERE auth_name = 'Robert Anton Wilson'"});
Might anyone know of a suggestion to fix this problem?My original plan was to use a basic query statement, but there was a problem with column _id and it was suggested I go with this approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用 rawQuery() 错误。第二个变量用于参数,而不是用于 WHERE 子句。使用它来代替:
Your using the rawQuery() wrong. The second variable is for the arguments, not for the WHERE clause. Use that instead:
可能与 quote() 函数混淆?您的其中一栏称为“报价”。
http://www.sqlite.org/lang_corefunc.html
http://www.sqlite.org/lang_keywords.html
Possibly confusion with the quote() function? One of your columns is called 'quote'.
http://www.sqlite.org/lang_corefunc.html
http://www.sqlite.org/lang_keywords.html