I am trying to get a list of table names from an SQLite database. I manage to get this, but I also get temporary table names like 'android_metadata' and 'sqlite_sequence'. I want to exclude these 2.
However, I can't get it to work right.
SQLiteDatabase database =
getBaseContext().openOrCreateDatabase("vocabularyDatabase",
MODE_PRIVATE, null);
Cursor c = database.rawQuery( "SELECT name FROM sqlite_master
WHERE (type = 'table') AND (name NOT LIKE 'sqlite_sequence' OR
name NOT LIKE 'android_metadata') ",
null);
if (c.moveToFirst()){
while (!c.isAfterLast() ){
listOfWords.add(c.getString(c.getColumnIndex("name"))
);
c.moveToNext();
}
}
Assume that the current row is for
android_metadata
. The expressionname NOT LIKE 'android_metadata'
will be false, but the expressionname NOT LIKE 'sqlite_sequence'
will be true. So the WHERE clause reduces totrue AND (true OR false)
, which is true.You need to replace the
OR
withAND
:If you really want to use
OR
, you have to apply DeMorgan's laws and negate the entire condition:Alternatively, simply use IN with a list: