0

This is a little doubt that i know it's gonna be interesting to share.

Searching about the best way to check if sqlite database exists, i saw that sometimes android send that the database don't exists because it cannot be open.

Source SQLITE

and some user suggest that the best option it's to check if a specific table exists.

Source SQLITE TABLE

My question is which method it's more secure when someone wants to check if the database already exists or not.

Thanks!, and sorry if some words aren't well written.

Luis Cardoza Bird
  • 1,265
  • 4
  • 24
  • 43
  • 1
    It depends on what you want to do, if you want to create a new sqlite database you check if there is already a database. If you want to insert a new table in a existing database then you will check if the table exists. – HB. Aug 06 '17 at 17:43
  • 1
    @H.Brooks I know that the best way it's to check if there is already a database, but sometimes that check goes with a ** database not created ** and as i say in the question, some users says that it's better to check if the table exists rather than check if the database exists. – Luis Cardoza Bird Aug 06 '17 at 17:51
  • So what exactly is your question then? – HB. Aug 06 '17 at 17:53
  • Which method it's more reliable for sqlite database. check if table exists, or check if the whole database exists. – Luis Cardoza Bird Aug 06 '17 at 17:55
  • Ok well I have already answered that in my first comment. – HB. Aug 06 '17 at 17:57
  • 1
    Attempting to check for the existence of a table requires the database to be opened (i.e. getReadableDatabase or getWriteableDatabase attempts to open the Database), if it cannot be opened then you'd basically get the same issue. What you are probably looking at is perhaps implementing `DatabaseErrorHandler` e.g. add `implements DatabaseErrorHandler` to the SQLiteOpenHelper subclass along with coding the `onCorruption` method as is appropriate. – MikeT Aug 06 '17 at 18:52

0 Answers0