1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| package com.fuban.user.db
|
| import android.content.Context
| import android.database.sqlite.SQLiteDatabase
| import org.jetbrains.anko.db.*
|
| /**
| *
| */
| 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)
|
|