I am trying to get result from two tables and i'm using IN query for this. My problem is that i'm not getting any value in cursor even i have correct data. What can be wrong with this???
public String getContactNameByNumber(String number) {
//String filter = MySQLiteHelper.COLUMN_CNT_NICK_NAME + " LIKE '%" + number + "%'";
number = number.substring(number.length() % 10);
String sql = "SELECT "
+ MySQLiteHelper.COLUMN_CNT_NICK_NAME
+ " FROM "
+ MySQLiteHelper.TABLE_NAME_CONTACT
+ " WHERE "
+ MySQLiteHelper.COLUMN_CNT_CONTACT_ID
+ " IN ( SELECT "
+ MySQLiteHelper.COLUMN_PHN_CONTACT_ID
+ " FROM "
+ MySQLiteHelper.TABLE_NAME_PHONE
+ " WHERE "
+ MySQLiteHelper.COLUMN_PHN_NUMBER
+ " = ?"
+ " ) ";
Log.e("getContactNameByNumber", sql);
Cursor cursor = database.rawQuery(sql, new String[] { number +"%" });
while (cursor.moveToNext()) {
Log.e("getContactNameByNumber", "1");
return cursor.getString(cursor.getColumnIndex(MySQLiteHelper.COLUMN_CNT_NICK_NAME));
}
// make sure to close the cursor
cursor.close();
return null;
}
0 comments:
Post a Comment