Skip to content

Commit e742585

Browse files
committed
Fix adding new properties to lists with special characters
1 parent 4810d08 commit e742585

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

collect_app/src/main/java/org/odk/collect/android/database/entities/DatabaseEntitiesRepository.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
6565
entities.forEach { entity ->
6666
val existing = if (listExists) {
6767
query(
68-
list,
68+
"\"$list\"",
6969
"${EntitiesTable.COLUMN_ID} = ?",
7070
arrayOf(entity.id)
7171
).first { mapCursorRowToEntity(it, 0) }
@@ -92,7 +92,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
9292
}
9393

9494
update(
95-
list,
95+
"\"$list\"",
9696
contentValues,
9797
"${EntitiesTable.COLUMN_ID} = ?",
9898
arrayOf(entity.id)
@@ -390,7 +390,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep
390390
missingColumns.forEach {
391391
execSQL(
392392
"""
393-
ALTER TABLE $list ADD "$it" text NOT NULL DEFAULT "";
393+
ALTER TABLE "$list" ADD "$it" text NOT NULL DEFAULT "";
394394
""".trimIndent()
395395
)
396396
}

collect_app/src/test/java/org/odk/collect/android/entities/EntitiesRepositoryTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,31 @@ abstract class EntitiesRepositoryTest {
162162
assertThat(wines[0].properties, contains("window" to "2019-2038", "score" to "92"))
163163
}
164164

165+
@Test
166+
fun `#save adds new properties for lists with dashes`() {
167+
val repository = buildSubject()
168+
169+
val wine = Entity.New(
170+
"1",
171+
"Léoville Barton 2008",
172+
properties = listOf("window" to "2019-2038"),
173+
version = 1
174+
)
175+
repository.save("favourite-wines", wine)
176+
177+
val updatedWine = Entity.New(
178+
wine.id,
179+
"Léoville Barton 2008",
180+
properties = listOf("score" to "92"),
181+
version = 2
182+
)
183+
repository.save("favourite-wines", updatedWine)
184+
185+
val wines = repository.getEntities("favourite-wines")
186+
assertThat(wines.size, equalTo(1))
187+
assertThat(wines[0].properties, contains("window" to "2019-2038", "score" to "92"))
188+
}
189+
165190
@Test
166191
fun `#save adds new properties to existing entities`() {
167192
val repository = buildSubject()

0 commit comments

Comments
 (0)