-3

Possible Duplicate:
How can i check to see if my sqlite table has data in it?
Android check if database is empty

Can anybody tell me how to check if sqlite database (in android) is empty or has tables and if it has tables is it empty or has values?

I made a login authentication program using sqlite and I want it to check if there is no users to log in automatically

Community
  • 1
  • 1
MohamedAli
  • 313
  • 1
  • 5
  • 13
  • This is an odd request... Normally you would already have a SQLite database with a table structure, in which case it becomes trivial to check for the presence of records in the table. – Robert Harvey Jun 28 '12 at 21:21
  • to check weather there is an empty table or not , you can use row count of Sqlite – rajpara Jun 28 '12 at 21:30
  • 2
    You have already asked this question here: http://stackoverflow.com/questions/11251901/android-check-if-database-is-empty – Yaqub Ahmad Jun 29 '12 at 03:59

1 Answers1

1

You can make a simple method checking if database alredy exists.

private boolean checkDataBase(){

    SQLiteDatabase checkDB = null;

    try{
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
    } catch(SQLiteException e){ 
        //database doesn't exist yet
    }

    if(checkDB != null){
        checkDB.close();
    }

    return checkDB != null ? true : false;
}