summaryrefslogtreecommitdiff
path: root/src/ejabberd_sql_pt.erl
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2016-05-04 21:01:05 +0300
committerAlexey Shchepin <alexey@process-one.net>2016-05-05 15:51:58 +0300
commit0ea0ba3004282636c95bc86c3aac8755fcf7f8b1 (patch)
tree1330b6db70f7f6100c1997851faece5ad569391f /src/ejabberd_sql_pt.erl
parentMerge remote-tracking branch 'processone/pr/1088' (diff)
Update more SQL queries
Diffstat (limited to 'src/ejabberd_sql_pt.erl')
-rw-r--r--src/ejabberd_sql_pt.erl24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/ejabberd_sql_pt.erl b/src/ejabberd_sql_pt.erl
index 47e4a07c..e51b7f92 100644
--- a/src/ejabberd_sql_pt.erl
+++ b/src/ejabberd_sql_pt.erl
@@ -305,20 +305,24 @@ parse_upsert(Fields) ->
"a constant string"})
end
end, {[], 0}, Fields),
- %io:format("asd ~p~n", [{Fields, Fs}]),
+ %io:format("upsert ~p~n", [{Fields, Fs}]),
Fs.
+%% key | {Update}
parse_upsert_field([$! | S], ParamPos, Loc) ->
{Name, ParseState} = parse_upsert_field1(S, [], ParamPos, Loc),
- {Name, true, ParseState};
+ {Name, key, ParseState};
+parse_upsert_field([$- | S], ParamPos, Loc) ->
+ {Name, ParseState} = parse_upsert_field1(S, [], ParamPos, Loc),
+ {Name, {false}, ParseState};
parse_upsert_field(S, ParamPos, Loc) ->
{Name, ParseState} = parse_upsert_field1(S, [], ParamPos, Loc),
- {Name, false, ParseState}.
+ {Name, {true}, ParseState}.
parse_upsert_field1([], _Acc, _ParamPos, Loc) ->
throw({error, Loc,
"?SQL_UPSERT fields must have the "
- "following form: \"[!]name=value\""});
+ "following form: \"[!-]name=value\""});
parse_upsert_field1([$= | S], Acc, ParamPos, Loc) ->
{lists:reverse(Acc), parse(S, ParamPos, Loc)};
parse_upsert_field1([C | S], Acc, ParamPos, Loc) ->
@@ -376,9 +380,9 @@ make_sql_upsert_generic(Table, ParseRes) ->
make_sql_upsert_update(Table, ParseRes) ->
WPairs =
lists:flatmap(
- fun({_Field, false, _ST}) ->
+ fun({_Field, {_}, _ST}) ->
[];
- ({Field, true, ST}) ->
+ ({Field, key, ST}) ->
[ST#state{
'query' = [{str, Field}, {str, "="}] ++ ST#state.'query'
}]
@@ -386,9 +390,11 @@ make_sql_upsert_update(Table, ParseRes) ->
Where = join_states(WPairs, " AND "),
SPairs =
lists:flatmap(
- fun({_Field, true, _ST}) ->
+ fun({_Field, key, _ST}) ->
+ [];
+ ({_Field, {false}, _ST}) ->
[];
- ({Field, false, ST}) ->
+ ({Field, {true}, ST}) ->
[ST#state{
'query' = [{str, Field}, {str, "="}] ++ ST#state.'query'
}]
@@ -462,7 +468,7 @@ check_upsert(ParseRes, Pos) ->
Set =
lists:filter(
fun({_Field, Match, _ST}) ->
- not Match
+ Match /= key
end, ParseRes),
case Set of
[] ->