diff --git a/README.md b/README.md index 3bdaafc..967a80f 100644 --- a/README.md +++ b/README.md @@ -71,14 +71,14 @@ try (RawResponse response = client.select("http://localhost:8123", "SELECT * FRO ## How to add clickhouse-client into your project ### Gradle ``` -compile "com.ecwid.clickhouse:clickhouse-client:0.15.0" +compile "com.ecwid.clickhouse:clickhouse-client:0.16.0" ``` ### Maven ``` com.ecwid.clickhouse clickhouse-client - 0.15.0 + 0.16.0 ``` diff --git a/src/main/kotlin/com/ecwid/clickhouse/convert/Convert.kt b/src/main/kotlin/com/ecwid/clickhouse/convert/Convert.kt index 428cad3..58351d7 100644 --- a/src/main/kotlin/com/ecwid/clickhouse/convert/Convert.kt +++ b/src/main/kotlin/com/ecwid/clickhouse/convert/Convert.kt @@ -386,34 +386,6 @@ object Convert { @JvmStatic fun fromNullableArray(array: List) = array.map(::fromNullableValue) - - private const val QUOTE: Char = '\'' - private const val BACKSLASH = '\\' - - private fun escapeAndQuoteString(str: String): String { - // 2 symbols for quotes and 8 for possible escaping - // it's just heuristics, no serious science behind :) - val capacity = str.length + 10 - - return buildString(capacity) { - append(QUOTE) - - for (char in str) { - when (char) { - QUOTE -> { - append(BACKSLASH) - append(QUOTE) - } - BACKSLASH -> { - append(BACKSLASH) - append(BACKSLASH) - } - else -> append(char) - } - } - append(QUOTE) - } - } } object DateTime { @@ -538,11 +510,41 @@ object Convert { @JvmStatic fun fromValue(map: kotlin.collections.Map) = map.map { kv -> - val value = kv.value?.let { "'$it'" } ?: "NULL" - "'${kv.key}'" to value + val value = kv.value?.let { escapeAndQuoteString(it) } ?: "NULL" + escapeAndQuoteString(kv.key) to value }.toMap() @JvmStatic fun toMapValue(map: kotlin.collections.Map) = fromValue(map) } + + private const val QUOTE: Char = '\'' + private const val BACKSLASH = '\\' + + private fun escapeAndQuoteString(str: String): String { + // 2 symbols for quotes and 8 for possible escaping + // it's just heuristics, no serious science behind :) + val capacity = str.length + 10 + + return buildString(capacity) { + append(QUOTE) + + for (char in str) { + when (char) { + QUOTE -> { + append(BACKSLASH) + append(QUOTE) + } + + BACKSLASH -> { + append(BACKSLASH) + append(BACKSLASH) + } + + else -> append(char) + } + } + append(QUOTE) + } + } }