Android SQLite 错误“请求带有表名的列名”
运行以下形式的 sql 查询后:
SELECT table_name.column_name FROM table_name,table_name2,etc... WHERE condition1,condition2,etc...,
我收到以下错误,该错误不会关闭我的程序:
请求列名与表名--table_name.column_name
google 搜索此错误短语,我找到了 android.database.sqlite.SQLiteCursor line 314
第 314 行上方的几行有一条注释,指出此代码是对 bug 903852 的响应。但我似乎无法在 google 上找到这个 bug。
所以这是一个由两部分组成的问题:
- 列名是否错误 SQL 中表的名称? (我当时 印象中这是一个 最佳实践)
- 我如何找到 Android 错误报告 903852 以便我 能明白问题是什么吗? (谷歌搜索 Android bug 903852 并没有 工作)
After running an sql query of the form:
SELECT table_name.column_name FROM table_name,table_name2,etc... WHERE condition1,condition2,etc...,
I get the following error, which does not shut down my program:
requesting column name with table name -- table_name.column_name
A google search for this error phrase led me to android.database.sqlite.SQLiteCursor line 314
A few lines above line 314 there is a comment that this code is a response to bug 903852. But I can't seem to find this bug on google.
So this is a two part question:
- Is it wrong to name the column
name with the table in SQL? (I was
under the impression that this was a
best practice) - How do I find
Android bug report 903852 so that I
can understand what the issue is?
(googling Android bug 903852 doesn't
work)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
就我而言,当我使用时问题得到了解决
,后来在我的 CursorAdapter 中,在字符串数组中仅将其引用为column_name_alt。
希望这有帮助。
In my case, the problem was solved when I used
and later, in my
CursorAdapter
, referred to it in the string array only ascolumn_name_alt
.Hope this helps.
因此,我在创建一个将传递给
SimpleCursorAdapter
的Cursor
时遇到了这个问题。事实证明,虽然可以在“查询”列前面添加 String[] 前缀,但随后传递给SimpleCursorAdapter
构造函数不需要需要添加前缀才能使适配器正确映射结果集。So I ran into this problem while creating a
Cursor
that would be passed to aSimpleCursorAdapter
. Turns out that while it's OK to prefix your 'query' columns String[], the subsequentString[] from
argument that's passed to theSimpleCursorAdapter
constructor does not need to be prefixed in order for the Adapter to map your result set correctly.几天前我遇到了同样的问题,并使用替代方法解决了该问题。以前我使用以下方法将光标设置为指向该列。
当我将其更改为以下方法后,它对我有用。
I got the same issue few days back and solved the issue using an alternative method. Previously I used the following method to set the cursor to point the column.
After I changed this into the following method it worked for me.
我发现最佳实践是将所有表名称和条件值用单引号引起来! [即使查询在我的独立 sqlite 管理器中工作,我也会在 android 中收到“未知列名称”错误。]
I have found that the best practice is to surround all table names and condition values with single quotes! [I was getting 'unknown column name' errors in android even when the query worked in my stand-alone sqlite manager.]