使用 Anko SQLite,检查数据库是否存在的最佳方法是什么?

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

我正在使用 Kotlin 开发一个 Android 应用程序,作为启动过程的一部分,我想确定 SQL Lite 数据库是否已经存在(意味着用户是不是新用户)

到目前为止,我一直无法确定使用来自 Anko SQLLite helpers 的 ManagedSQLiteOpenHelper helper 基础设施的最佳方法是什么。

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

我不一定要查询一个不存在的table从而抛出异常作为一种逻辑控制,有没有更好的方法?

回答了我自己的问题。

这个有效

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

你可以使用这个:

db.use{
  select("youtTableName").whereSimple("fieldId = ?",id).exec {
      //your code here
  }
}