Reputation: 11728
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:
Upvotes: 15
Views: 8417
Reputation: 31
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());
}
Upvotes: 3
Reputation: 1757
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.
Upvotes: 11
Reputation: 8163
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.
Upvotes: 7
Reputation: 5087
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.]
Upvotes: 0