Skip to content

Business intelligence made simple

Fixed backslash test for ClickHouse [skip ci]

Andrew Kaneffa4d21b31e1
diff --git a/lib/blazer/adapters/clickhouse_adapter.rb b/lib/blazer/adapters/clickhouse_adapter.rb
index 8c64dc28..41a34cbc 100644
--- a/lib/blazer/adapters/clickhouse_adapter.rb
+++ b/lib/blazer/adapters/clickhouse_adapter.rb
@@ -21,6 +21,8 @@ module Blazer
}
bind_params.each do |k, v|
v = v.utc.strftime("%Y-%m-%d %H:%M:%S.%N") if v.is_a?(ActiveSupport::TimeWithZone)
+ # https://github.com/ClickHouse/ClickHouse/issues/69656
+ v = v.gsub("\\") { "\\\\" } if v.is_a?(String)
post_data["param_#{k}"] = v.to_s unless v.nil?
end
diff --git a/test/adapters/clickhouse_test.rb b/test/adapters/clickhouse_test.rb
index 21e9e3f5..cbbdc76e 100644
--- a/test/adapters/clickhouse_test.rb
+++ b/test/adapters/clickhouse_test.rb
@@ -88,8 +88,11 @@ class ClickhouseTest < ActionDispatch::IntegrationTest
assert_result [{"hello" => '"'}], "SELECT {var} AS hello", var: '"'
end
- # TODO fix
- # def test_backslash
- # assert_result [{"hello" => "\\"}], "SELECT {var} AS hello", var: "\\"
- # end
+ def test_backslash
+ assert_result [{"hello" => "\\"}], "SELECT {var} AS hello", var: "\\"
+ end
+
+ def test_double_backslash
+ assert_result [{"hello" => "\\\\"}], "SELECT {var} AS hello", var: "\\\\"
+ end
end