I am working with SQLite and I think I have a problem getting table ID, my table stores book categories, their images details here is a graphical representation of my table
| mSubCategory_id | mCategory_id_FK | mSubCategory_description | mSubCategory_image|
my problem is getting the ID field values, below is a query am using to match books in my sub Cateogory table with a certain Category, its working perfectly but I cannot seem to access value of id, I am getting the same value for id
and mSubCateogory_id
which in the actual sense is the value for mSubCateogory_id
and not id
below is the query am using:
String sQuery = " SELECT "+mCategory_id+", "+mCategory_id_FK+", "+Constant.SUB_DESCRIPTION+
", "+mSubCategory_image+" FROM "+CATEGORY_TABLE+
" INNER JOIN "+SUB_CATEGORY_TABLE+" ON "+mCategory_id +" = " +mCategory_id_FK
+ " WHERE "+mCategory_id +" = ?";
String[] args = new String[1];
args[0] = String.valueOf(mtargetID);
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(sQuery, args);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
ExpandableCategoryItem mCateogory= new ExpandableCategoryItem();
//I am getting the same value here whether I use
//getString(0) or getString(1)
mCateogory.setId(Integer.parseInt(cursor.getString(1)));
mCateogory.setmDescription(cursor.getString(2));
mCateogory.setmCategoryImgPath(cursor.getString(3));
mCategoryImgPost.add(mCateogoryPost);
} while (cursor.moveToNext());
Aucun commentaire:
Enregistrer un commentaire