package com.igo.user.db
|
|
import android.content.Context
|
import android.database.sqlite.SQLiteDatabase
|
import org.jetbrains.anko.db.INTEGER
|
import org.jetbrains.anko.db.ManagedSQLiteOpenHelper
|
import org.jetbrains.anko.db.PRIMARY_KEY
|
import org.jetbrains.anko.db.TEXT
|
import org.jetbrains.anko.db.createTable
|
|
/**
|
*
|
*/
|
class DBHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "OK_db") {
|
companion object {
|
const val HISTORY_TABLE_NAME = "history_table"
|
private var instance: DBHelper? = null
|
@Synchronized
|
fun getInstance(ctx: Context): DBHelper {
|
if (instance == null) {
|
instance = DBHelper(ctx.applicationContext)
|
}
|
return instance!!
|
}
|
}
|
|
override fun onCreate(db: SQLiteDatabase?) {
|
db?.createTable(
|
HISTORY_TABLE_NAME, true, "id" to INTEGER + PRIMARY_KEY ,
|
"name" to TEXT,
|
"lat" to TEXT,
|
"lng" to TEXT,
|
"address" to TEXT,
|
"district" to TEXT,
|
"code" to TEXT,
|
"city" to TEXT,
|
"time" to TEXT
|
)
|
}
|
|
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
|
|
}
|
}
|
|
val Context.database: DBHelper
|
get() = DBHelper.getInstance(applicationContext)
|