mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +01:00
Use specialized upsert with mysql
This commit is contained in:
parent
72867f8d1e
commit
d34227cae1
@ -558,6 +558,11 @@ make_sql_upsert(Table, ParseRes, Pos) ->
|
|||||||
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(
|
||||||
|
[erl_syntax:atom(mysql), erl_syntax:underscore()],
|
||||||
|
[],
|
||||||
|
[make_sql_upsert_mysql(Table, ParseRes),
|
||||||
|
erl_syntax:atom(ok)]),
|
||||||
erl_syntax:clause(
|
erl_syntax:clause(
|
||||||
[erl_syntax:underscore(), erl_syntax:underscore()],
|
[erl_syntax:underscore(), erl_syntax:underscore()],
|
||||||
none,
|
none,
|
||||||
@ -628,6 +633,9 @@ make_sql_upsert_update(Table, ParseRes) ->
|
|||||||
State.
|
State.
|
||||||
|
|
||||||
make_sql_upsert_insert(Table, ParseRes) ->
|
make_sql_upsert_insert(Table, ParseRes) ->
|
||||||
|
make_sql_upsert_insert_replace(Table, ParseRes, "INSERT").
|
||||||
|
|
||||||
|
make_sql_upsert_insert_replace(Table, ParseRes, Keyword) ->
|
||||||
Vals =
|
Vals =
|
||||||
lists:map(
|
lists:map(
|
||||||
fun({_Field, _, ST}) ->
|
fun({_Field, _, ST}) ->
|
||||||
@ -640,7 +648,7 @@ make_sql_upsert_insert(Table, ParseRes) ->
|
|||||||
end, ParseRes),
|
end, ParseRes),
|
||||||
State =
|
State =
|
||||||
concat_states(
|
concat_states(
|
||||||
[#state{'query' = [{str, "INSERT INTO "}, {str, Table}, {str, "("}]},
|
[#state{'query' = [{str, Keyword ++" INTO "}, {str, Table}, {str, "("}]},
|
||||||
join_states(Fields, ", "),
|
join_states(Fields, ", "),
|
||||||
#state{'query' = [{str, ") VALUES ("}]},
|
#state{'query' = [{str, ") VALUES ("}]},
|
||||||
join_states(Vals, ", "),
|
join_states(Vals, ", "),
|
||||||
@ -648,6 +656,16 @@ make_sql_upsert_insert(Table, ParseRes) ->
|
|||||||
]),
|
]),
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
make_sql_upsert_replace(Table, ParseRes) ->
|
||||||
|
make_sql_upsert_insert_replace(Table, ParseRes, "REPLACE").
|
||||||
|
|
||||||
|
make_sql_upsert_mysql(Table, ParseRes) ->
|
||||||
|
Replace = make_sql_query(make_sql_upsert_replace(Table, ParseRes)),
|
||||||
|
erl_syntax:application(
|
||||||
|
erl_syntax:atom(ejabberd_sql),
|
||||||
|
erl_syntax:atom(sql_query_t),
|
||||||
|
[Replace]).
|
||||||
|
|
||||||
make_sql_upsert_pgsql901(Table, ParseRes0) ->
|
make_sql_upsert_pgsql901(Table, ParseRes0) ->
|
||||||
ParseRes = lists:map(
|
ParseRes = lists:map(
|
||||||
fun({"family", A2, A3}) -> {"\"family\"", A2, A3};
|
fun({"family", A2, A3}) -> {"\"family\"", A2, A3};
|
||||||
|
Loading…
Reference in New Issue
Block a user