Created
August 5, 2012 18:56
-
-
Save nxax/3266683 to your computer and use it in GitHub Desktop.
Check table if exists on SQLite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
hi what is mDatabase declaration?
can you show me how to call this method..
thanks
Hi all.
mDatabase
is the connection to the table database.
Regards
hi what is getReadableDatabase();
thanks.
application/x-sqlite3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good work