本文整理汇总了Scala中android.database.sqlite.SQLiteDatabase类的典型用法代码示例。如果您正苦于以下问题:Scala SQLiteDatabase类的具体用法?Scala SQLiteDatabase怎么用?Scala SQLiteDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SQLiteDatabase类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SlickDatabaseHelper
//设置package包名称以及导入依赖的类
package com.nullpointerbay.dbtest
import android.content.Context
import android.database.sqlite.{SQLiteDatabase, SQLiteOpenHelper}
import com.fortysevendeg.mvessel.AndroidDriver
import slick.driver.SQLiteDriver.api._
import SlickDatabaseHelper._
class SlickDatabaseHelper(context: Context)
extends SQLiteOpenHelper(context, databaseName, null, databaseVersion)
with SlickDatabaseConfig {
val driverName = "com.fortysevendeg.mvessel.AndroidDriver"
lazy val database = {
val sqliteDatabase = getReadableDatabase
AndroidDriver.register()
Database.forURL(
url = "jdbc:sqlite:" + sqliteDatabase.getPath,
driver = driverName)
}
override def onCreate(sqliteDatabase: SQLiteDatabase): Unit = {
todoTable.schema.create.statements foreach sqliteDatabase.execSQL
}
override def onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int): Unit =
throw new IllegalStateException("Can't make an upgrade")
}
object SlickDatabaseHelper {
val databaseName = "slick.db"
val databaseVersion = 1
}
示例2: DBHelper
//设置package包名称以及导入依赖的类
package com.rainm.scanote.db
import android.content.Context
import android.database.sqlite.{SQLiteDatabase, SQLiteOpenHelper}
import com.rainm.scanote.model.SimpleNote
object DBHelper {
val DB_VERSION = 0x1
var DB_NAME = "action_note_db"
def setDbName(dbName: String): Unit = {
DB_NAME = dbName
}
}
class DBHelper(context: Context)
extends SQLiteOpenHelper(context, DBHelper.DB_NAME, null, DBHelper.DB_VERSION) {
override def onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int): Unit = {
//TODO: add upgrade code here.
}
override def onCreate(db: SQLiteDatabase): Unit = {
db.execSQL("CREATE TABLE IF NOT EXISTS " + SimpleNote.TABLE_NAME + SimpleNote.DDL)
}
}