Last active
May 19, 2019 14:08
-
-
Save hirauchg/f9e3ce28da660d05dddfc1e72c06cda4 to your computer and use it in GitHub Desktop.
AnkoでSQLiteデータベースを実装する - データベースとテーブルの作成 - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SampleDBHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, DB_SAMPLE, null, DB_VERSION) { | |
companion object { | |
const val DB_SAMPLE = "db_sample" | |
const val DB_VERSION = 1 | |
const val TABLE_SAMPLE = "table_sample" | |
const val CULM_ID = "id" | |
const val CULM_TEXT = "text" | |
const val CULM_NUMBER = "number" | |
private var instance: SampleDBHelper? = null | |
@Synchronized | |
fun getInstance(ctx: Context): SampleDBHelper { | |
if (instance == null) { | |
instance = SampleDBHelper(ctx.getApplicationContext()) | |
} | |
return instance!! | |
} | |
} | |
override fun onCreate(db: SQLiteDatabase) { | |
db.createTable( | |
TABLE_SAMPLE, true, | |
CULM_ID to INTEGER + PRIMARY_KEY + UNIQUE, | |
CULM_TEXT to TEXT, | |
CULM_NUMBER to INTEGER) | |
} | |
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment