I have created a DB and yet I fail to select a column from it.
android.database.sqlite.SQLiteException: no such column: KEY_PHONE (code 1): , while compiling: SELECT id FROM BLOCKED_PHONES_TABLE WHERE KEY_PHONE = ? AND KEY_IS_BLOCKED = ?
but I did construct such column
my code:
@Override
public void onCreate(SQLiteDatabase db) {
// SQL statement to create book table
String CREATE_BLOCKED_PHONES_TABLE = "CREATE TABLE "
+ BLOCKED_PHONES_TABLE + " ( "
+ KEY_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_PHONE+" TEXT, "
+ KEY_IS_BLOCKED+" BIT )";
db.execSQL(CREATE_BLOCKED_PHONES_TABLE);
}
public Phone getItem(String phone) {
// 1. get reference to readable DB
SQLiteDatabase db = this.getReadableDatabase();
Phone result = null;
Cursor cursor = getReadableDatabase().query(BLOCKED_PHONES_TABLE,
new String[] { KEY_ID }, ""+KEY_PHONE+" = ? AND "+KEY_IS_BLOCKED+" = ?",
new String[] { phone, "1" }, null, null, null);
// 3. if we got results get the first one
if (cursor != null) {
result.id = (cursor.getInt(1));
result.phone = phone;
result.isBlocked = false;
}
return result;
}
what am i missing?
Aucun commentaire:
Enregistrer un commentaire