25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Don't use REPLACE for upsert when there are "-" fields.

This should fix problem reported in #3476
This commit is contained in:
Paweł Chmielowski 2021-01-11 14:20:17 +01:00
parent 402b301eb5
commit 446cb485ac

View File

@ -549,6 +549,20 @@ parse_upsert_field1([C | S], Acc, ParamPos, Loc) ->
make_sql_upsert(Table, ParseRes, Pos) -> make_sql_upsert(Table, ParseRes, Pos) ->
check_upsert(ParseRes, Pos), check_upsert(ParseRes, Pos),
HasInsertOnlyFields = lists:any(
fun({_, {false}, _}) -> true;
(_) -> false
end, ParseRes),
MySqlReplace = case HasInsertOnlyFields of
false ->
[erl_syntax:clause(
[erl_syntax:atom(mysql), erl_syntax:underscore()],
[],
[make_sql_upsert_mysql(Table, ParseRes),
erl_syntax:atom(ok)])];
_ ->
[]
end,
erl_syntax:fun_expr( erl_syntax:fun_expr(
[erl_syntax:clause( [erl_syntax:clause(
[erl_syntax:atom(pgsql), erl_syntax:variable("__Version")], [erl_syntax:atom(pgsql), erl_syntax:variable("__Version")],
@ -557,13 +571,9 @@ make_sql_upsert(Table, ParseRes, Pos) ->
erl_syntax:operator('>='), erl_syntax:operator('>='),
erl_syntax:integer(90100))], erl_syntax:integer(90100))],
[make_sql_upsert_pgsql901(Table, ParseRes), [make_sql_upsert_pgsql901(Table, ParseRes),
erl_syntax:atom(ok)]), erl_syntax:atom(ok)])] ++
erl_syntax:clause( MySqlReplace ++
[erl_syntax:atom(mysql), erl_syntax:underscore()], [erl_syntax:clause(
[],
[make_sql_upsert_mysql(Table, ParseRes),
erl_syntax:atom(ok)]),
erl_syntax:clause(
[erl_syntax:underscore(), erl_syntax:underscore()], [erl_syntax:underscore(), erl_syntax:underscore()],
none, none,
[make_sql_upsert_generic(Table, ParseRes)]) [make_sql_upsert_generic(Table, ParseRes)])