Search code examples
sqlitekotlinanko

Using Anko SQLLite, what is the best way to check if a database exists?


I'm working on an Android app using Kotlin and as part of the startup process, I would like to determine whether or not a SQL Lite database already exists (meaning the user is not a new user)

I've so far been unable to determine what is the best way to do this using the ManagedSQLiteOpenHelper helper infrastructure from the Anko SQLLite helpers.

        database.use {
        // what should go in here???   
        }

I don't necessarily want to query a non existent table and thus throw an exception and use that as a form of logic control, is there a better way?


Solution

  • Answered my own question.

    This works

    this.query("sqlite_master", arrayOf("name"), "name='userInfo' AND type='table'", null,null,null, null,null).count