0% found this document useful (0 votes)
63 views

Mysql Helper

This document defines a class called MySqlHelper that is used to create and manage a SQLite database in an Android application. The class extends the ManagedSQLiteOpenHelper and overrides methods like onCreate to define the database schema, and onUpgrade to handle schema changes. A companion object is used to implement the singleton pattern so that there is only one instance of the database helper.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Mysql Helper

This document defines a class called MySqlHelper that is used to create and manage a SQLite database in an Android application. The class extends the ManagedSQLiteOpenHelper and overrides methods like onCreate to define the database schema, and onUpgrade to handle schema changes. A companion object is used to implement the singleton pattern so that there is only one instance of the database helper.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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)

You might also like