mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 21:45:27 +00:00
Fix magisk database code in app
This commit is contained in:
parent
662a5c8ea6
commit
f417389a7a
@ -10,11 +10,12 @@ class SettingsDao : BaseDao() {
|
|||||||
condition { equals("key", key) }
|
condition { equals("key", key) }
|
||||||
}.ignoreElement()
|
}.ignoreElement()
|
||||||
|
|
||||||
fun put(key: String, value: Int) = query<Insert> {
|
fun put(key: String, value: Int) = query<Replace> {
|
||||||
values(key to value.toString())
|
values("key" to key, "value" to value)
|
||||||
}.ignoreElement()
|
}.ignoreElement()
|
||||||
|
|
||||||
fun fetch(key: String, default: Int = -1) = query<Select> {
|
fun fetch(key: String, default: Int = -1) = query<Select> {
|
||||||
|
fields("value")
|
||||||
condition { equals("key", key) }
|
condition { equals("key", key) }
|
||||||
}.map { it.firstOrNull()?.values?.firstOrNull()?.toIntOrNull() ?: default }
|
}.map { it.firstOrNull()?.values?.firstOrNull()?.toIntOrNull() ?: default }
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ class StringDao : BaseDao() {
|
|||||||
condition { equals("key", key) }
|
condition { equals("key", key) }
|
||||||
}.ignoreElement()
|
}.ignoreElement()
|
||||||
|
|
||||||
fun put(key: String, value: String) = query<Insert> {
|
fun put(key: String, value: String) = query<Replace> {
|
||||||
values(key to value)
|
values("key" to key, "value" to value)
|
||||||
}.ignoreElement()
|
}.ignoreElement()
|
||||||
|
|
||||||
fun fetch(key: String, default: String = "") = query<Select> {
|
fun fetch(key: String, default: String = "") = query<Select> {
|
||||||
|
@ -32,11 +32,7 @@ class Delete : MagiskQueryBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return StringBuilder()
|
return listOf(requestType, table, condition).joinToString(" ")
|
||||||
.appendln(requestType)
|
|
||||||
.appendln(table)
|
|
||||||
.appendln(condition)
|
|
||||||
.toString()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,13 +61,7 @@ class Select : MagiskQueryBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return StringBuilder()
|
return listOf(requestType, table, condition, orderField).joinToString(" ")
|
||||||
.appendln(requestType)
|
|
||||||
.appendln(table)
|
|
||||||
.appendln(condition)
|
|
||||||
.appendln(orderField)
|
|
||||||
.toString()
|
|
||||||
.replace("\n", " ")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,23 +74,21 @@ open class Insert : MagiskQueryBuilder {
|
|||||||
override lateinit var table: String
|
override lateinit var table: String
|
||||||
|
|
||||||
private val keys get() = _values.keys.joinToString(",")
|
private val keys get() = _values.keys.joinToString(",")
|
||||||
private val values get() = _values.values.joinToString(",") { "\"$it\"" }
|
private val values get() = _values.values.joinToString(",") {
|
||||||
private var _values: Map<String, String> = mapOf()
|
if (it is String) "\"$it\"" else it.toString()
|
||||||
|
}
|
||||||
|
private var _values: Map<String, Any> = mapOf()
|
||||||
|
|
||||||
fun values(vararg pairs: Pair<String, String>) {
|
fun values(vararg pairs: Pair<String, Any>) {
|
||||||
_values = pairs.toMap()
|
_values = pairs.toMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun values(values: Map<String, String>) {
|
fun values(values: Map<String, Any>) {
|
||||||
_values = values
|
_values = values
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return StringBuilder()
|
return listOf(requestType, table, "($keys) VALUES($values)").joinToString(" ")
|
||||||
.appendln(requestType)
|
|
||||||
.appendln(table)
|
|
||||||
.appendln("($keys) VALUES($values)")
|
|
||||||
.toString()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user