From f417389a7a598fc607e5fc81825b3cf52d33766f Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 6 Jun 2019 00:39:24 -0700 Subject: [PATCH] Fix magisk database code in app --- .../magisk/data/database/SettingsDao.kt | 5 ++-- .../magisk/data/database/StringDao.kt | 4 +-- .../data/database/base/MagiskQueryBuilder.kt | 30 ++++++------------- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/SettingsDao.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/SettingsDao.kt index 22cb370e2..a394dd5e9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/SettingsDao.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/SettingsDao.kt @@ -10,11 +10,12 @@ class SettingsDao : BaseDao() { condition { equals("key", key) } }.ignoreElement() - fun put(key: String, value: Int) = query { - values(key to value.toString()) + fun put(key: String, value: Int) = query { + values("key" to key, "value" to value) }.ignoreElement() fun fetch(key: String, default: Int = -1) = query { diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt index de4e38425..ad9cc9f8a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/base/MagiskQueryBuilder.kt @@ -32,11 +32,7 @@ class Delete : MagiskQueryBuilder { } override fun toString(): String { - return StringBuilder() - .appendln(requestType) - .appendln(table) - .appendln(condition) - .toString() + return listOf(requestType, table, condition).joinToString(" ") } } @@ -65,13 +61,7 @@ class Select : MagiskQueryBuilder { } override fun toString(): String { - return StringBuilder() - .appendln(requestType) - .appendln(table) - .appendln(condition) - .appendln(orderField) - .toString() - .replace("\n", " ") + return listOf(requestType, table, condition, orderField).joinToString(" ") } } @@ -84,23 +74,21 @@ open class Insert : MagiskQueryBuilder { override lateinit var table: String private val keys get() = _values.keys.joinToString(",") - private val values get() = _values.values.joinToString(",") { "\"$it\"" } - private var _values: Map = mapOf() + private val values get() = _values.values.joinToString(",") { + if (it is String) "\"$it\"" else it.toString() + } + private var _values: Map = mapOf() - fun values(vararg pairs: Pair) { + fun values(vararg pairs: Pair) { _values = pairs.toMap() } - fun values(values: Map) { + fun values(values: Map) { _values = values } override fun toString(): String { - return StringBuilder() - .appendln(requestType) - .appendln(table) - .appendln("($keys) VALUES($values)") - .toString() + return listOf(requestType, table, "($keys) VALUES($values)").joinToString(" ") } }