My function always return false SqlCipher

36 views Asked by At

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;
}
3

There are 3 answers

0
Ewelina Maj On BEST ANSWER

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);
0
Aravindraj On
 public boolean checkIfExistCard(String numberCard, String expirationDate) {
    boolean isAvailable=false;
    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) {

            isAvailable=true;
        }
        else {

            isAvailable=false;
        }
        cursor.close();
        db.close();
    }
    return isAvailable;
}
0
just On

Maybe you missed a space in your query. In this line:

CardColumn.CardEntry.CARD_NAME + " = ? and " + CardColumn.CardEntry.CARD_EXPIRATION_DATA + " = ?",

After the last ? sign put a space before the " sign.