From 05e8ea586856b86e79b3d3273bea55a7555170ab Mon Sep 17 00:00:00 2001 From: yaqiao Date: Tue, 13 Dec 2022 13:33:34 +0800 Subject: [PATCH] Fix the behavior of Cursor's columnNames that SELECT the columns those have same name in two tables at JOIN clause --- .../co/touchlab/sqliter/native/NativeCursor.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/native/NativeCursor.kt b/sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/native/NativeCursor.kt index f13a6120..cabbe6b8 100644 --- a/sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/native/NativeCursor.kt +++ b/sqliter-driver/src/nativeCommonMain/kotlin/co/touchlab/sqliter/native/NativeCursor.kt @@ -37,7 +37,18 @@ class NativeCursor(override val statement: NativeStatement) : Cursor { override val columnNames: Map by lazy { val map = HashMap(this.columnCount) for (i in 0 until columnCount) { - map.put(columnName(i), i) + val key = columnName(i) + if (map.containsKey(key)) { + var index = 1 + val basicKey = "$key&JOIN" + var finalKey = basicKey + index + while (map.containsKey(finalKey)) { + finalKey = basicKey + ++index + } + map[finalKey] = i + } else { + map[key] = i + } } map }