diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2010-11-01 22:22:41 +0900 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2010-11-01 22:22:41 +0900 |
commit | ab80513755387112fa3c34a1fc7169766a51a51e (patch) | |
tree | 3593cff3cd20a4417a8f327dd4ba274a832f4084 /src/odbc/odbc_queries.erl | |
parent | Include 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.erl | 28 |
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( |