package nogueig.gmail.com.rallytotemmobile.
db
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import org.jetbrains.anko.db.*
///https://antonioleiva.com/databases-anko-kotlin/
class MySqlHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "rally_db") {
companion object {
private var instance: MySqlHelper? = null
@Synchronized
fun getInstance(ctx: Context): MySqlHelper {
if (instance == null) {
instance = MySqlHelper(ctx.applicationContext)
}
return instance!!
}
}
override fun onCreate(db: SQLiteDatabase) {
db.createTable("dadosRally", true,
"_id" to INTEGER + PRIMARY_KEY + AUTOINCREMENT,
"competidor" to TEXT,
"competicao" to TEXT,
"time" to TEXT)
}
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
}
// Access property for Context
val Context.database: MySqlHelper
get() = MySqlHelper.getInstance(applicationContext)