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
1 changed files with 28 additions and 18 deletions

View File

@ -549,25 +549,35 @@ 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")],
[erl_syntax:infix_expr( [erl_syntax:infix_expr(
erl_syntax:variable("__Version"), erl_syntax:variable("__Version"),
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(
[], [erl_syntax:underscore(), erl_syntax:underscore()],
[make_sql_upsert_mysql(Table, ParseRes), none,
erl_syntax:atom(ok)]), [make_sql_upsert_generic(Table, ParseRes)])
erl_syntax:clause( ]).
[erl_syntax:underscore(), erl_syntax:underscore()],
none,
[make_sql_upsert_generic(Table, ParseRes)])
]).
make_sql_upsert_generic(Table, ParseRes) -> make_sql_upsert_generic(Table, ParseRes) ->
Update = make_sql_query(make_sql_upsert_update(Table, ParseRes)), Update = make_sql_query(make_sql_upsert_update(Table, ParseRes)),