feat(tpl): support `:n` SQL parameters
This commit is contained in:
parent
dfb7faf6a8
commit
7bb995f0c6
|
@ -34,7 +34,7 @@
|
|||
-type values() :: [emqx_connector_sql:value()].
|
||||
|
||||
-type parse_opts() :: #{
|
||||
parameters => '$n' | '?',
|
||||
parameters => '$n' | ':n' | '?',
|
||||
% Inherited from `emqx_connector_template:parse_opts()`
|
||||
strip_double_quote => boolean()
|
||||
}.
|
||||
|
@ -116,7 +116,9 @@ mk_prepared_statement(Template, Opts) ->
|
|||
mk_replace('?', Acc) ->
|
||||
{"?", Acc};
|
||||
mk_replace('$n', N) ->
|
||||
{"$" ++ integer_to_list(N), N + 1}.
|
||||
{"$" ++ integer_to_list(N), N + 1};
|
||||
mk_replace(':n', N) ->
|
||||
{":" ++ integer_to_list(N), N + 1}.
|
||||
|
||||
%% @doc Render a row template into a list of SQL values.
|
||||
%% An _SQL value_ is a vaguely defined concept here, it is something that's considered
|
||||
|
|
|
@ -188,6 +188,13 @@ t_parse_sql_prepstmt_n(_) ->
|
|||
emqx_connector_template_sql:render_prepstmt_strict(RowTemplate, Bindings)
|
||||
).
|
||||
|
||||
t_parse_sql_prepstmt_colon(_) ->
|
||||
{PrepareStatement, _RowTemplate} =
|
||||
emqx_connector_template_sql:parse_prepstmt(<<"a=${a},b=${b},c=${c},d=${d}">>, #{
|
||||
parameters => ':n'
|
||||
}),
|
||||
?assertEqual(<<"a=:1,b=:2,c=:3,d=:4">>, bin(PrepareStatement)).
|
||||
|
||||
t_parse_sql_prepstmt_partial_ph(_) ->
|
||||
Bindings = #{a => <<"1">>, b => 1, c => 1.0, d => #{d1 => <<"hi">>}},
|
||||
{PrepareStatement, RowTemplate} =
|
||||
|
|
Loading…
Reference in New Issue