androidsqlcipher-android

My function always return false SqlCipher


I use database to encrytp/decypt sqlcipher. Now I write function witch check if this card if exist in table Card. When I debug my method always return false.

public boolean checkIfExistCard(String numberCard, String expirationDate) {
    net.sqlcipher.database.SQLiteDatabase db = this.getReadableDatabase(DATABASE_PASSWORD);
    Cursor cursor = db.query(CardColumn.CardEntry.TABLE_CARD,
            new String[]{CardColumn.CardEntry.CARD_NUMBER, CardColumn.CardEntry.CARD_EXPIRATION_DATA},
            CardColumn.CardEntry.CARD_NAME + " = ? and " + CardColumn.CardEntry.CARD_EXPIRATION_DATA + " = ?",
            new String[]{numberCard, expirationDate},
            null, null, null, null);

    if (cursor != null) {
        if (cursor.getCount() > 0) {
            cursor.close();
            db.close();
            return true;
        }
        cursor.close();
        db.close();
    }
    return false;
}

Solution

  • I solved my problem :) I make mistake in Cursor should be CardColumn.CardEntry.CARD_NUMBER instead CardColumn.CardEntry.CARD_NAME It's works :)

        Cursor cursor = db.query(CardColumn.CardEntry.TABLE_CARD,
                new String[]{CardColumn.CardEntry.CARD_NUMBER, CardColumn.CardEntry.CARD_EXPIRATION_DATA},
                CardColumn.CardEntry.CARD_NUMBER + " = ? and " + CardColumn.CardEntry.CARD_EXPIRATION_DATA + " = ?",
                new String[]{numberCard, expirationDate},
                null, null, null, null);