Android SQLite 错误“请求带有表名的列名”

发布于 2024-10-31 04:37:35 字数 754 浏览 0 评论 0原文

运行以下形式的 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。

所以这是一个由两部分组成的问题:

  1. 列名是否错误 SQL 中表的名称? (我当时 印象中这是一个 最佳实践)
  2. 我如何找到 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:

  1. Is it wrong to name the column
    name with the table in SQL? (I was
    under the impression that this was a
    best practice)
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

太阳哥哥 2024-11-07 04:37:35

就我而言,当我使用时问题得到了解决

select table_name.column_name as column_name_alt WHERE ....

,后来在我的 CursorAdapter 中,在字符串数组中仅将其引用为column_name_alt。

希望这有帮助。

In my case, the problem was solved when I used

select table_name.column_name as column_name_alt WHERE ....

and later, in my CursorAdapter, referred to it in the string array only as column_name_alt.

Hope this helps.

孤凫 2024-11-07 04:37:35

因此,我在创建一个将传递给 SimpleCursorAdapterCursor 时遇到了这个问题。事实证明,虽然可以在“查询”列前面添加 String[] 前缀,但随后传递给 SimpleCursorAdapter 构造函数不需要需要添加前缀才能使适配器正确映射结果集。

So I ran into this problem while creating a Cursor that would be passed to a SimpleCursorAdapter. Turns out that while it's OK to prefix your 'query' columns String[], the subsequent String[] from argument that's passed to the SimpleCursorAdapter constructor does not need to be prefixed in order for the Adapter to map your result set correctly.

将军与妓 2024-11-07 04:37:35

几天前我遇到了同样的问题,并使用替代方法解决了该问题。以前我使用以下方法将光标设置为指向该列。

String sqlStatement = "SELECT supplierid,suppliercode,suppliername FROM supplierinfo WHERE suppliername  LIKE '%"+query+"%' ";
        cursor = db.rawQuery(sqlStatement,null);
        if (cursor != null && cursor.getCount() > 0){
            if (cursor.moveToFirst()){
                do {
                    int supplierId = cursor.getInt( 0);
                    String supplierCode = cursor.getString(cursor.getColumnIndex( "suppliercode" )) != null ? cursor.getString( cursor.getColumnIndex( "suppliercode" ) ) : "";
                    String supplierName = cursor.getString(cursor.getColumnIndex( "suppliername" )) != null ? cursor.getString( cursor.getColumnIndex( "suppliername" ) ) : "";
                    supplierInfo =  new SupplierInfo();
                    supplierInfo.setSupplierID( supplierId );
                    supplierInfo.setSupplierCode( supplierCode );
                    supplierInfo.setSupplierName( supplierName );
                    supplierInfoList.add(supplierInfo);
                } while (cursor.moveToNext());
            }

当我将其更改为以下方法后,它对我有用。

String sqlStatement = "SELECT supplierid,suppliercode,suppliername FROM supplierinfo WHERE suppliername  LIKE '%"+query+"%' ";
        cursor = db.rawQuery(sqlStatement,null);
        if (cursor != null && cursor.getCount() > 0){
            if (cursor.moveToFirst()){
                do {
                    int supplierId = cursor.getInt( 0);
                    String supplierCode = cursor.getString(1) != null ? cursor.getString( 1 ) : "";
                    String supplierName = cursor.getString(2) != null ? cursor.getString( 2 ) : "";
                    supplierInfo =  new SupplierInfo();
                    supplierInfo.setSupplierID( supplierId );
                    supplierInfo.setSupplierCode( supplierCode );
                    supplierInfo.setSupplierName( supplierName );
                    supplierInfoList.add(supplierInfo);
                } while (cursor.moveToNext());
            }

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.

String sqlStatement = "SELECT supplierid,suppliercode,suppliername FROM supplierinfo WHERE suppliername  LIKE '%"+query+"%' ";
        cursor = db.rawQuery(sqlStatement,null);
        if (cursor != null && cursor.getCount() > 0){
            if (cursor.moveToFirst()){
                do {
                    int supplierId = cursor.getInt( 0);
                    String supplierCode = cursor.getString(cursor.getColumnIndex( "suppliercode" )) != null ? cursor.getString( cursor.getColumnIndex( "suppliercode" ) ) : "";
                    String supplierName = cursor.getString(cursor.getColumnIndex( "suppliername" )) != null ? cursor.getString( cursor.getColumnIndex( "suppliername" ) ) : "";
                    supplierInfo =  new SupplierInfo();
                    supplierInfo.setSupplierID( supplierId );
                    supplierInfo.setSupplierCode( supplierCode );
                    supplierInfo.setSupplierName( supplierName );
                    supplierInfoList.add(supplierInfo);
                } while (cursor.moveToNext());
            }

After I changed this into the following method it worked for me.

String sqlStatement = "SELECT supplierid,suppliercode,suppliername FROM supplierinfo WHERE suppliername  LIKE '%"+query+"%' ";
        cursor = db.rawQuery(sqlStatement,null);
        if (cursor != null && cursor.getCount() > 0){
            if (cursor.moveToFirst()){
                do {
                    int supplierId = cursor.getInt( 0);
                    String supplierCode = cursor.getString(1) != null ? cursor.getString( 1 ) : "";
                    String supplierName = cursor.getString(2) != null ? cursor.getString( 2 ) : "";
                    supplierInfo =  new SupplierInfo();
                    supplierInfo.setSupplierID( supplierId );
                    supplierInfo.setSupplierCode( supplierCode );
                    supplierInfo.setSupplierName( supplierName );
                    supplierInfoList.add(supplierInfo);
                } while (cursor.moveToNext());
            }
苦笑流年记忆 2024-11-07 04:37:35

我发现最佳实践是将所有表名称和条件值用单引号引起来! [即使查询在我的独立 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.]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文