I have a table into which I have no problem inserting data. But when I try to delete a row, it returns 0 count. It does not delete the row. What is wrong with my sql statement?
Table creation
final String SQL_CREATE_DOG_TABLE = "CREATE TABLE " + DogContract.DogEntry.TABLE_NAME + " ( " +
//identification
DogContract.DogEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
DogContract.DogEntry.COLUMN_DOG_ID + " INTEGER NOT NULL, " +
DogContract.DogEntry.COLUMN_DOG_TYPE + " TEXT NOT NULL, " +
DogContract.DogEntry.COLUMN_OWNER_ID + " INTEGER, " +
//position
DogContract.DogEntry.COLUMN_BIRTH_TIME + " BIGINT NOT NULL, " +
DogContract.DogEntry.COLUMN_DEATH_TIME + " BIGINT NOT NULL, " +
//contact info
DogContract.DogEntry.COLUMN_CONTACT_FIRSTNAME + " TEXT, " +
DogContract.DogEntry.COLUMN_CONTACT_LASTNAME + " TEXT, " +
DogContract.DogEntry.COLUMN_CONTACT_PHONE + " TEXT, " +
//Dog data
DogContract.DogEntry.COLUMN_FOODS + " TEXT, " +
DogContract.DogEntry.COLUMN_TOYS + " TEXT, " +
//address
DogContract.DogEntry.COLUMN_ADDRESS_1 + " TEXT, " +
DogContract.DogEntry.COLUMN_ADDRESS_2 + " TEXT, " +
DogContract.DogEntry.COLUMN_CITY + " TEXT, " +
DogContract.DogEntry.COLUMN_STATE + " TEXT, " +
DogContract.DogEntry.COLUMN_ZIP_CODE + " TEXT" +
");";
sqliteDatabase.execSQL(SQL_CREATE_DOG_TABLE);
Delete query
private int deleteByDogTypeAndId(Uri uri) {
if (null == mOpenHelper) {
mOpenHelper = new DogDBHelper(getContext());
}
final String TABLE_NAME = DogContract.DogEntry.TABLE_NAME;
final String[] selectionArgs = DogContract.DogEntry.getDogTypeAndDogIdFromUri(uri);
final String selection = DogContract.DogEntry.COLUMN_DOG_TYPE + " = ? AND " +
DogContract.DogEntry.COLUMN_DOG_ID + " = ? ";
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
int count = db.delete(TABLE_NAME, selection, selectionArgs);
if (0 < count) {
getContext().getContentResolver().notifyChange(DogContract.DogEntry.CONTENT_URI, null);
}
return count;
}
Some notes. Although I am not showing logging here, I am actually logging the steps. dogType is a String while dogId is a Long. Notice that dogId is different from dbId. dogId is set on the server, whereas dbId is a local db construct.
Aucun commentaire:
Enregistrer un commentaire