我的函数总是 return false SqlCipher
My function always return false SqlCipher
我使用数据库 encrytp/decypt sqlcipher。现在我写函数 检查这张卡是否存在于 table 卡中。当我调试我的方法时,总是 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;
}
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;
}
也许您在查询中遗漏了 space。
在这一行中:
CardColumn.CardEntry.CARD_NAME + " = ? and " + CardColumn.CardEntry.CARD_EXPIRATION_DATA + " = ?",
在最后一个之后? sign 在 " 符号前加上 space。
我解决了我的问题 :) 我弄错了 Cursor 应该是 CardColumn.CardEntry.CARD_NUMBER 而不是 CardColumn.CardEntry.CARD_NAME
有用:)
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);
我使用数据库 encrytp/decypt sqlcipher。现在我写函数 检查这张卡是否存在于 table 卡中。当我调试我的方法时,总是 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;
}
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;
}
也许您在查询中遗漏了 space。 在这一行中:
CardColumn.CardEntry.CARD_NAME + " = ? and " + CardColumn.CardEntry.CARD_EXPIRATION_DATA + " = ?",
在最后一个之后? sign 在 " 符号前加上 space。
我解决了我的问题 :) 我弄错了 Cursor 应该是 CardColumn.CardEntry.CARD_NUMBER 而不是 CardColumn.CardEntry.CARD_NAME 有用:)
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);