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

* src/odbc/odbc_queries.erl: replaced string:join/2 function.

Removed ugly "catch" statement from update_t/4.
WARNING: this change requires last version of mysql driver.
You can update it from ejabberd-modules repository.

SVN Revision: 1762
This commit is contained in:
Evgeniy Khramtsov 2008-12-29 09:26:20 +00:00
parent 85fdf7cb25
commit 5a5ab955cb
2 changed files with 21 additions and 11 deletions

View File

@ -4,6 +4,11 @@
an SQL transaction exceeds number of restarts. Also rollbacks an SQL transaction exceeds number of restarts. Also rollbacks
this transaction to prevent deadlocks. this transaction to prevent deadlocks.
* src/odbc/odbc_queries.erl: replaced string:join/2 function.
Removed ugly "catch" statement from update_t/4.
WARNING: this change requires last version of mysql driver.
You can update it from ejabberd-modules repository.
2008-12-28 Mickael Remond <mremond@process-one.net> 2008-12-28 Mickael Remond <mremond@process-one.net>
* src/ejabberd_c2s.erl: We should allow use of bare resource in from by * src/ejabberd_c2s.erl: We should allow use of bare resource in from by

View File

@ -88,6 +88,14 @@
-define(generic, true). -define(generic, true).
-endif. -endif.
%% Almost a copy of string:join/2.
%% We use this version because string:join/2 is relatively
%% new function (introduced in R12B-0).
join([], _Sep) ->
[];
join([H|T], Sep) ->
[H, [[Sep, X] || X <- T]].
%% ----------------- %% -----------------
%% Generic queries %% Generic queries
-ifdef(generic). -ifdef(generic).
@ -101,17 +109,14 @@ update_t(Table, Fields, Vals, Where) ->
Fields, Vals), Fields, Vals),
case ejabberd_odbc:sql_query_t( case ejabberd_odbc:sql_query_t(
["update ", Table, " set ", ["update ", Table, " set ",
string:join(UPairs, ", "), join(UPairs, ", "),
" where ", Where, ";"]) of " where ", Where, ";"]) of
{updated, 1} -> {updated, 1} ->
ok; ok;
_ -> _ ->
%% The 'catch' herein is used because mysql returns ejabberd_odbc:sql_query_t(
%% affected rows (not matched as in postgresql). ["insert into ", Table, "(", join(Fields, ", "),
%% FIXME: need to find more suitable solution. ") values ('", join(Vals, "', '"), "');"])
catch ejabberd_odbc:sql_query_t(
["insert into ", Table, "(", string:join(Fields, ", "),
") values ('", string:join(Vals, "', '"), "');"])
end. end.
%% F can be either a fun or a list of queries %% F can be either a fun or a list of queries
@ -346,7 +351,7 @@ update_roster(_LServer, Username, SJID, ItemVals, ItemGroups) ->
ejabberd_odbc:sql_query_t( ejabberd_odbc:sql_query_t(
["insert into rostergroups(" ["insert into rostergroups("
" username, jid, grp) " " username, jid, grp) "
" values ('", string:join(ItemGroup, "', '"), "');"]) " values ('", join(ItemGroup, "', '"), "');"])
end, end,
ItemGroups). ItemGroups).
@ -358,13 +363,13 @@ update_roster_sql(Username, SJID, ItemVals, ItemGroups) ->
" username, jid, nick, " " username, jid, nick, "
" subscription, ask, askmessage, " " subscription, ask, askmessage, "
" server, subscribe, type) " " server, subscribe, type) "
" values ('", string:join(ItemVals, "', '"), "');"], " values ('", join(ItemVals, "', '"), "');"],
["delete from rostergroups " ["delete from rostergroups "
" where username='", Username, "' " " where username='", Username, "' "
" and jid='", SJID, "';"]] ++ " and jid='", SJID, "';"]] ++
[["insert into rostergroups(" [["insert into rostergroups("
" username, jid, grp) " " username, jid, grp) "
" values ('", string:join(ItemGroup, "', '"), "');"] || " values ('", join(ItemGroup, "', '"), "');"] ||
ItemGroup <- ItemGroups]. ItemGroup <- ItemGroups].
roster_subscribe(_LServer, Username, SJID, ItemVals) -> roster_subscribe(_LServer, Username, SJID, ItemVals) ->
@ -520,7 +525,7 @@ set_privacy_list(ID, RItems) ->
"match_presence_out " "match_presence_out "
") " ") "
"values ('", ID, "', '", "values ('", ID, "', '",
string:join(Items, "', '"), "');"]) join(Items, "', '"), "');"])
end, RItems). end, RItems).
del_privacy_lists(LServer, Server, Username) -> del_privacy_lists(LServer, Server, Username) ->