My function always return false SqlCipher


#1

hi,
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;
}

#2

Hi @Magdalena_Dziesinska

It looks like you might be trying to check the CARD_NAME column against the numberCard here:

I think you meant

CardColumn.CardEntry.CARD_NUMBER + " = ?

Let me know if this resolves the issue for you.

Cheers,
Micah


#3

Thank you so much for help. I did’t notice :slight_smile:Works.


#4

@Magdalena_Dziesinska

Excellent! Glad I could help.

Cheers,
Micah