Browse Source

fix: sql split re

Even though sql templates ending with `;` may sometimes fail to work.
they should be bug-to-bug compatible.
JimMoen 1 year ago
parent
commit
4b9c8cb5d2

+ 1 - 1
apps/emqx_bridge_clickhouse/src/emqx_bridge_clickhouse_connector.erl

@@ -110,7 +110,7 @@
     %%     `VALUES [([<VALUE> | <PLACEHOLDER>], ...)]`
     %% Keep Capturing-Group:
     %%     `([<VALUE> | <PLACEHOLDER>], ...) [, ([<VALUE> | <PLACEHOLDER>], ..)]`
-    "(?:values\\s*(\\((?:[^()]++|(?2))*\\)(?:\\s*,\\s*\\((?:[^()]++|(?2)*)\\))*))",
+    "(?:values\\s*(\\((?:[^()]++|(?2))*\\)(?:\\s*,\\s*\\((?:[^()]++|(?2)*)\\))*)\\s*;?\\s*)",
     %% End Group-2
     %% or
     "|",

+ 13 - 0
apps/emqx_bridge_clickhouse/test/emqx_bridge_clickhouse_SUITE.erl

@@ -261,6 +261,19 @@ t_parse_insert_sql_template(_Config) ->
             <<"INSERT INTO Values_таблица (идентификатор, имя, возраст)   VALUES \t (${id}, 'Иван', 25)  "/utf8>>
         )
     ),
+    %% with `;` suffix, bug-to-bug compatibility
+    ?assertEqual(
+        <<"(${id}, 'Иван', 25)"/utf8>>,
+        parse_insert(
+            <<"INSERT INTO Values_таблица (идентификатор, имя, возраст)   VALUES \t (${id}, 'Иван', 25);  "/utf8>>
+        )
+    ),
+    ?assertEqual(
+        <<"(${id},'李四', 35)"/utf8>>,
+        parse_insert(
+            <<"  inSErt into 表格(标识,名字,年龄)values(${id},'李四', 35) ; "/utf8>>
+        )
+    ),
 
     %% `values` in column name
     ?assertEqual(