Skip to content

Instantly share code, notes, and snippets.

@nxax
Created August 5, 2012 18:56
Show Gist options
  • Save nxax/3266683 to your computer and use it in GitHub Desktop.
Save nxax/3266683 to your computer and use it in GitHub Desktop.
Check table if exists on SQLite
// Check table if exists on SQLite
// http://stackoverflow.com/questions/3058909/how-does-one-check-if-a-table-exists-in-an-android-sqlite-database
//
public boolean isTableExists(String tableName, boolean openDb) {
if(openDb) {
if(mDatabase == null || !mDatabase.isOpen()) {
mDatabase = getReadableDatabase();
}
if(!mDatabase.isReadOnly()) {
mDatabase.close();
mDatabase = getReadableDatabase();
}
}
Cursor cursor = mDatabase.rawQuery("select DISTINCT tbl_name from sqlite_master where tbl_name = '"+tableName+"'", null);
if(cursor!=null) {
if(cursor.getCount()>0) {
cursor.close();
return true;
}
cursor.close();
}
return false;
}
@meldouh
Copy link

meldouh commented Jul 12, 2018

hi what is getReadableDatabase();
thanks.

@wjkhappy14
Copy link

application/x-sqlite3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment