Add missing folder constraints to database query/update commands

This commit is contained in:
cketti 2019-12-13 13:11:51 +01:00
parent a084e8e0db
commit bc97920f70

View file

@ -117,7 +117,14 @@ class K9BackendFolder(
override fun isMessagePresent(messageServerId: String): Boolean { override fun isMessagePresent(messageServerId: String): Boolean {
return database.execute(false) { db -> return database.execute(false) { db ->
val cursor = db.query("messages", arrayOf("id"), "uid = ?", arrayOf(messageServerId), null, null, null) val cursor = db.query(
"messages",
arrayOf("id"),
"folder_id = ? AND uid = ?",
arrayOf(databaseId, messageServerId),
null, null, null
)
cursor.use { cursor.use {
cursor.moveToFirst() cursor.moveToFirst()
} }
@ -137,8 +144,8 @@ class K9BackendFolder(
val cursor = db.query( val cursor = db.query(
"messages", "messages",
arrayOf("deleted", "read", "flagged", "answered", "forwarded", "flags"), arrayOf("deleted", "read", "flagged", "answered", "forwarded", "flags"),
"uid = ?", "folder_id = ? AND uid = ?",
arrayOf(messageServerId), arrayOf(databaseId, messageServerId),
null, null, null) null, null, null)
cursor.use { cursor.use {
@ -177,8 +184,8 @@ class K9BackendFolder(
val flagsColumnValue = database.getString( val flagsColumnValue = database.getString(
table = "messages", table = "messages",
column = "flags", column = "flags",
selection = "uid = ?", selection = "folder_id = ? AND uid = ?",
selectionArgs = *arrayOf(messageServerId) selectionArgs = *arrayOf(databaseId, messageServerId)
) ?: "" ) ?: ""
val flags = flagsColumnValue.split(',').toMutableSet() val flags = flagsColumnValue.split(',').toMutableSet()
@ -193,8 +200,8 @@ class K9BackendFolder(
database.setString( database.setString(
table = "messages", table = "messages",
column = "flags", column = "flags",
selection = "uid = ?", selection = "folder_id = ? AND uid = ?",
selectionArgs = *arrayOf(messageServerId), selectionArgs = *arrayOf(databaseId, messageServerId),
value = serializedFlags value = serializedFlags
) )
} }
@ -336,7 +343,7 @@ class K9BackendFolder(
val contentValues = ContentValues().apply { val contentValues = ContentValues().apply {
put(column, if (value) 1 else 0) put(column, if (value) 1 else 0)
} }
db.update("messages", contentValues, "uid = ?", arrayOf(messageServerId)) db.update("messages", contentValues, "folder_id = ? AND uid = ?", arrayOf(databaseId, messageServerId))
} }
} }