aboutsummaryrefslogtreecommitdiff
path: root/src/odbc/odbc_queries.erl
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2010-11-01 22:22:41 +0900
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2010-11-01 22:22:41 +0900
commitab80513755387112fa3c34a1fc7169766a51a51e (patch)
tree3593cff3cd20a4417a8f327dd4ba274a832f4084 /src/odbc/odbc_queries.erl
parentInclude a Required xml element in the captcha field (diff)
Do not run set_last request inside a transaction
Diffstat (limited to 'src/odbc/odbc_queries.erl')
-rw-r--r--src/odbc/odbc_queries.erl28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/odbc/odbc_queries.erl b/src/odbc/odbc_queries.erl
index 8782eeba7..c2b280b1a 100644
--- a/src/odbc/odbc_queries.erl
+++ b/src/odbc/odbc_queries.erl
@@ -121,6 +121,23 @@ update_t(Table, Fields, Vals, Where) ->
") values ('", join(Vals, "', '"), "');"])
end.
+update(LServer, Table, Fields, Vals, Where) ->
+ UPairs = lists:zipwith(fun(A, B) -> A ++ "='" ++ B ++ "'" end,
+ Fields, Vals),
+ case ejabberd_odbc:sql_query(
+ LServer,
+ ["update ", Table, " set ",
+ join(UPairs, ", "),
+ " where ", Where, ";"]) of
+ {updated, 1} ->
+ ok;
+ _ ->
+ ejabberd_odbc:sql_query(
+ LServer,
+ ["insert into ", Table, "(", join(Fields, ", "),
+ ") values ('", join(Vals, "', '"), "');"])
+ end.
+
%% F can be either a fun or a list of queries
%% TODO: We should probably move the list of queries transaction
%% wrapper from the ejabberd_odbc module to this one (odbc_queries)
@@ -134,14 +151,9 @@ get_last(LServer, Username) ->
"where username='", Username, "'"]).
set_last_t(LServer, Username, Seconds, State) ->
- %% MREMOND: I think this should be turn into a non transactional behaviour
- ejabberd_odbc:sql_transaction(
- LServer,
- fun() ->
- update_t("last", ["username", "seconds", "state"],
- [Username, Seconds, State],
- ["username='", Username, "'"])
- end).
+ update(LServer, "last", ["username", "seconds", "state"],
+ [Username, Seconds, State],
+ ["username='", Username, "'"]).
del_last(LServer, Username) ->
ejabberd_odbc:sql_query(