sqia09
09/21/2017, 9:38 AMclass DbHelper(ctx: Context) : ManagedSQLiteOpenHelper( ctx, DB_NAME, null, DB_VERSION ){
override fun onCreate(db: SQLiteDatabase?) {
db?.createTable(NodeTable.TABLE_NAME, true,
NodeTable.TABLE_ID to INTEGER + PRIMARY_KEY,
NodeTable.ROUTE_ID to INTEGER,
NodeTable.SITE_ID to INTEGER,
NodeTable.ACTIVITY_ID to INTEGER,
NodeTable.DEVICE_IMEI to TEXT,
NodeTable.BARCODE to TEXT,
NodeTable.EQUIPMENT_ID to INTEGER,
NodeTable.SCANNED_ON to TEXT,
NodeTable.SCANNED_BY to TEXT)
}
override fun onUpgrade(db: SQLiteDatabase?, p1: Int, p2: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
companion object {
@JvmField
val DB_VERSION = 1
@JvmField
val DB_NAME = "dbScanner"
private var instance: DbHelper? = null
@Synchronized
fun getInstance(ctx: Context): DbHelper {
if (instance == null) {
instance = DbHelper(ctx.applicationContext)
}
return instance!!
}
}
}
val Context.database: DbHelper
get() = DbHelper.getInstance(applicationContext)