1- package com.simplemobiletools.notes.databases
1+ package com.simplemobiletools.notes.helpers
22
33import android.content.ContentValues
44import android.content.Context
@@ -8,11 +8,10 @@ import android.database.sqlite.SQLiteOpenHelper
88import com.simplemobiletools.commons.extensions.getIntValue
99import com.simplemobiletools.commons.extensions.getStringValue
1010import com.simplemobiletools.notes.R
11- import com.simplemobiletools.notes.helpers.TYPE_NOTE
1211import com.simplemobiletools.notes.models.Note
1312import java.util.*
1413
15- class DBHelper private constructor(private val mContext : Context ) : SQLiteOpenHelper(mContext, DBHelper . DB_NAME , null , DBHelper . DB_VERSION ) {
14+ class DBHelper private constructor(private val mContext : Context ) : SQLiteOpenHelper(mContext, DB_NAME , null , DB_VERSION ) {
1615 private val mDb: SQLiteDatabase = writableDatabase
1716
1817 companion object {
@@ -30,16 +29,16 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
3029 }
3130
3231 override fun onCreate (db : SQLiteDatabase ) {
33- db.execSQL(" CREATE TABLE $TABLE_NAME ($COL_ID INTEGER PRIMARY KEY, $COL_TITLE TEXT UNIQUE, $COL_VALUE TEXT, $COL_TYPE INTEGER DEFAULT 0, $COL_PATH TEXT)" )
32+ db.execSQL(" CREATE TABLE ${ TABLE_NAME } (${ COL_ID } INTEGER PRIMARY KEY, ${ COL_TITLE } TEXT UNIQUE, ${ COL_VALUE } TEXT, ${ COL_TYPE } INTEGER DEFAULT 0, ${ COL_PATH } TEXT)" )
3433 insertFirstNote(db)
3534 }
3635
3736 override fun onUpgrade (db : SQLiteDatabase , oldVersion : Int , newVersion : Int ) {
3837 if (oldVersion < 2 )
39- db.execSQL(" ALTER TABLE $TABLE_NAME ADD COLUMN $COL_TYPE INTEGER DEFAULT 0" )
38+ db.execSQL(" ALTER TABLE ${ TABLE_NAME } ADD COLUMN ${ COL_TYPE } INTEGER DEFAULT 0" )
4039
4140 if (oldVersion < 3 )
42- db.execSQL(" ALTER TABLE $TABLE_NAME ADD COLUMN $COL_PATH TEXT" )
41+ db.execSQL(" ALTER TABLE ${ TABLE_NAME } ADD COLUMN ${ COL_PATH } TEXT" )
4342 }
4443
4544 private fun insertFirstNote (db : SQLiteDatabase ) {
@@ -67,12 +66,12 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
6766 }
6867
6968 fun deleteNote (id : Int ) {
70- mDb.delete(TABLE_NAME , " $COL_ID = $id " , null )
69+ mDb.delete(TABLE_NAME , " ${ COL_ID } = $id " , null )
7170 }
7271
7372 fun doesTitleExist (title : String ): Boolean {
7473 val cols = arrayOf(COL_ID )
75- val selection = " $COL_TITLE = ?"
74+ val selection = " ${ COL_TITLE } = ?"
7675 val selectionArgs = arrayOf(title)
7776 var cursor: Cursor ? = null
7877 try {
@@ -88,7 +87,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
8887 val cols = arrayOf(COL_ID , COL_TITLE , COL_VALUE , COL_TYPE )
8988 var cursor: Cursor ? = null
9089 try {
91- cursor = mDb.query(TABLE_NAME , cols, null , null , null , null , " $COL_TITLE COLLATE NOCASE ASC" )
90+ cursor = mDb.query(TABLE_NAME , cols, null , null , null , null , " ${ COL_TITLE } COLLATE NOCASE ASC" )
9291 if (cursor?.moveToFirst() == true ) {
9392 do {
9493 val id = cursor.getIntValue(COL_ID )
@@ -108,7 +107,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
108107
109108 fun getNote (id : Int ): Note ? {
110109 val cols = arrayOf(COL_TITLE , COL_VALUE , COL_TYPE )
111- val selection = " $COL_ID = ?"
110+ val selection = " ${ COL_ID } = ?"
112111 val selectionArgs = arrayOf(id.toString())
113112 var note: Note ? = null
114113 var cursor: Cursor ? = null
@@ -128,7 +127,7 @@ class DBHelper private constructor(private val mContext: Context) : SQLiteOpenHe
128127
129128 fun updateNote (note : Note ) {
130129 val values = fillContentValues(note)
131- val selection = " $COL_ID = ?"
130+ val selection = " ${ COL_ID } = ?"
132131 val selectionArgs = arrayOf(note.id.toString())
133132 mDb.update(TABLE_NAME , values, selection, selectionArgs)
134133 }
0 commit comments