]> granicus.if.org Git - ejabberd/commitdiff
Rename odbc to sql everywhere
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Wed, 20 Apr 2016 09:27:32 +0000 (12:27 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Wed, 20 Apr 2016 10:25:42 +0000 (13:25 +0300)
47 files changed:
ejabberd.yml.example
include/ejabberd_sql_pt.hrl
include/pubsub.hrl
src/ejabberd_admin.erl
src/ejabberd_auth.erl
src/ejabberd_auth_internal.erl
src/ejabberd_auth_riak.erl
src/ejabberd_auth_sql.erl [moved from src/ejabberd_auth_odbc.erl with 89% similarity]
src/ejabberd_config.erl
src/ejabberd_piefxis.erl
src/ejabberd_rdbms.erl
src/ejabberd_sm.erl
src/ejabberd_sm_sql.erl
src/ejabberd_sql.erl [moved from src/ejabberd_odbc.erl with 95% similarity]
src/ejabberd_sql_pt.erl
src/ejabberd_sql_sup.erl [moved from src/ejabberd_odbc_sup.erl with 89% similarity]
src/ejabberd_web_admin.erl
src/ejd2sql.erl [moved from src/ejd2odbc.erl with 95% similarity]
src/gen_mod.erl
src/mod_announce_sql.erl
src/mod_blocking_sql.erl
src/mod_caps.erl
src/mod_caps_sql.erl
src/mod_irc_sql.erl
src/mod_last_sql.erl
src/mod_mam.erl
src/mod_mam_sql.erl
src/mod_muc_sql.erl
src/mod_offline.erl
src/mod_offline_sql.erl
src/mod_privacy_sql.erl
src/mod_private_sql.erl
src/mod_pubsub.erl
src/mod_roster_sql.erl
src/mod_shared_roster_sql.erl
src/mod_vcard_sql.erl
src/mod_vcard_xupdate_sql.erl
src/node_flat_sql.erl [moved from src/node_flat_odbc.erl with 89% similarity]
src/node_hometree_sql.erl [moved from src/node_hometree_odbc.erl with 69% similarity]
src/node_mix_sql.erl [moved from src/node_mix_odbc.erl with 68% similarity]
src/node_pep_sql.erl [moved from src/node_pep_odbc.erl with 72% similarity]
src/nodetree_tree_sql.erl [moved from src/nodetree_tree_odbc.erl with 82% similarity]
src/pubsub_db_sql.erl [moved from src/pubsub_db_odbc.erl with 57% similarity]
src/pubsub_subscription_sql.erl [moved from src/pubsub_subscription_odbc.erl with 99% similarity]
src/sql_queries.erl [moved from src/odbc_queries.erl with 88% similarity]
test/ejabberd_SUITE.erl
test/ejabberd_SUITE_data/ejabberd.yml

index 11b27e650148ccd24c742adc5aa8d8e4967f0086..b0f62214901a25666ad59dc8f50c370d7eacbef5 100644 (file)
@@ -254,10 +254,10 @@ auth_method: internal
 ## extauth_program: "/path/to/authentication/script"
 
 ##
-## Authentication using ODBC
+## Authentication using SQL
 ## Remember to setup a database in the next section.
 ##
-## auth_method: odbc
+## auth_method: sql
 
 ##
 ## Authentication using PAM
@@ -330,26 +330,26 @@ auth_method: internal
 ##
 ## MySQL server:
 ##
-## odbc_type: mysql
-## odbc_server: "server"
-## odbc_database: "database"
-## odbc_username: "username"
-## odbc_password: "password"
+## sql_type: mysql
+## sql_server: "server"
+## sql_database: "database"
+## sql_username: "username"
+## sql_password: "password"
 ##
 ## If you want to specify the port:
-## odbc_port: 1234
+## sql_port: 1234
 
 ##
 ## PostgreSQL server:
 ##
-## odbc_type: pgsql
-## odbc_server: "server"
-## odbc_database: "database"
-## odbc_username: "username"
-## odbc_password: "password"
+## sql_type: pgsql
+## sql_server: "server"
+## sql_database: "database"
+## sql_username: "username"
+## sql_password: "password"
 ##
 ## If you want to specify the port:
-## odbc_port: 1234
+## sql_port: 1234
 ##
 ## If you use PostgreSQL, have a large database, and need a
 ## faster but inexact replacement for "select count(*) from users"
@@ -359,25 +359,25 @@ auth_method: internal
 ##
 ## SQLite:
 ##
-## odbc_type: sqlite
-## odbc_database: "/path/to/database.db"
+## sql_type: sqlite
+## sql_database: "/path/to/database.db"
 
 ##
 ## ODBC compatible or MSSQL server:
 ##
-## odbc_type: odbc
-## odbc_server: "DSN=ejabberd;UID=ejabberd;PWD=ejabberd"
+## sql_type: odbc
+## sql_server: "DSN=ejabberd;UID=ejabberd;PWD=ejabberd"
 
 ##
 ## Number of connections to open to the database for each virtual host
 ##
-## odbc_pool_size: 10
+## sql_pool_size: 10
 
 ##
 ## Interval to make a dummy SQL request to keep the connections to the
 ## database alive. Specify in seconds: for example 28800 means 8 hours
 ##
-## odbc_keepalive_interval: undefined
+## sql_keepalive_interval: undefined
 
 ###.  ===============
 ###'  TRAFFIC SHAPERS
index 0048661dac7e903061b267435cc4f4c496f3bb44..f1a3dba3f7c71c581bbd57fa45d3061f904011fa 100644 (file)
@@ -23,9 +23,9 @@
 
 -define(SQL_UPSERT_MARK, sql_upsert__mark_).
 -define(SQL_UPSERT(Host, Table, Fields),
-        ejabberd_odbc:sql_query(Host, ?SQL_UPSERT_MARK(Table, Fields))).
+        ejabberd_sql:sql_query(Host, ?SQL_UPSERT_MARK(Table, Fields))).
 -define(SQL_UPSERT_T(Table, Fields),
-        ejabberd_odbc:sql_query_t(?SQL_UPSERT_MARK(Table, Fields))).
+        ejabberd_sql:sql_query_t(?SQL_UPSERT_MARK(Table, Fields))).
 
 -record(sql_query, {hash, format_query, format_res, args, loc}).
 
index 209f802db42f96af36b609487febc06aa8ef56aa..3aa090d3bad39ce31fcc9a836880391ea95f9401 100644 (file)
@@ -65,7 +65,7 @@
 %% note: pos_integer() should always be used, but we allow anything else coded
 %% as binary, so one can have a custom implementation of nodetree with custom
 %% indexing (see nodetree_virtual). this also allows to use any kind of key for
-%% indexing nodes, as this can be usefull with external backends such as odbc.
+%% indexing nodes, as this can be usefull with external backends such as sql.
 
 -type(itemId() :: binary()).
 %% @type itemId() = string().
index b22a70385f8477a7edcfeabbe141060836b89f8f..a22f8f3d348bbd613c5922400f2582ce473488ee 100644 (file)
@@ -192,20 +192,20 @@ get_commands_spec() ->
                        module = ejabberd_piefxis, function = export_host,
                        args = [{dir, string}, {host, string}], result = {res, rescode}},
 
-     #ejabberd_commands{name = export_odbc, tags = [mnesia, odbc],
+     #ejabberd_commands{name = export_sql, tags = [mnesia, sql],
                         desc = "Export all tables as SQL queries to a file",
-                        module = ejd2odbc, function = export,
+                        module = ejd2sql, function = export,
                         args = [{host, string}, {file, string}], result = {res, rescode}},
-     #ejabberd_commands{name = delete_mnesia, tags = [mnesia, odbc],
+     #ejabberd_commands{name = delete_mnesia, tags = [mnesia, sql],
                         desc = "Export all tables as SQL queries to a file",
-                        module = ejd2odbc, function = delete,
+                        module = ejd2sql, function = delete,
                         args = [{host, string}], result = {res, rescode}},
-     #ejabberd_commands{name = convert_to_scram, tags = [odbc],
+     #ejabberd_commands{name = convert_to_scram, tags = [sql],
                        desc = "Convert the passwords in 'users' ODBC table to SCRAM",
-                       module = ejabberd_auth_odbc, function = convert_to_scram,
+                       module = ejabberd_auth_sql, function = convert_to_scram,
                        args = [{host, binary}], result = {res, rescode}},
 
-     #ejabberd_commands{name = import_prosody, tags = [mnesia, odbc, riak],
+     #ejabberd_commands{name = import_prosody, tags = [mnesia, sql, riak],
                        desc = "Import data from Prosody",
                        module = prosody2ejabberd, function = from_dir,
                        args = [{dir, string}], result = {res, rescode}},
@@ -225,9 +225,9 @@ get_commands_spec() ->
                        module = ?MODULE, function = delete_old_messages,
                        args = [{days, integer}], result = {res, rescode}},
         
-     #ejabberd_commands{name = export2odbc, tags = [mnesia],
+     #ejabberd_commands{name = export2sql, tags = [mnesia],
                        desc = "Export virtual host information from Mnesia tables to SQL files",
-                       module = ejd2odbc, function = export,
+                       module = ejd2sql, function = export,
                        args = [{host, string}, {directory, string}],
                        result = {res, rescode}},
      #ejabberd_commands{name = set_master, tags = [mnesia],
index 343ad94369494545f29851395932c32b51d3e7bf..0267a2192761e958356afe42844823321eb6577e 100644 (file)
@@ -137,7 +137,7 @@ check_password(User, AuthzId, Server, Password, Digest,
 %% where
 %%   AuthModule = ejabberd_auth_anonymous | ejabberd_auth_external
 %%                 | ejabberd_auth_internal | ejabberd_auth_ldap
-%%                 | ejabberd_auth_odbc | ejabberd_auth_pam | ejabberd_auth_riak
+%%                 | ejabberd_auth_sql | ejabberd_auth_pam | ejabberd_auth_riak
 -spec check_password_with_authmodule(binary(), binary(), binary(), binary()) -> false |
                                                                       {true, atom()}.
 
index 3b30b360735001689fc4632def338206505b51a0..acbbfe506730646ddcd67646eb032232ee29b81f 100644 (file)
@@ -474,8 +474,8 @@ export(_Server) ->
     [{passwd,
       fun(Host, #passwd{us = {LUser, LServer}, password = Password})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
-              Pass = ejabberd_odbc:escape(Password),
+              Username = ejabberd_sql:escape(LUser),
+              Pass = ejabberd_sql:escape(Password),
               [[<<"delete from users where username='">>, Username, <<"';">>],
                [<<"insert into users(username, password) "
                   "values ('">>, Username, <<"', '">>, Pass, <<"');">>]];
index bc745fea449870b4d7ad2065064e54e55124f690..c48b94410972bd6bc420a10dae6e6bfd93c30173 100644 (file)
@@ -291,8 +291,8 @@ export(_Server) ->
     [{passwd,
       fun(Host, #passwd{us = {LUser, LServer}, password = Password})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
-              Pass = ejabberd_odbc:escape(Password),
+              Username = ejabberd_sql:escape(LUser),
+              Pass = ejabberd_sql:escape(Password),
               [[<<"delete from users where username='">>, Username, <<"';">>],
                [<<"insert into users(username, password) "
                   "values ('">>, Username, <<"', '">>, Pass, <<"');">>]];
similarity index 89%
rename from src/ejabberd_auth_odbc.erl
rename to src/ejabberd_auth_sql.erl
index dc3248fe8f6ddd09381a92873871394e6baba971..000b4a4f4e8b177b52957a54fa958fb6fdf67260 100644 (file)
@@ -1,5 +1,5 @@
 %%%----------------------------------------------------------------------
-%%% File    : ejabberd_auth_odbc.erl
+%%% File    : ejabberd_auth_sql.erl
 %%% Author  : Alexey Shchepin <alexey@process-one.net>
 %%% Purpose : Authentification via ODBC
 %%% Created : 12 Dec 2004 by Alexey Shchepin <alexey@process-one.net>
@@ -23,7 +23,7 @@
 %%%
 %%%----------------------------------------------------------------------
 
--module(ejabberd_auth_odbc).
+-module(ejabberd_auth_sql).
 
 -behaviour(ejabberd_config).
 
@@ -77,7 +77,7 @@ check_password(User, AuthzId, Server, Password) ->
        true ->
             case is_scrammed() of
                 true ->
-                    try odbc_queries:get_password_scram(LServer, LUser) of
+                    try sql_queries:get_password_scram(LServer, LUser) of
                         {selected,
                          [{StoredKey, ServerKey, Salt, IterationCount}]} ->
                             Scram =
@@ -95,7 +95,7 @@ check_password(User, AuthzId, Server, Password) ->
                             false %% Typical error is database not accessible
                     end;
                 false ->
-                    try odbc_queries:get_password(LServer, LUser) of
+                    try sql_queries:get_password(LServer, LUser) of
                         {selected, [{Password}]} ->
                             Password /= <<"">>;
                         {selected, [{_Password2}]} ->
@@ -127,7 +127,7 @@ check_password(User, AuthzId, Server, Password, Digest,
        true ->
             case is_scrammed() of
                 false ->
-                    try odbc_queries:get_password(LServer, LUser) of
+                    try sql_queries:get_password(LServer, LUser) of
                         %% Account exists, check if password is valid
                         {selected, [{Passwd}]} ->
                             DigRes = if Digest /= <<"">> ->
@@ -164,7 +164,7 @@ set_password(User, Server, Password) ->
             case is_scrammed() of
                 true ->
                     Scram = password_to_scram(Password),
-                    case catch odbc_queries:set_password_scram_t(
+                    case catch sql_queries:set_password_scram_t(
                                  LServer,
                                  LUser,
                                  Scram#scram.storedkey,
@@ -177,7 +177,7 @@ set_password(User, Server, Password) ->
                         Other -> {error, Other}
                     end;
                 false ->
-                    case catch odbc_queries:set_password_t(LServer,
+                    case catch sql_queries:set_password_t(LServer,
                                                            LUser, Password)
                         of
                         {atomic, ok} -> ok;
@@ -198,7 +198,7 @@ try_register(User, Server, Password) ->
             case is_scrammed() of
                 true ->
                     Scram = password_to_scram(Password),
-                    case catch odbc_queries:add_user_scram(
+                    case catch sql_queries:add_user_scram(
                                  LServer,
                                  LUser,
                                  Scram#scram.storedkey,
@@ -210,7 +210,7 @@ try_register(User, Server, Password) ->
                         _ -> {atomic, exists}
                     end;
                 false ->
-                    case catch odbc_queries:add_user(LServer, LUser,
+                    case catch sql_queries:add_user(LServer, LUser,
                                                      Password) of
                         {updated, 1} -> {atomic, ok};
                         _ -> {atomic, exists}
@@ -219,7 +219,7 @@ try_register(User, Server, Password) ->
     end.
 
 dirty_get_registered_users() ->
-    Servers = ejabberd_config:get_vh_by_auth_method(odbc),
+    Servers = ejabberd_config:get_vh_by_auth_method(sql),
     lists:flatmap(fun (Server) ->
                          get_vh_registered_users(Server)
                  end,
@@ -230,7 +230,7 @@ get_vh_registered_users(Server) ->
         error -> [];
         <<>> -> [];
         LServer ->
-            case catch odbc_queries:list_users(LServer) of
+            case catch sql_queries:list_users(LServer) of
                 {selected, Res} ->
                     [{U, LServer} || {U} <- Res];
                 _ -> []
@@ -242,7 +242,7 @@ get_vh_registered_users(Server, Opts) ->
         error -> [];
         <<>> -> [];
         LServer ->
-            case catch odbc_queries:list_users(LServer, Opts) of
+            case catch sql_queries:list_users(LServer, Opts) of
                 {selected, Res} ->
                     [{U, LServer} || {U} <- Res];
                 _ -> []
@@ -254,7 +254,7 @@ get_vh_registered_users_number(Server) ->
         error -> 0;
         <<>> -> 0;
         LServer ->
-            case catch odbc_queries:users_number(LServer) of
+            case catch sql_queries:users_number(LServer) of
                 {selected, [{Res}]} ->
                     Res;
                 _ -> 0
@@ -266,7 +266,7 @@ get_vh_registered_users_number(Server, Opts) ->
         error -> 0;
         <<>> -> 0;
         LServer ->
-            case catch odbc_queries:users_number(LServer, Opts) of
+            case catch sql_queries:users_number(LServer, Opts) of
                 {selected, [{Res}]} ->
                     Res;
                 _Other -> 0
@@ -283,7 +283,7 @@ get_password(User, Server) ->
        true ->
             case is_scrammed() of
                 true ->
-                    case catch odbc_queries:get_password_scram(
+                    case catch sql_queries:get_password_scram(
                                  LServer, LUser) of
                         {selected,
                          [{StoredKey, ServerKey, Salt, IterationCount}]} ->
@@ -294,7 +294,7 @@ get_password(User, Server) ->
                         _ -> false
                     end;
                 false ->
-                    case catch odbc_queries:get_password(LServer, LUser)
+                    case catch sql_queries:get_password(LServer, LUser)
                         of
                         {selected, [{Password}]} -> Password;
                         _ -> false
@@ -312,7 +312,7 @@ get_password_s(User, Server) ->
        true ->
             case is_scrammed() of
                 false ->
-                    case catch odbc_queries:get_password(LServer, LUser) of
+                    case catch sql_queries:get_password(LServer, LUser) of
                         {selected, [{Password}]} -> Password;
                         _ -> <<"">>
                     end;
@@ -329,7 +329,7 @@ is_user_exists(User, Server) ->
        (LUser == <<>>) or (LServer == <<>>) ->
             false;
        true ->
-         try odbc_queries:get_password(LServer, LUser) of
+         try sql_queries:get_password(LServer, LUser) of
            {selected, [{_Password}]} ->
                true; %% Account exists
            {selected, []} ->
@@ -351,7 +351,7 @@ remove_user(User, Server) ->
        (LUser == <<>>) or (LServer == <<>>) ->
             error;
        true ->
-         catch odbc_queries:del_user(LServer, LUser),
+         catch sql_queries:del_user(LServer, LUser),
          ok
     end.
 
@@ -375,7 +375,7 @@ remove_user(User, Server, Password) ->
                     end;
                 false ->
                     F = fun () ->
-                                Result = odbc_queries:del_user_return_password(
+                                Result = sql_queries:del_user_return_password(
                                            LServer, LUser, Password),
                                 case Result of
                                     {selected, [{Password}]} -> ok;
@@ -383,7 +383,7 @@ remove_user(User, Server, Password) ->
                                     _ -> not_allowed
                                 end
                         end,
-                    {atomic, Result} = odbc_queries:sql_transaction(
+                    {atomic, Result} = sql_queries:sql_transaction(
                                          LServer, F),
                     Result
             end
@@ -427,7 +427,7 @@ is_password_scram_valid(Password, Scram) ->
 
 set_password_scram_t(Username,
                      StoredKey, ServerKey, Salt, IterationCount) ->
-    odbc_queries:update_t(<<"users">>,
+    sql_queries:update_t(<<"users">>,
                           [<<"username">>,
                            <<"password">>,
                            <<"serverkey">>,
@@ -447,7 +447,7 @@ convert_to_scram(Server) ->
             {error, {incorrect_server_name, Server}};
         true ->
             F = fun () ->
-                        case ejabberd_odbc:sql_query_t(
+                        case ejabberd_sql:sql_query_t(
                                [<<"select username, password from users where "
                                  "iterationcount=0 limit ">>,
                                 integer_to_binary(?BATCH_SIZE),
@@ -457,13 +457,13 @@ convert_to_scram(Server) ->
                             {selected, [<<"username">>, <<"password">>], Rs} ->
                                 lists:foreach(
                                   fun([LUser, Password]) ->
-                                          Username = ejabberd_odbc:escape(LUser),
+                                          Username = ejabberd_sql:escape(LUser),
                                           Scram = password_to_scram(Password),
                                           set_password_scram_t(
                                             Username,
-                                            ejabberd_odbc:escape(Scram#scram.storedkey),
-                                            ejabberd_odbc:escape(Scram#scram.serverkey),
-                                            ejabberd_odbc:escape(Scram#scram.salt),
+                                            ejabberd_sql:escape(Scram#scram.storedkey),
+                                            ejabberd_sql:escape(Scram#scram.serverkey),
+                                            ejabberd_sql:escape(Scram#scram.salt),
                                             integer_to_binary(Scram#scram.iterationcount)
                                            )
                                   end, Rs),
@@ -471,7 +471,7 @@ convert_to_scram(Server) ->
                             Err -> {bad_reply, Err}
                         end
                 end,
-            case odbc_queries:sql_transaction(LServer, F) of
+            case sql_queries:sql_transaction(LServer, F) of
                 {atomic, ok} -> ok;
                 {atomic, continue} -> convert_to_scram(Server);
                 {atomic, Error} -> {error, Error};
index 13b636c7b04d1eb83efa51298d57fac75dd6cbe6..f73474fe7b909f1ef085c4dafd5a8e508421f872 100644 (file)
@@ -651,14 +651,27 @@ process_host_term(Term, Host, State, Action) ->
         {hosts, _} ->
             State;
        {Opt, Val} when Action == set ->
-           set_option({Opt, Host}, Val, State);
+           set_option({rename_option(Opt), Host}, Val, State);
         {Opt, Val} when Action == append ->
-            append_option({Opt, Host}, Val, State);
+            append_option({rename_option(Opt), Host}, Val, State);
         Opt ->
             ?WARNING_MSG("Ignore invalid (outdated?) option ~p", [Opt]),
             State
     end.
 
+rename_option(Option) when is_atom(Option) ->
+    case atom_to_list(Option) of
+       "odbc_" ++ T ->
+           NewOption = list_to_atom("sql_" ++ T),
+           ?WARNING_MSG("Option '~s' is obsoleted, use '~s' instead",
+                        [Option, NewOption]),
+           NewOption;
+       _ ->
+           Option
+    end;
+rename_option(Option) ->
+    Option.
+
 set_option(Opt, Val, State) ->
     State#state{opts = [#local_config{key = Opt, value = Val} |
                         State#state.opts]}.
@@ -867,20 +880,20 @@ get_mylang() ->
       fun iolist_to_binary/1,
       <<"en">>).
 
-replace_module(mod_announce_odbc) -> {mod_announce, odbc};
-replace_module(mod_blocking_odbc) -> {mod_blocking, odbc};
-replace_module(mod_caps_odbc) -> {mod_caps, odbc};
-replace_module(mod_irc_odbc) -> {mod_irc, odbc};
-replace_module(mod_last_odbc) -> {mod_last, odbc};
-replace_module(mod_muc_odbc) -> {mod_muc, odbc};
-replace_module(mod_offline_odbc) -> {mod_offline, odbc};
-replace_module(mod_privacy_odbc) -> {mod_privacy, odbc};
-replace_module(mod_private_odbc) -> {mod_private, odbc};
-replace_module(mod_roster_odbc) -> {mod_roster, odbc};
-replace_module(mod_shared_roster_odbc) -> {mod_shared_roster, odbc};
-replace_module(mod_vcard_odbc) -> {mod_vcard, odbc};
-replace_module(mod_vcard_xupdate_odbc) -> {mod_vcard_xupdate, odbc};
-replace_module(mod_pubsub_odbc) -> {mod_pubsub, odbc};
+replace_module(mod_announce_odbc) -> {mod_announce, sql};
+replace_module(mod_blocking_odbc) -> {mod_blocking, sql};
+replace_module(mod_caps_odbc) -> {mod_caps, sql};
+replace_module(mod_irc_odbc) -> {mod_irc, sql};
+replace_module(mod_last_odbc) -> {mod_last, sql};
+replace_module(mod_muc_odbc) -> {mod_muc, sql};
+replace_module(mod_offline_odbc) -> {mod_offline, sql};
+replace_module(mod_privacy_odbc) -> {mod_privacy, sql};
+replace_module(mod_private_odbc) -> {mod_private, sql};
+replace_module(mod_roster_odbc) -> {mod_roster, sql};
+replace_module(mod_shared_roster_odbc) -> {mod_shared_roster, sql};
+replace_module(mod_vcard_odbc) -> {mod_vcard, sql};
+replace_module(mod_vcard_xupdate_odbc) -> {mod_vcard_xupdate, sql};
+replace_module(mod_pubsub_odbc) -> {mod_pubsub, sql};
 replace_module(Module) ->
     case is_elixir_module(Module) of
         true  -> expand_elixir_module(Module);
@@ -985,7 +998,7 @@ transform_terms(Terms) ->
             mod_last,
             ejabberd_s2s,
             ejabberd_listener,
-            ejabberd_odbc_sup,
+            ejabberd_sql_sup,
             shaper,
             ejabberd_s2s_out,
             acl,
index 123189dde10b1e118a82e12db420b2ae21f4a39b..7580012393cf2a228af5999827591bd888ec7789 100644 (file)
@@ -28,8 +28,8 @@
 
 %%% Not implemented:
 %%% - write mod_piefxis with ejabberdctl commands
-%%% - Export from mod_offline_odbc.erl
-%%% - Export from mod_private_odbc.erl
+%%% - Export from mod_offline_sql.erl
+%%% - Export from mod_private_sql.erl
 %%% - XEP-227: 6. Security Considerations
 %%% - Other schemas of XInclude are not tested, and may not be imported correctly.
 %%% - If a host has many users, split that host in XML files with 50 users each.
index ae405db0a490673a7eaa03ae1d2fc6e52d35c6d1..5224b035b426ef4f9c44c334e179da665e8332e2 100644 (file)
 -include("logger.hrl").
 
 start() ->
-    file:delete(ejabberd_odbc:freetds_config()),
-    file:delete(ejabberd_odbc:odbc_config()),
-    file:delete(ejabberd_odbc:odbcinst_config()),
-    case lists:any(fun(H) -> needs_odbc(H) /= false end,
+    file:delete(ejabberd_sql:freetds_config()),
+    file:delete(ejabberd_sql:odbc_config()),
+    file:delete(ejabberd_sql:odbcinst_config()),
+    case lists:any(fun(H) -> needs_sql(H) /= false end,
                    ?MYHOSTS) of
         true ->
             start_hosts();
@@ -49,34 +49,34 @@ start() ->
 %% Start relationnal DB module on the nodes where it is needed
 start_hosts() ->
     lists:foreach(fun (Host) ->
-                         case needs_odbc(Host) of
-                           {true, App} -> start_odbc(Host, App);
+                         case needs_sql(Host) of
+                           {true, App} -> start_sql(Host, App);
                            false -> ok
                          end
                  end,
                  ?MYHOSTS).
 
-%% Start the ODBC module on the given host
-start_odbc(Host, App) ->
+%% Start the SQL module on the given host
+start_sql(Host, App) ->
     ejabberd:start_app(App),
     Supervisor_name = gen_mod:get_module_proc(Host,
-                                             ejabberd_odbc_sup),
+                                             ejabberd_sql_sup),
     ChildSpec = {Supervisor_name,
-                {ejabberd_odbc_sup, start_link, [Host]}, transient,
-                infinity, supervisor, [ejabberd_odbc_sup]},
+                {ejabberd_sql_sup, start_link, [Host]}, transient,
+                infinity, supervisor, [ejabberd_sql_sup]},
     case supervisor:start_child(ejabberd_sup, ChildSpec) of
       {ok, _PID} -> ok;
       _Error ->
          ?ERROR_MSG("Start of supervisor ~p failed:~n~p~nRetrying."
                     "..~n",
                     [Supervisor_name, _Error]),
-         start_odbc(Host, App)
+         start_sql(Host, App)
     end.
 
-%% Returns {true, App} if we have configured odbc for the given host
-needs_odbc(Host) ->
+%% Returns {true, App} if we have configured sql for the given host
+needs_sql(Host) ->
     LHost = jid:nameprep(Host),
-    case ejabberd_config:get_option({odbc_type, LHost},
+    case ejabberd_config:get_option({sql_type, LHost},
                                     fun(mysql) -> mysql;
                                        (pgsql) -> pgsql;
                                        (sqlite) -> sqlite;
@@ -91,11 +91,11 @@ needs_odbc(Host) ->
         undefined -> false
     end.
 
-opt_type(odbc_type) ->
+opt_type(sql_type) ->
     fun (mysql) -> mysql;
        (pgsql) -> pgsql;
        (sqlite) -> sqlite;
        (mssql) -> mssql;
        (odbc) -> odbc
     end;
-opt_type(_) -> [odbc_type].
+opt_type(_) -> [sql_type].
index 9170ae676af70ec8c5e89fc3f70290dda0909b04..b7fc39502c60a928d4a14e350f1661eb0ec11ebf 100644 (file)
@@ -814,7 +814,8 @@ make_sid() ->
 opt_type(sm_db_type) ->
     fun (mnesia) -> mnesia;
        (internal) -> mnesia;
-       (odbc) -> odbc;
+       (sql) -> sql;
+       (odbc) -> sql;
        (redis) -> redis
     end;
 opt_type(_) -> [sm_db_type].
index dfc0eb2a1e657b73b9090f813d2b02a66129da17..3d4e224d4fb2f6c14db548ce8f9c72ace588285c 100644 (file)
 %%%===================================================================
 -spec init() -> ok | {error, any()}.
 init() ->
-    Node = ejabberd_odbc:escape(jlib:atom_to_binary(node())),
+    Node = ejabberd_sql:escape(jlib:atom_to_binary(node())),
     ?INFO_MSG("Cleaning SQL SM table...", []),
     lists:foldl(
       fun(Host, ok) ->
-             case ejabberd_odbc:sql_query(
+             case ejabberd_sql:sql_query(
                     Host, [<<"delete from sm where node='">>, Node, <<"'">>]) of
                  {updated, _} ->
                      ok;
@@ -47,14 +47,14 @@ init() ->
 
 set_session(#session{sid = {Now, Pid}, usr = {U, LServer, R},
                     priority = Priority, info = Info}) ->
-    Username = ejabberd_odbc:escape(U),
-    Resource = ejabberd_odbc:escape(R),
-    InfoS = ejabberd_odbc:encode_term(Info),
+    Username = ejabberd_sql:escape(U),
+    Resource = ejabberd_sql:escape(R),
+    InfoS = ejabberd_sql:encode_term(Info),
     PrioS = enc_priority(Priority),
     TS = now_to_timestamp(Now),
     PidS = list_to_binary(erlang:pid_to_list(Pid)),
-    Node = ejabberd_odbc:escape(jlib:atom_to_binary(node(Pid))),
-    case odbc_queries:update(
+    Node = ejabberd_sql:escape(jlib:atom_to_binary(node(Pid))),
+    case sql_queries:update(
           LServer,
           <<"sm">>,
           [<<"usec">>, <<"pid">>, <<"node">>, <<"username">>,
@@ -70,12 +70,12 @@ set_session(#session{sid = {Now, Pid}, usr = {U, LServer, R},
 delete_session(_LUser, LServer, _LResource, {Now, Pid}) ->
     TS = now_to_timestamp(Now),
     PidS = list_to_binary(erlang:pid_to_list(Pid)),
-    case ejabberd_odbc:sql_query(
+    case ejabberd_sql:sql_query(
           LServer,
           [<<"select usec, pid, username, resource, priority, info ">>,
            <<"from sm where usec='">>, TS, <<"' and pid='">>,PidS, <<"'">>]) of
        {selected, _, [Row]} ->
-           ejabberd_odbc:sql_query(
+           ejabberd_sql:sql_query(
              LServer, [<<"delete from sm where usec='">>,
                        TS, <<"' and pid='">>, PidS, <<"'">>]),
            {ok, row_to_session(LServer, Row)};
@@ -93,7 +93,7 @@ get_sessions() ->
       end, ejabberd_sm:get_vh_by_backend(?MODULE)).
 
 get_sessions(LServer) ->
-    case ejabberd_odbc:sql_query(
+    case ejabberd_sql:sql_query(
           LServer, [<<"select usec, pid, username, ">>,
                     <<"resource, priority, info from sm">>]) of
        {selected, _, Rows} ->
@@ -104,8 +104,8 @@ get_sessions(LServer) ->
     end.
 
 get_sessions(LUser, LServer) ->
-    Username = ejabberd_odbc:escape(LUser),
-    case ejabberd_odbc:sql_query(
+    Username = ejabberd_sql:escape(LUser),
+    case ejabberd_sql:sql_query(
           LServer, [<<"select usec, pid, username, ">>,
                     <<"resource, priority, info from sm where ">>,
                     <<"username='">>, Username, <<"'">>]) of
@@ -117,9 +117,9 @@ get_sessions(LUser, LServer) ->
     end.
 
 get_sessions(LUser, LServer, LResource) ->
-    Username = ejabberd_odbc:escape(LUser),
-    Resource = ejabberd_odbc:escape(LResource),
-    case ejabberd_odbc:sql_query(
+    Username = ejabberd_sql:escape(LUser),
+    Resource = ejabberd_sql:escape(LResource),
+    case ejabberd_sql:sql_query(
           LServer, [<<"select usec, pid, username, ">>,
                     <<"resource, priority, info from sm where ">>,
                     <<"username='">>, Username, <<"' and resource='">>,
@@ -162,7 +162,7 @@ row_to_session(LServer, [USec, PidS, User, Resource, PrioS, InfoS]) ->
     Now = timestamp_to_now(USec),
     Pid = erlang:list_to_pid(binary_to_list(PidS)),
     Priority = dec_priority(PrioS),
-    Info = ejabberd_odbc:decode_term(InfoS),
+    Info = ejabberd_sql:decode_term(InfoS),
     #session{sid = {Now, Pid}, us = {User, LServer},
             usr = {User, LServer, Resource},
             priority = Priority,
similarity index 95%
rename from src/ejabberd_odbc.erl
rename to src/ejabberd_sql.erl
index f595933a1f452b81a9c5474d864d3890e13074eb..4bee08f7ed2c03d800209f2d4bbb37cb29645735 100644 (file)
@@ -23,7 +23,7 @@
 %%%
 %%%----------------------------------------------------------------------
 
--module(ejabberd_odbc).
+-module(ejabberd_sql).
 
 -behaviour(ejabberd_config).
 
@@ -75,9 +75,9 @@
         max_pending_requests_len            :: non_neg_integer(),
         pending_requests = {0, queue:new()} :: {non_neg_integer(), ?TQUEUE}}).
 
--define(STATE_KEY, ejabberd_odbc_state).
+-define(STATE_KEY, ejabberd_sql_state).
 
--define(NESTING_KEY, ejabberd_odbc_nesting_level).
+-define(NESTING_KEY, ejabberd_sql_nesting_level).
 
 -define(TOP_LEVEL_TXN, 0).
 
@@ -95,7 +95,7 @@
 
 -define(KEEPALIVE_QUERY, [<<"SELECT 1;">>]).
 
--define(PREPARE_KEY, ejabberd_odbc_prepare).
+-define(PREPARE_KEY, ejabberd_sql_prepare).
 
 %%-define(DBGFSM, true).
 
 %%% API
 %%%----------------------------------------------------------------------
 start(Host) ->
-    (?GEN_FSM):start(ejabberd_odbc, [Host],
+    (?GEN_FSM):start(ejabberd_sql, [Host],
                     fsm_limit_opts() ++ (?FSMOPTS)).
 
 start_link(Host, StartInterval) ->
-    (?GEN_FSM):start_link(ejabberd_odbc,
+    (?GEN_FSM):start_link(ejabberd_sql,
                          [Host, StartInterval],
                          fsm_limit_opts() ++ (?FSMOPTS)).
 
@@ -157,7 +157,7 @@ sql_bloc(Host, F) -> sql_call(Host, {sql_bloc, F}).
 sql_call(Host, Msg) ->
     case get(?STATE_KEY) of
       undefined ->
-        case ejabberd_odbc_sup:get_random_pid(Host) of
+        case ejabberd_sql_sup:get_random_pid(Host) of
           none -> {error, <<"Unknown Host">>};
           Pid ->
             (?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg,
@@ -190,7 +190,7 @@ sql_query_t(Query) ->
 
 %% Escape character that will confuse an SQL engine
 escape(S) ->
-       <<  <<(odbc_queries:escape(Char))/binary>> || <<Char>> <= S >>.
+       <<  <<(sql_queries:escape(Char))/binary>> || <<Char>> <= S >>.
 
 %% Escape character that will confuse an SQL engine
 %% Percent and underscore only need to be escaped for pattern matching like
@@ -199,7 +199,7 @@ escape_like(S) when is_binary(S) ->
     << <<(escape_like(C))/binary>> || <<C>> <= S >>;
 escape_like($%) -> <<"\\%">>;
 escape_like($_) -> <<"\\_">>;
-escape_like(C) when is_integer(C), C >= 0, C =< 255 -> odbc_queries:escape(C).
+escape_like(C) when is_integer(C), C >= 0, C =< 255 -> sql_queries:escape(C).
 
 escape_like_arg(S) when is_binary(S) ->
     << <<(escape_like_arg(C))/binary>> || <<C>> <= S >>;
@@ -232,7 +232,7 @@ sqlite_db(Host) ->
 
 -spec sqlite_file(binary()) -> string().
 sqlite_file(Host) ->
-    case ejabberd_config:get_option({odbc_database, Host},
+    case ejabberd_config:get_option({sql_database, Host},
                                    fun iolist_to_binary/1) of
        undefined ->
            {ok, Cwd} = file:get_cwd(),
@@ -247,7 +247,7 @@ sqlite_file(Host) ->
 %%%----------------------------------------------------------------------
 init([Host, StartInterval]) ->
     case ejabberd_config:get_option(
-           {odbc_keepalive_interval, Host},
+           {sql_keepalive_interval, Host},
            fun(I) when is_integer(I), I>0 -> I end) of
         undefined ->
             ok;
@@ -257,7 +257,7 @@ init([Host, StartInterval]) ->
     end,
     [DBType | _] = db_opts(Host),
     (?GEN_FSM):send_event(self(), connect),
-    ejabberd_odbc_sup:add_pid(Host, self()),
+    ejabberd_sql_sup:add_pid(Host, self()),
     {ok, connecting,
      #state{db_type = DBType, host = Host,
            max_pending_requests_len = max_fsm_queue(),
@@ -371,7 +371,7 @@ handle_info(Info, StateName, State) ->
     {next_state, StateName, State}.
 
 terminate(_Reason, _StateName, State) ->
-    ejabberd_odbc_sup:remove_pid(State#state.host, self()),
+    ejabberd_sql_sup:remove_pid(State#state.host, self()),
     case State#state.db_type of
         mysql -> catch p1_mysql_conn:stop(State#state.db_ref);
         sqlite -> catch sqlite3:close(sqlite_db(State#state.host));
@@ -869,14 +869,14 @@ log(Level, Format, Args) ->
     end.
 
 db_opts(Host) ->
-    Type = ejabberd_config:get_option({odbc_type, Host},
+    Type = ejabberd_config:get_option({sql_type, Host},
                                       fun(mysql) -> mysql;
                                          (pgsql) -> pgsql;
                                          (sqlite) -> sqlite;
                                         (mssql) -> mssql;
                                          (odbc) -> odbc
                                       end, odbc),
-    Server = ejabberd_config:get_option({odbc_server, Host},
+    Server = ejabberd_config:get_option({sql_server, Host},
                                         fun iolist_to_binary/1,
                                         <<"localhost">>),
     case Type of
@@ -886,20 +886,20 @@ db_opts(Host) ->
             [sqlite, Host];
         _ ->
             Port = ejabberd_config:get_option(
-                     {odbc_port, Host},
+                     {sql_port, Host},
                      fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
                      case Type of
                         mssql -> ?MSSQL_PORT;
                          mysql -> ?MYSQL_PORT;
                          pgsql -> ?PGSQL_PORT
                      end),
-            DB = ejabberd_config:get_option({odbc_database, Host},
+            DB = ejabberd_config:get_option({sql_database, Host},
                                             fun iolist_to_binary/1,
                                             <<"ejabberd">>),
-            User = ejabberd_config:get_option({odbc_username, Host},
+            User = ejabberd_config:get_option({sql_username, Host},
                                               fun iolist_to_binary/1,
                                               <<"ejabberd">>),
-            Pass = ejabberd_config:get_option({odbc_password, Host},
+            Pass = ejabberd_config:get_option({sql_password, Host},
                                               fun iolist_to_binary/1,
                                               <<"">>),
            case Type of
@@ -912,14 +912,14 @@ db_opts(Host) ->
     end.
 
 init_mssql(Host) ->
-    Server = ejabberd_config:get_option({odbc_server, Host},
+    Server = ejabberd_config:get_option({sql_server, Host},
                                         fun iolist_to_binary/1,
                                         <<"localhost">>),
     Port = ejabberd_config:get_option(
-            {odbc_port, Host},
+            {sql_port, Host},
             fun(P) when is_integer(P), P > 0, P < 65536 -> P end,
             ?MSSQL_PORT),
-    DB = ejabberd_config:get_option({odbc_database, Host},
+    DB = ejabberd_config:get_option({sql_database, Host},
                                    fun iolist_to_binary/1,
                                    <<"ejabberd">>),
     FreeTDS = io_lib:fwrite("[~s]~n"
@@ -1004,22 +1004,22 @@ check_error(Result, _Query) ->
 
 opt_type(max_fsm_queue) ->
     fun (N) when is_integer(N), N > 0 -> N end;
-opt_type(odbc_database) -> fun iolist_to_binary/1;
-opt_type(odbc_keepalive_interval) ->
+opt_type(sql_database) -> fun iolist_to_binary/1;
+opt_type(sql_keepalive_interval) ->
     fun (I) when is_integer(I), I > 0 -> I end;
-opt_type(odbc_password) -> fun iolist_to_binary/1;
-opt_type(odbc_port) ->
+opt_type(sql_password) -> fun iolist_to_binary/1;
+opt_type(sql_port) ->
     fun (P) when is_integer(P), P > 0, P < 65536 -> P end;
-opt_type(odbc_server) -> fun iolist_to_binary/1;
-opt_type(odbc_type) ->
+opt_type(sql_server) -> fun iolist_to_binary/1;
+opt_type(sql_type) ->
     fun (mysql) -> mysql;
        (pgsql) -> pgsql;
        (sqlite) -> sqlite;
        (mssql) -> mssql;
        (odbc) -> odbc
     end;
-opt_type(odbc_username) -> fun iolist_to_binary/1;
+opt_type(sql_username) -> fun iolist_to_binary/1;
 opt_type(_) ->
-    [max_fsm_queue, odbc_database, odbc_keepalive_interval,
-     odbc_password, odbc_port, odbc_server, odbc_type,
-     odbc_username].
+    [max_fsm_queue, sql_database, sql_keepalive_interval,
+     sql_password, sql_port, sql_server, sql_type,
+     sql_username].
index 660eac197674da9e800bae4d6945542e29c15bd1..47e4a07c7deaa74dfc9ddaf8dddc9ce621ab1d42 100644 (file)
@@ -163,7 +163,7 @@ parse1([$@, $( | S], Acc, State) ->
                 EVar;
             boolean ->
                 erl_syntax:application(
-                  erl_syntax:atom(ejabberd_odbc),
+                  erl_syntax:atom(ejabberd_sql),
                   erl_syntax:atom(to_bool),
                   [EVar])
         end,
@@ -348,7 +348,7 @@ make_sql_upsert_generic(Table, ParseRes) ->
     InsertBranch =
         erl_syntax:case_expr(
           erl_syntax:application(
-            erl_syntax:atom(ejabberd_odbc),
+            erl_syntax:atom(ejabberd_sql),
             erl_syntax:atom(sql_query_t),
             [Insert]),
           [erl_syntax:clause(
@@ -361,7 +361,7 @@ make_sql_upsert_generic(Table, ParseRes) ->
              [erl_syntax:variable("__UpdateRes")])]),
     erl_syntax:case_expr(
       erl_syntax:application(
-        erl_syntax:atom(ejabberd_odbc),
+        erl_syntax:atom(ejabberd_sql),
         erl_syntax:atom(sql_query_t),
         [Update]),
       [erl_syntax:clause(
@@ -453,7 +453,7 @@ make_sql_upsert_pgsql901(Table, ParseRes) ->
           ]),
     Upsert = make_sql_query(State),
     erl_syntax:application(
-      erl_syntax:atom(ejabberd_odbc),
+      erl_syntax:atom(ejabberd_sql),
       erl_syntax:atom(sql_query_t),
       [Upsert]).
 
similarity index 89%
rename from src/ejabberd_odbc_sup.erl
rename to src/ejabberd_sql_sup.erl
index 65fa3c1c6e267fac1a917da9fd89e87e991d1971..682414557e83b50bcb88ec42d6f018012171d4c8 100644 (file)
@@ -1,7 +1,7 @@
 %%%----------------------------------------------------------------------
-%%% File    : ejabberd_odbc_sup.erl
+%%% File    : ejabberd_sql_sup.erl
 %%% Author  : Alexey Shchepin <alexey@process-one.net>
-%%% Purpose : ODBC connections supervisor
+%%% Purpose : SQL connections supervisor
 %%% Created : 22 Dec 2004 by Alexey Shchepin <alexey@process-one.net>
 %%%
 %%%
@@ -23,7 +23,7 @@
 %%%
 %%%----------------------------------------------------------------------
 
--module(ejabberd_odbc_sup).
+-module(ejabberd_sql_sup).
 
 -behaviour(ejabberd_config).
 
@@ -42,7 +42,7 @@
 
 -define(DEFAULT_POOL_SIZE, 10).
 
--define(DEFAULT_ODBC_START_INTERVAL, 30).
+-define(DEFAULT_SQL_START_INTERVAL, 30).
 
 -define(CONNECT_TIMEOUT, 500).
 
@@ -62,14 +62,14 @@ start_link(Host) ->
 
 init([Host]) ->
     PoolSize = ejabberd_config:get_option(
-                 {odbc_pool_size, Host},
+                 {sql_pool_size, Host},
                  fun(I) when is_integer(I), I>0 -> I end,
                  ?DEFAULT_POOL_SIZE),
     StartInterval = ejabberd_config:get_option(
-                      {odbc_start_interval, Host},
+                      {sql_start_interval, Host},
                       fun(I) when is_integer(I), I>0 -> I end,
-                      ?DEFAULT_ODBC_START_INTERVAL),
-    Type = ejabberd_config:get_option({odbc_type, Host},
+                      ?DEFAULT_SQL_START_INTERVAL),
+    Type = ejabberd_config:get_option({sql_type, Host},
                                       fun(mysql) -> mysql;
                                          (pgsql) -> pgsql;
                                          (sqlite) -> sqlite;
@@ -80,7 +80,7 @@ init([Host]) ->
         sqlite ->
             check_sqlite_db(Host);
        mssql ->
-           ejabberd_odbc:init_mssql(Host);
+           ejabberd_sql:init_mssql(Host);
         _ ->
             ok
     end,
@@ -89,7 +89,7 @@ init([Host]) ->
      {{one_for_one, PoolSize * 10, 1},
       lists:map(fun (I) ->
                        {I,
-                        {ejabberd_odbc, start_link,
+                        {ejabberd_sql, start_link,
                          [Host, StartInterval * 1000]},
                         transient, 2000, worker, [?MODULE]}
                end,
@@ -121,12 +121,12 @@ transform_options(Opts) ->
     lists:foldl(fun transform_options/2, [], Opts).
 
 transform_options({odbc_server, {Type, Server, Port, DB, User, Pass}}, Opts) ->
-    [{odbc_type, Type},
-     {odbc_server, Server},
-     {odbc_port, Port},
-     {odbc_database, DB},
-     {odbc_username, User},
-     {odbc_password, Pass}|Opts];
+    [{sql_type, Type},
+     {sql_server, Server},
+     {sql_port, Port},
+     {sql_database, DB},
+     {sql_username, User},
+     {sql_password, Pass}|Opts];
 transform_options({odbc_server, {mysql, Server, DB, User, Pass}}, Opts) ->
     transform_options({odbc_server, {mysql, Server, ?MYSQL_PORT, DB, User, Pass}}, Opts);
 transform_options({odbc_server, {pgsql, Server, DB, User, Pass}}, Opts) ->
@@ -137,8 +137,8 @@ transform_options(Opt, Opts) ->
     [Opt|Opts].
 
 check_sqlite_db(Host) ->
-    DB = ejabberd_odbc:sqlite_db(Host),
-    File = ejabberd_odbc:sqlite_file(Host),
+    DB = ejabberd_sql:sqlite_db(Host),
+    File = ejabberd_sql:sqlite_file(Host),
     Ret = case filelib:ensure_dir(File) of
              ok ->
                  case sqlite3:open(DB, [{file, File}]) of
@@ -211,11 +211,11 @@ read_lines(Fd, File, Acc) ->
             []
     end.
 
-opt_type(odbc_pool_size) ->
+opt_type(sql_pool_size) ->
     fun (I) when is_integer(I), I > 0 -> I end;
-opt_type(odbc_start_interval) ->
+opt_type(sql_start_interval) ->
     fun (I) when is_integer(I), I > 0 -> I end;
-opt_type(odbc_type) ->
+opt_type(sql_type) ->
     fun (mysql) -> mysql;
        (pgsql) -> pgsql;
        (sqlite) -> sqlite;
@@ -223,4 +223,4 @@ opt_type(odbc_type) ->
        (odbc) -> odbc
     end;
 opt_type(_) ->
-    [odbc_pool_size, odbc_start_interval, odbc_type].
+    [sql_pool_size, sql_start_interval, sql_type].
index f525a4d39b5be82157b678caa556e95841c74462..3281f643094d08a9e786938bb976a992fdfac619 100644 (file)
@@ -2414,7 +2414,7 @@ node_backup_parse_query(Node, Query) ->
                                                     lists:keysearch(<<Action/binary,
                                                                       "host">>,
                                                                     1, Query),
-                                                ejabberd_cluster:call(Node, ejd2odbc,
+                                                ejabberd_cluster:call(Node, ejd2sql,
                                                          export, [Host, Path]);
                                            <<"import_file">> ->
                                                ejabberd_cluster:call(Node, ejabberd_admin,
similarity index 95%
rename from src/ejd2odbc.erl
rename to src/ejd2sql.erl
index 1df88470cbe1411efe0c8c8d5dba362d5f1a673f..aa74286edde64b943281282ec1fb24e4a7de3523 100644 (file)
@@ -1,5 +1,5 @@
 %%%----------------------------------------------------------------------
-%%% File    : ejd2odbc.erl
+%%% File    : ejd2sql.erl
 %%% Author  : Alexey Shchepin <alexey@process-one.net>
 %%% Purpose : Export some mnesia tables to SQL DB
 %%% Created : 22 Aug 2005 by Alexey Shchepin <alexey@process-one.net>
@@ -23,7 +23,7 @@
 %%%
 %%%----------------------------------------------------------------------
 
--module(ejd2odbc).
+-module(ejd2sql).
 
 -author('alexey@process-one.net').
 
@@ -43,7 +43,7 @@
 %%% A table can be converted from Mnesia to an ODBC database by calling
 %%% one of the API function with the following parameters:
 %%% - Server is the server domain you want to convert
-%%% - Output can be either odbc to export to the configured relational
+%%% - Output can be either sql to export to the configured relational
 %%%   database or "Filename" to export to text file.
 
 modules() ->
@@ -168,8 +168,8 @@ export(LServer, Table, IO, ConvertFun) ->
 
 output(_LServer, _Table, _IO, []) ->
     ok;
-output(LServer, _Table, odbc, SQLs) ->
-    ejabberd_odbc:sql_transaction(LServer, SQLs);
+output(LServer, _Table, sql, SQLs) ->
+    ejabberd_sql:sql_transaction(LServer, SQLs);
 output(_LServer, Table, Fd, SQLs) ->
     file:write(Fd, ["-- \n-- Mnesia table: ", atom_to_list(Table),
                     "\n--\n", SQLs]).
@@ -197,7 +197,7 @@ import(LServer, SelectQuery, IO, ConvertFun, Opts) ->
     F = case proplists:get_bool(fast, Opts) of
             true ->
                 fun() ->
-                        case ejabberd_odbc:sql_query_t(SelectQuery) of
+                        case ejabberd_sql:sql_query_t(SelectQuery) of
                             {selected, _, Rows} ->
                                 lists:foldl(fun process_sql_row/2,
                                             {IO, ConvertFun, undefined}, Rows);
@@ -207,16 +207,16 @@ import(LServer, SelectQuery, IO, ConvertFun, Opts) ->
                 end;
             false ->
                 fun() ->
-                        ejabberd_odbc:sql_query_t(
+                        ejabberd_sql:sql_query_t(
                           [iolist_to_binary(
                              [<<"declare c cursor for ">>, SelectQuery])]),
                         fetch(IO, ConvertFun, undefined)
                 end
         end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 fetch(IO, ConvertFun, PrevRow) ->
-    case ejabberd_odbc:sql_query_t([<<"fetch c;">>]) of
+    case ejabberd_sql:sql_query_t([<<"fetch c;">>]) of
         {selected, _, [Row]} ->
             process_sql_row(Row, {IO, ConvertFun, PrevRow}),
             fetch(IO, ConvertFun, Row);
index a290aa20a9416654dbb818d36e60f7156aff1bb1..26e662dc68d15d6532b812c6941b50ea2532b5a8 100644 (file)
@@ -48,7 +48,7 @@
          opts = [] :: opts() | '_' | '$2'}).
 
 -type opts() :: [{atom(), any()}].
--type db_type() :: odbc | mnesia | riak.
+-type db_type() :: sql | mnesia | riak.
 
 -callback start(binary(), opts()) -> any().
 -callback stop(binary()) -> any().
@@ -297,7 +297,8 @@ validate_opts(Module, Opts) ->
 
 -spec v_db(db_type() | internal) -> db_type().
 
-v_db(odbc) -> odbc;
+v_db(odbc) -> sql;
+v_db(sql) -> sql;
 v_db(internal) -> mnesia;
 v_db(mnesia) -> mnesia;
 v_db(riak) -> riak.
@@ -322,6 +323,7 @@ default_db(Host) ->
 -spec db_mod(binary() | global | db_type(), module()) -> module().
 
 db_mod(odbc, Module) -> list_to_atom(atom_to_list(Module) ++ "_sql");
+db_mod(sql, Module) -> list_to_atom(atom_to_list(Module) ++ "_sql");
 db_mod(mnesia, Module) -> list_to_atom(atom_to_list(Module) ++ "_mnesia");
 db_mod(riak, Module) -> list_to_atom(atom_to_list(Module) ++ "_riak");
 db_mod(Host, Module) when is_binary(Host) orelse Host == global ->
index cf10ffd85870831a7ad54911edf8e316129aa15d..692c8fae43a3e7de5b12127cb77b7f1f1412f606 100644 (file)
@@ -27,35 +27,35 @@ set_motd_users(LServer, USRs) ->
     F = fun() ->
                lists:foreach(
                  fun({U, _S, _R}) ->
-                         Username = ejabberd_odbc:escape(U),
-                         odbc_queries:update_t(
+                         Username = ejabberd_sql:escape(U),
+                         sql_queries:update_t(
                            <<"motd">>,
                            [<<"username">>, <<"xml">>],
                            [Username, <<"">>],
                            [<<"username='">>, Username, <<"'">>])
                  end, USRs)
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 set_motd(LServer, Packet) ->
-    XML = ejabberd_odbc:escape(fxml:element_to_binary(Packet)),
+    XML = ejabberd_sql:escape(fxml:element_to_binary(Packet)),
     F = fun() ->
-               odbc_queries:update_t(
+               sql_queries:update_t(
                  <<"motd">>,
                  [<<"username">>, <<"xml">>],
                  [<<"">>, XML],
                  [<<"username=''">>])
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 delete_motd(LServer) ->
     F = fun() ->
-               ejabberd_odbc:sql_query_t([<<"delete from motd;">>])
+               ejabberd_sql:sql_query_t([<<"delete from motd;">>])
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 get_motd(LServer) ->
-    case catch ejabberd_odbc:sql_query(
+    case catch ejabberd_sql:sql_query(
                  LServer, [<<"select xml from motd where username='';">>]) of
         {selected, [<<"xml">>], [[XML]]} ->
             case fxml_stream:parse_element(XML) of
@@ -69,8 +69,8 @@ get_motd(LServer) ->
     end.
 
 is_motd_user(LUser, LServer) ->
-    Username = ejabberd_odbc:escape(LUser),
-    case catch ejabberd_odbc:sql_query(
+    Username = ejabberd_sql:escape(LUser),
+    case catch ejabberd_sql:sql_query(
                 LServer,
                 [<<"select username from motd "
                    "where username='">>, Username, <<"';">>]) of
@@ -81,15 +81,15 @@ is_motd_user(LUser, LServer) ->
     end.
 
 set_motd_user(LUser, LServer) ->
-    Username = ejabberd_odbc:escape(LUser),
+    Username = ejabberd_sql:escape(LUser),
     F = fun() ->
-               odbc_queries:update_t(
+               sql_queries:update_t(
                  <<"motd">>,
                  [<<"username">>, <<"xml">>],
                  [Username, <<"">>],
                  [<<"username='">>, Username, <<"'">>])
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 export(_Server) ->
     [{motd,
@@ -97,7 +97,7 @@ export(_Server) ->
             when LServer == Host ->
               [[<<"delete from motd where username='';">>],
                [<<"insert into motd(username, xml) values ('', '">>,
-                ejabberd_odbc:escape(fxml:element_to_binary(El)),
+                ejabberd_sql:escape(fxml:element_to_binary(El)),
                 <<"');">>]];
          (_Host, _R) ->
               []
@@ -105,7 +105,7 @@ export(_Server) ->
      {motd_users,
       fun(Host, #motd_users{us = {LUser, LServer}})
             when LServer == Host, LUser /= <<"">> ->
-              Username = ejabberd_odbc:escape(LUser),
+              Username = ejabberd_sql:escape(LUser),
               [[<<"delete from motd where username='">>, Username, <<"';">>],
                [<<"insert into motd(username, xml) values ('">>,
                 Username, <<"', '');">>]];
index 8177adae87670ae4e12871218635adf81c1e1992..fb8380e2c53ae3e14dcf96016943fbb281c7f6db 100644 (file)
@@ -44,7 +44,7 @@ process_blocklist_block(LUser, LServer, Filter) ->
                mod_privacy_sql:sql_set_privacy_list(ID, NewRItems),
                {ok, Default, NewList}
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 unblock_by_filter(LUser, LServer, Filter) ->
     F = fun () ->
@@ -67,7 +67,7 @@ unblock_by_filter(LUser, LServer, Filter) ->
                    _ -> ok
                end
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 process_blocklist_get(LUser, LServer) ->
     case catch mod_privacy_sql:sql_get_default_privacy_list(LUser, LServer) of
index bd0f14f5eb4f7818f6fc485f93b113518e714232..3d5c360a8ad56458905c0f9e86ac526b9f9e90b3 100644 (file)
@@ -609,7 +609,7 @@ import_start(LServer, DBType) ->
     Mod:init(LServer, []),
     ok.
 
-import(_LServer, {odbc, _}, _DBType, <<"caps_features">>,
+import(_LServer, {sql, _}, _DBType, <<"caps_features">>,
        [Node, SubNode, Feature, _TimeStamp]) ->
     Feature1 = case catch jlib:binary_to_integer(Feature) of
                    I when is_integer(I), I>0 -> I;
@@ -642,7 +642,7 @@ import_next(LServer, DBType, NodePair) ->
             ejabberd_riak:put(
               #caps_features{node_pair = NodePair, features = Features},
              caps_features_schema());
-        _ when DBType == odbc ->
+        _ when DBType == sql ->
             ok
     end,
     import_next(LServer, DBType, ets:next(caps_features_tmp, NodePair)).
index 353b95b1bd7b34eaa1264330dfb90c447c70ac92..9f587db356376295ced18cfcae88da54c7ef0afc 100644 (file)
@@ -21,9 +21,9 @@ init(_Host, _Opts) ->
     ok.
 
 caps_read(LServer, {Node, SubNode}) ->
-    SNode = ejabberd_odbc:escape(Node),
-    SSubNode = ejabberd_odbc:escape(SubNode),
-    case ejabberd_odbc:sql_query(
+    SNode = ejabberd_sql:escape(Node),
+    SSubNode = ejabberd_sql:escape(SubNode),
+    case ejabberd_sql:sql_query(
           LServer, [<<"select feature from caps_features where ">>,
                     <<"node='">>, SNode, <<"' and subnode='">>,
                     SSubNode, <<"';">>]) of
@@ -39,7 +39,7 @@ caps_read(LServer, {Node, SubNode}) ->
     end.
 
 caps_write(LServer, NodePair, Features) ->
-    ejabberd_odbc:sql_transaction(
+    ejabberd_sql:sql_transaction(
       LServer,
       sql_write_features_t(NodePair, Features)).
 
@@ -56,8 +56,8 @@ export(_Server) ->
 %%% Internal functions
 %%%===================================================================
 sql_write_features_t({Node, SubNode}, Features) ->
-    SNode = ejabberd_odbc:escape(Node),
-    SSubNode = ejabberd_odbc:escape(SubNode),
+    SNode = ejabberd_sql:escape(Node),
+    SSubNode = ejabberd_sql:escape(SubNode),
     NewFeatures = if is_integer(Features) ->
                           [jlib:integer_to_binary(Features)];
                      true ->
@@ -67,5 +67,5 @@ sql_write_features_t({Node, SubNode}, Features) ->
       SNode, <<"' and subnode='">>, SSubNode, <<"';">>]|
      [[<<"insert into caps_features(node, subnode, feature) ">>,
        <<"values ('">>, SNode, <<"', '">>, SSubNode, <<"', '">>,
-       ejabberd_odbc:escape(F), <<"');">>] || F <- NewFeatures]].
+       ejabberd_sql:escape(F), <<"');">>] || F <- NewFeatures]].
 
index bf6dbb48e56fafc464ef3844d93f963b8d04b186..9a97d5728a5b557860eabb73d2f1da363e53d01c 100644 (file)
@@ -24,33 +24,33 @@ init(_Host, _Opts) ->
 
 get_data(LServer, Host, From) ->
     LJID = jid:tolower(jid:remove_resource(From)),
-    SJID = ejabberd_odbc:escape(jid:to_string(LJID)),
-    SHost = ejabberd_odbc:escape(Host),
-    case catch ejabberd_odbc:sql_query(
+    SJID = ejabberd_sql:escape(jid:to_string(LJID)),
+    SHost = ejabberd_sql:escape(Host),
+    case catch ejabberd_sql:sql_query(
                 LServer,
                 [<<"select data from irc_custom where jid='">>,
                  SJID, <<"' and host='">>, SHost,
                  <<"';">>]) of
        {selected, [<<"data">>], [[SData]]} ->
-           mod_irc:data_to_binary(From, ejabberd_odbc:decode_term(SData));
+           mod_irc:data_to_binary(From, ejabberd_sql:decode_term(SData));
        {'EXIT', _} -> error;
        {selected, _, _} -> empty
     end.
 
 set_data(LServer, Host, From, Data) ->
     LJID = jid:tolower(jid:remove_resource(From)),
-    SJID = ejabberd_odbc:escape(jid:to_string(LJID)),
-    SHost = ejabberd_odbc:escape(Host),
-    SData = ejabberd_odbc:encode_term(Data),
+    SJID = ejabberd_sql:escape(jid:to_string(LJID)),
+    SHost = ejabberd_sql:escape(Host),
+    SData = ejabberd_sql:encode_term(Data),
     F = fun () ->
-               odbc_queries:update_t(<<"irc_custom">>,
+               sql_queries:update_t(<<"irc_custom">>,
                                      [<<"jid">>, <<"host">>, <<"data">>],
                                      [SJID, SHost, SData],
                                      [<<"jid='">>, SJID, <<"' and host='">>,
                                       SHost, <<"'">>]),
                ok
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 export(_Server) ->
     [{irc_custom,
@@ -58,11 +58,11 @@ export(_Server) ->
                             data = Data}) ->
               case str:suffix(Host, IRCHost) of
                   true ->
-                      SJID = ejabberd_odbc:escape(
+                      SJID = ejabberd_sql:escape(
                                jid:to_string(
                                  jid:make(U, S, <<"">>))),
-                      SIRCHost = ejabberd_odbc:escape(IRCHost),
-                      SData = ejabberd_odbc:encode_term(Data),
+                      SIRCHost = ejabberd_sql:escape(IRCHost),
+                      SData = ejabberd_sql:encode_term(Data),
                       [[<<"delete from irc_custom where jid='">>, SJID,
                         <<"' and host='">>, SIRCHost, <<"';">>],
                        [<<"insert into irc_custom(jid, host, "
@@ -78,7 +78,7 @@ import(_LServer) ->
     [{<<"select jid, host, data from irc_custom;">>,
       fun([SJID, IRCHost, SData]) ->
               #jid{luser = U, lserver = S} = jid:from_string(SJID),
-              Data = ejabberd_odbc:decode_term(SData),
+              Data = ejabberd_sql:decode_term(SData),
               #irc_custom{us_host = {{U, S}, IRCHost},
                           data = Data}
       end}].
index edfa3763963e8c4e487b90570500656f94389e3f..5f67b14fcceba8d7a60913e1dc76b7ace1f0437e 100644 (file)
@@ -23,7 +23,7 @@ init(_Host, _Opts) ->
     ok.
 
 get_last(LUser, LServer) ->
-    case catch odbc_queries:get_last(LServer, LUser) of
+    case catch sql_queries:get_last(LServer, LUser) of
         {selected, []} ->
             not_found;
         {selected, [{TimeStamp, Status}]} ->
@@ -35,10 +35,10 @@ get_last(LUser, LServer) ->
     end.
 
 store_last_info(LUser, LServer, TimeStamp, Status) ->
-    odbc_queries:set_last_t(LServer, LUser, TimeStamp, Status).
+    sql_queries:set_last_t(LServer, LUser, TimeStamp, Status).
 
 remove_user(LUser, LServer) ->
-    odbc_queries:del_last(LServer, LUser).
+    sql_queries:del_last(LServer, LUser).
 
 import(_LServer, _LA) ->
     pass.
@@ -48,10 +48,10 @@ export(_Server) ->
       fun(Host, #last_activity{us = {LUser, LServer},
                                timestamp = TimeStamp, status = Status})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
+              Username = ejabberd_sql:escape(LUser),
               Seconds =
-                  ejabberd_odbc:escape(jlib:integer_to_binary(TimeStamp)),
-              State = ejabberd_odbc:escape(Status),
+                  ejabberd_sql:escape(jlib:integer_to_binary(TimeStamp)),
+              State = ejabberd_sql:escape(Status),
               [[<<"delete from last where username='">>, Username, <<"';">>],
                [<<"insert into last(username, seconds, "
                   "state) values ('">>,
index 098ee8967a3c04c27ab055011ff25df7b55000f0..f84519a080bbb4bc72533f0a9dac94c0d1390dd6 100644 (file)
@@ -344,7 +344,7 @@ delete_old_messages(TypeBin, Days) when TypeBin == <<"chat">>;
                lists:map(
                  fun(Host) ->
                          case gen_mod:db_type(Host, ?MODULE) of
-                             odbc -> {odbc, Host};
+                             sql -> {sql, Host};
                              Other -> {Other, global}
                          end
                  end, ?MYHOSTS)),
@@ -1018,7 +1018,8 @@ mod_opt_type(cache_life_time) ->
 mod_opt_type(cache_size) ->
     fun (I) when is_integer(I), I > 0 -> I end;
 mod_opt_type(db_type) ->
-    fun(odbc) -> odbc;
+    fun(sql) -> sql;
+       (odbc) -> sql;
        (internal) -> mnesia;
        (mnesia) -> mnesia
     end;
index 1f24de3170d185d6d4e982d950e885a2ecc42b48..69fdf32388abb535346bd0a0896eba624626c284 100644 (file)
@@ -26,11 +26,11 @@ init(_Host, _Opts) ->
     ok.
 
 remove_user(LUser, LServer) ->
-    SUser = ejabberd_odbc:escape(LUser),
-    ejabberd_odbc:sql_query(
+    SUser = ejabberd_sql:escape(LUser),
+    ejabberd_sql:sql_query(
       LServer,
       [<<"delete from archive where username='">>, SUser, <<"';">>]),
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       [<<"delete from archive_prefs where username='">>, SUser, <<"';">>]).
 
@@ -43,7 +43,7 @@ delete_old_messages(ServerHost, TimeStamp, Type) ->
                    true -> [<<" and kind='">>, jlib:atom_to_binary(Type), <<"'">>]
                 end,
     TS = integer_to_binary(now_to_usec(TimeStamp)),
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       ServerHost, [<<"delete from archive where timestamp<">>,
                   TS, TypeClause, <<";">>]),
     ok.
@@ -67,18 +67,18 @@ store(Pkt, LServer, {LUser, LHost}, Type, Peer, Nick, _Dir) ->
              jid:tolower(Peer)),
     XML = fxml:element_to_binary(Pkt),
     Body = fxml:get_subtag_cdata(Pkt, <<"body">>),
-    case ejabberd_odbc:sql_query(
+    case ejabberd_sql:sql_query(
            LServer,
            [<<"insert into archive (username, timestamp, "
                    "peer, bare_peer, xml, txt, kind, nick) values (">>,
-               <<"'">>, ejabberd_odbc:escape(SUser), <<"', ">>,
+               <<"'">>, ejabberd_sql:escape(SUser), <<"', ">>,
                <<"'">>, TS, <<"', ">>,
-               <<"'">>, ejabberd_odbc:escape(LPeer), <<"', ">>,
-               <<"'">>, ejabberd_odbc:escape(BarePeer), <<"', ">>,
-               <<"'">>, ejabberd_odbc:escape(XML), <<"', ">>,
-               <<"'">>, ejabberd_odbc:escape(Body), <<"', ">>,
+               <<"'">>, ejabberd_sql:escape(LPeer), <<"', ">>,
+               <<"'">>, ejabberd_sql:escape(BarePeer), <<"', ">>,
+               <<"'">>, ejabberd_sql:escape(XML), <<"', ">>,
+               <<"'">>, ejabberd_sql:escape(Body), <<"', ">>,
                <<"'">>, jlib:atom_to_binary(Type), <<"', ">>,
-               <<"'">>, ejabberd_odbc:escape(Nick), <<"');">>]) of
+               <<"'">>, ejabberd_sql:escape(Nick), <<"');">>]) of
        {updated, _} ->
            {ok, ID};
        Err ->
@@ -89,10 +89,10 @@ write_prefs(LUser, _LServer, #archive_prefs{default = Default,
                                           never = Never,
                                           always = Always},
            ServerHost) ->
-    SUser = ejabberd_odbc:escape(LUser),
+    SUser = ejabberd_sql:escape(LUser),
     SDefault = erlang:atom_to_binary(Default, utf8),
-    SAlways = ejabberd_odbc:encode_term(Always),
-    SNever = ejabberd_odbc:encode_term(Never),
+    SAlways = ejabberd_sql:encode_term(Always),
+    SNever = ejabberd_sql:encode_term(Never),
     case update(ServerHost, <<"archive_prefs">>,
                [<<"username">>, <<"def">>, <<"always">>, <<"never">>],
                [SUser, SDefault, SAlways, SNever],
@@ -104,15 +104,15 @@ write_prefs(LUser, _LServer, #archive_prefs{default = Default,
     end.
 
 get_prefs(LUser, LServer) ->
-    case ejabberd_odbc:sql_query(
+    case ejabberd_sql:sql_query(
           LServer,
           [<<"select def, always, never from archive_prefs ">>,
            <<"where username='">>,
-           ejabberd_odbc:escape(LUser), <<"';">>]) of
+           ejabberd_sql:escape(LUser), <<"';">>]) of
        {selected, _, [[SDefault, SAlways, SNever]]} ->
            Default = erlang:binary_to_existing_atom(SDefault, utf8),
-           Always = ejabberd_odbc:decode_term(SAlways),
-           Never = ejabberd_odbc:decode_term(SNever),
+           Always = ejabberd_sql:decode_term(SAlways),
+           Never = ejabberd_sql:decode_term(SNever),
            {ok, #archive_prefs{us = {LUser, LServer},
                    default = Default,
                    always = Always,
@@ -135,8 +135,8 @@ select(LServer, JidRequestor, #jid{luser = LUser} = JidArchive,
     % and the client did not specify a limit using RSM then the server should
     % return a policy-violation error to the client." We currently don't do this
     % for v0.2 requests, but we do limit #rsm_in.max for v0.3 and newer.
-    case {ejabberd_odbc:sql_query(LServer, Query),
-         ejabberd_odbc:sql_query(LServer, CountQuery)} of
+    case {ejabberd_sql:sql_query(LServer, Query),
+         ejabberd_sql:sql_query(LServer, CountQuery)} of
        {{selected, _, Res}, {selected, _, [[Count]]}} ->
            {Max, Direction} = case RSM of
                                   #rsm_in{max = M, direction = D} -> {M, D};
@@ -206,8 +206,8 @@ make_sql_query(User, LServer, Start, End, With, RSM) ->
            {none, none, <<>>}
     end,
     ODBCType = ejabberd_config:get_option(
-                {odbc_type, LServer},
-                ejabberd_odbc:opt_type(odbc_type)),
+                {sql_type, LServer},
+                ejabberd_sql:opt_type(sql_type)),
     LimitClause = if is_integer(Max), Max >= 0, ODBCType /= mssql ->
                          [<<" limit ">>, jlib:integer_to_binary(Max+1)];
                     true ->
@@ -223,14 +223,14 @@ make_sql_query(User, LServer, Start, End, With, RSM) ->
                         [];
                     {text, Txt} ->
                         [<<" and match (txt) against ('">>,
-                         ejabberd_odbc:escape(Txt), <<"')">>];
+                         ejabberd_sql:escape(Txt), <<"')">>];
                     {_, _, <<>>} ->
                         [<<" and bare_peer='">>,
-                         ejabberd_odbc:escape(jid:to_string(With)),
+                         ejabberd_sql:escape(jid:to_string(With)),
                          <<"'">>];
                     {_, _, _} ->
                         [<<" and peer='">>,
-                         ejabberd_odbc:escape(jid:to_string(With)),
+                         ejabberd_sql:escape(jid:to_string(With)),
                          <<"'">>];
                     none ->
                         []
@@ -262,7 +262,7 @@ make_sql_query(User, LServer, Start, End, With, RSM) ->
                    _ ->
                        []
                end,
-    SUser = ejabberd_odbc:escape(User),
+    SUser = ejabberd_sql:escape(User),
 
     Query = [<<"SELECT ">>, TopClause, <<" timestamp, xml, peer, kind, nick"
              " FROM archive WHERE username='">>,
@@ -291,14 +291,14 @@ update(LServer, Table, Fields, Vals, Where) ->
                                   <<A/binary, "='", B/binary, "'">>
                           end,
                           Fields, Vals),
-    case ejabberd_odbc:sql_query(LServer,
+    case ejabberd_sql:sql_query(LServer,
                                 [<<"update ">>, Table, <<" set ">>,
                                  join(UPairs, <<", ">>), <<" where ">>, Where,
                                  <<";">>])
        of
        {updated, 1} -> {updated, 1};
        _ ->
-           ejabberd_odbc:sql_query(LServer,
+           ejabberd_sql:sql_query(LServer,
                                    [<<"insert into ">>, Table, <<"(">>,
                                     join(Fields, <<", ">>), <<") values ('">>,
                                     join(Vals, <<"', '">>), <<"');">>])
index 9acd9f8d75c66c6ce5cbca46cfca92add2c56905..55628d43e04e2f2d4ff1bb1d952881bf2a64143f 100644 (file)
@@ -26,46 +26,46 @@ init(_Host, _Opts) ->
     ok.
 
 store_room(LServer, Host, Name, Opts) ->
-    SName = ejabberd_odbc:escape(Name),
-    SHost = ejabberd_odbc:escape(Host),
-    SOpts = ejabberd_odbc:encode_term(Opts),
+    SName = ejabberd_sql:escape(Name),
+    SHost = ejabberd_sql:escape(Host),
+    SOpts = ejabberd_sql:encode_term(Opts),
     F = fun () ->
-               odbc_queries:update_t(<<"muc_room">>,
+               sql_queries:update_t(<<"muc_room">>,
                                      [<<"name">>, <<"host">>, <<"opts">>],
                                      [SName, SHost, SOpts],
                                      [<<"name='">>, SName, <<"' and host='">>,
                                       SHost, <<"'">>])
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 restore_room(LServer, Host, Name) ->
-    SName = ejabberd_odbc:escape(Name),
-    SHost = ejabberd_odbc:escape(Host),
-    case catch ejabberd_odbc:sql_query(LServer,
+    SName = ejabberd_sql:escape(Name),
+    SHost = ejabberd_sql:escape(Host),
+    case catch ejabberd_sql:sql_query(LServer,
                                       [<<"select opts from muc_room where name='">>,
                                        SName, <<"' and host='">>, SHost,
                                        <<"';">>]) of
        {selected, [<<"opts">>], [[Opts]]} ->
-           mod_muc:opts_to_binary(ejabberd_odbc:decode_term(Opts));
+           mod_muc:opts_to_binary(ejabberd_sql:decode_term(Opts));
        _ ->
            error
     end.
 
 forget_room(LServer, Host, Name) ->
-    SName = ejabberd_odbc:escape(Name),
-    SHost = ejabberd_odbc:escape(Host),
+    SName = ejabberd_sql:escape(Name),
+    SHost = ejabberd_sql:escape(Host),
     F = fun () ->
-               ejabberd_odbc:sql_query_t([<<"delete from muc_room where name='">>,
+               ejabberd_sql:sql_query_t([<<"delete from muc_room where name='">>,
                                           SName, <<"' and host='">>, SHost,
                                           <<"';">>])
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 can_use_nick(LServer, Host, JID, Nick) ->
     SJID = jid:to_string(jid:tolower(jid:remove_resource(JID))),
-    SNick = ejabberd_odbc:escape(Nick),
-    SHost = ejabberd_odbc:escape(Host),
-    case catch ejabberd_odbc:sql_query(LServer,
+    SNick = ejabberd_sql:escape(Nick),
+    SHost = ejabberd_sql:escape(Host),
+    case catch ejabberd_sql:sql_query(LServer,
                                       [<<"select jid from muc_registered ">>,
                                        <<"where nick='">>, SNick,
                                        <<"' and host='">>, SHost, <<"';">>]) of
@@ -74,8 +74,8 @@ can_use_nick(LServer, Host, JID, Nick) ->
     end.
 
 get_rooms(LServer, Host) ->
-    SHost = ejabberd_odbc:escape(Host),
-    case catch ejabberd_odbc:sql_query(LServer,
+    SHost = ejabberd_sql:escape(Host),
+    case catch ejabberd_sql:sql_query(LServer,
                                       [<<"select name, opts from muc_room ">>,
                                        <<"where host='">>, SHost, <<"';">>]) of
        {selected, [<<"name">>, <<"opts">>], RoomOpts} ->
@@ -83,7 +83,7 @@ get_rooms(LServer, Host) ->
              fun([Room, Opts]) ->
                      #muc_room{name_host = {Room, Host},
                                opts = mod_muc:opts_to_binary(
-                                        ejabberd_odbc:decode_term(Opts))}
+                                        ejabberd_sql:decode_term(Opts))}
              end, RoomOpts);
        Err ->
            ?ERROR_MSG("failed to get rooms: ~p", [Err]),
@@ -91,9 +91,9 @@ get_rooms(LServer, Host) ->
     end.
 
 get_nick(LServer, Host, From) ->
-    SJID = ejabberd_odbc:escape(jid:to_string(jid:tolower(jid:remove_resource(From)))),
-    SHost = ejabberd_odbc:escape(Host),
-    case catch ejabberd_odbc:sql_query(LServer,
+    SJID = ejabberd_sql:escape(jid:to_string(jid:tolower(jid:remove_resource(From)))),
+    SHost = ejabberd_sql:escape(Host),
+    case catch ejabberd_sql:sql_query(LServer,
                                       [<<"select nick from muc_registered where "
                                          "jid='">>,
                                        SJID, <<"' and host='">>, SHost,
@@ -104,20 +104,20 @@ get_nick(LServer, Host, From) ->
 
 set_nick(LServer, Host, From, Nick) ->
     JID = jid:to_string(jid:tolower(jid:remove_resource(From))),
-    SJID = ejabberd_odbc:escape(JID),
-    SNick = ejabberd_odbc:escape(Nick),
-    SHost = ejabberd_odbc:escape(Host),
+    SJID = ejabberd_sql:escape(JID),
+    SNick = ejabberd_sql:escape(Nick),
+    SHost = ejabberd_sql:escape(Host),
     F = fun () ->
                case Nick of
                    <<"">> ->
-                       ejabberd_odbc:sql_query_t(
+                       ejabberd_sql:sql_query_t(
                          [<<"delete from muc_registered where ">>,
                           <<"jid='">>, SJID,
                           <<"' and host='">>, Host,
                           <<"';">>]),
                        ok;
                    _ ->
-                       Allow = case ejabberd_odbc:sql_query_t(
+                       Allow = case ejabberd_sql:sql_query_t(
                                       [<<"select jid from muc_registered ">>,
                                        <<"where nick='">>,
                                        SNick,
@@ -127,7 +127,7 @@ set_nick(LServer, Host, From, Nick) ->
                                    _ -> true
                                end,
                        if Allow ->
-                               odbc_queries:update_t(<<"muc_registered">>,
+                               sql_queries:update_t(<<"muc_registered">>,
                                                      [<<"jid">>, <<"host">>,
                                                       <<"nick">>],
                                                      [SJID, SHost, SNick],
@@ -140,16 +140,16 @@ set_nick(LServer, Host, From, Nick) ->
                        end
                end
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 export(_Server) ->
     [{muc_room,
       fun(Host, #muc_room{name_host = {Name, RoomHost}, opts = Opts}) ->
               case str:suffix(Host, RoomHost) of
                   true ->
-                      SName = ejabberd_odbc:escape(Name),
-                      SRoomHost = ejabberd_odbc:escape(RoomHost),
-                      SOpts = ejabberd_odbc:encode_term(Opts),
+                      SName = ejabberd_sql:escape(Name),
+                      SRoomHost = ejabberd_sql:escape(RoomHost),
+                      SOpts = ejabberd_sql:encode_term(Opts),
                       [[<<"delete from muc_room where name='">>, SName,
                         <<"' and host='">>, SRoomHost, <<"';">>],
                        [<<"insert into muc_room(name, host, opts) ",
@@ -165,11 +165,11 @@ export(_Server) ->
                                 nick = Nick}) ->
               case str:suffix(Host, RoomHost) of
                   true ->
-                      SJID = ejabberd_odbc:escape(
+                      SJID = ejabberd_sql:escape(
                                jid:to_string(
                                  jid:make(U, S, <<"">>))),
-                      SNick = ejabberd_odbc:escape(Nick),
-                      SRoomHost = ejabberd_odbc:escape(RoomHost),
+                      SNick = ejabberd_sql:escape(Nick),
+                      SRoomHost = ejabberd_sql:escape(RoomHost),
                       [[<<"delete from muc_registered where jid='">>,
                         SJID, <<"' and host='">>, SRoomHost, <<"';">>],
                        [<<"insert into muc_registered(jid, host, "
@@ -184,7 +184,7 @@ export(_Server) ->
 import(_LServer) ->
     [{<<"select name, host, opts from muc_room;">>,
       fun([Name, RoomHost, SOpts]) ->
-              Opts = mod_muc:opts_to_binary(ejabberd_odbc:decode_term(SOpts)),
+              Opts = mod_muc:opts_to_binary(ejabberd_sql:decode_term(SOpts)),
               #muc_room{name_host = {Name, RoomHost}, opts = Opts}
       end},
      {<<"select jid, host, nick from muc_registered;">>,
index 2cdd82ae8a297babaae016441ad4245f66a5ee72..356d89a67f3f6627f8d011bea72fc38ad8b42c8a 100644 (file)
@@ -243,7 +243,7 @@ receive_all(US, Msgs, DBType) ->
       after 0 ->
                case DBType of
                  mnesia -> Msgs;
-                 odbc -> lists:reverse(Msgs);
+                 sql -> lists:reverse(Msgs);
                  riak -> Msgs
                end
     end.
index 37b90163dbf7c4668e41f9fd987a65ca8fa75cf2..4d9455570b0476fb1b489acde028bfe091474091 100644 (file)
@@ -39,7 +39,7 @@ store_messages(Host, {User, _Server}, Msgs, Len, MaxOfflineMsgs) ->
            Query = lists:map(
                      fun(M) ->
                              Username =
-                                 ejabberd_odbc:escape((M#offline_msg.to)#jid.luser),
+                                 ejabberd_sql:escape((M#offline_msg.to)#jid.luser),
                              From = M#offline_msg.from,
                              To = M#offline_msg.to,
                              Packet =
@@ -50,15 +50,15 @@ store_messages(Host, {User, _Server}, Msgs, Len, MaxOfflineMsgs) ->
                                                      M#offline_msg.timestamp,
                                                      <<"Offline Storage">>),
                              XML =
-                                 ejabberd_odbc:escape(fxml:element_to_binary(NewPacket)),
-                                    odbc_queries:add_spool_sql(Username, XML)
+                                 ejabberd_sql:escape(fxml:element_to_binary(NewPacket)),
+                                    sql_queries:add_spool_sql(Username, XML)
                      end,
                      Msgs),
-           odbc_queries:add_spool(Host, Query)
+           sql_queries:add_spool(Host, Query)
     end.
 
 pop_messages(LUser, LServer) ->
-    case odbc_queries:get_and_del_spool_msg_t(LServer, LUser) of
+    case sql_queries:get_and_del_spool_msg_t(LServer, LUser) of
        {atomic, {selected, Rs}} ->
            {ok, lists:flatmap(
                   fun({_, XML}) ->
@@ -78,7 +78,7 @@ remove_expired_messages(_LServer) ->
     {atomic, ok}.
 
 remove_old_messages(Days, LServer) ->
-    case catch ejabberd_odbc:sql_query(
+    case catch ejabberd_sql:sql_query(
                 LServer,
                 [<<"DELETE FROM spool"
                   " WHERE created_at < "
@@ -92,11 +92,11 @@ remove_old_messages(Days, LServer) ->
     {atomic, ok}.
 
 remove_user(LUser, LServer) ->
-    odbc_queries:del_spool_msg(LServer, LUser).
+    sql_queries:del_spool_msg(LServer, LUser).
 
 read_message_headers(LUser, LServer) ->
-    Username = ejabberd_odbc:escape(LUser),
-    case catch ejabberd_odbc:sql_query(
+    Username = ejabberd_sql:escape(LUser),
+    case catch ejabberd_sql:sql_query(
                 LServer, [<<"select xml, seq from spool where username ='">>,
                           Username, <<"' order by seq;">>]) of
        {selected, [<<"xml">>, <<"seq">>], Rows} ->
@@ -117,9 +117,9 @@ read_message_headers(LUser, LServer) ->
     end.
 
 read_message(LUser, LServer, Seq) ->
-    Username = ejabberd_odbc:escape(LUser),
-    SSeq = ejabberd_odbc:escape(integer_to_binary(Seq)),
-    case ejabberd_odbc:sql_query(
+    Username = ejabberd_sql:escape(LUser),
+    SSeq = ejabberd_sql:escape(integer_to_binary(Seq)),
+    case ejabberd_sql:sql_query(
           LServer,
           [<<"select xml from spool  where username='">>, Username,
            <<"'  and seq='">>, SSeq, <<"';">>]) of
@@ -135,16 +135,16 @@ read_message(LUser, LServer, Seq) ->
     end.
 
 remove_message(LUser, LServer, Seq) ->
-    Username = ejabberd_odbc:escape(LUser),
-    SSeq = ejabberd_odbc:escape(integer_to_binary(Seq)),
-    ejabberd_odbc:sql_query(
+    Username = ejabberd_sql:escape(LUser),
+    SSeq = ejabberd_sql:escape(integer_to_binary(Seq)),
+    ejabberd_sql:sql_query(
       LServer,
       [<<"delete from spool  where username='">>, Username,
        <<"'  and seq='">>, SSeq, <<"';">>]),
     ok.
 
 read_all_messages(LUser, LServer) ->
-    case catch ejabberd_odbc:sql_query(
+    case catch ejabberd_sql:sql_query(
                  LServer,
                  ?SQL("select @(xml)s from spool where "
                       "username=%(LUser)s order by seq")) of
@@ -161,11 +161,11 @@ read_all_messages(LUser, LServer) ->
     end.
 
 remove_all_messages(LUser, LServer) ->
-    odbc_queries:del_spool_msg(LServer, LUser),
+    sql_queries:del_spool_msg(LServer, LUser),
     {atomic, ok}.
 
 count_messages(LUser, LServer) ->
-    case catch ejabberd_odbc:sql_query(
+    case catch ejabberd_sql:sql_query(
                  LServer,
                  ?SQL("select @(count(*))d from spool "
                       "where username=%(LUser)s")) of
@@ -180,11 +180,11 @@ export(_Server) ->
                              timestamp = TimeStamp, from = From, to = To,
                              packet = Packet})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
+              Username = ejabberd_sql:escape(LUser),
               Packet1 = jlib:replace_from_to(From, To, Packet),
               Packet2 = jlib:add_delay_info(Packet1, LServer, TimeStamp,
                                             <<"Offline Storage">>),
-              XML = ejabberd_odbc:escape(fxml:element_to_binary(Packet2)),
+              XML = ejabberd_sql:escape(fxml:element_to_binary(Packet2)),
               [[<<"delete from spool where username='">>, Username, <<"';">>],
                [<<"insert into spool(username, xml) values ('">>,
                 Username, <<"', '">>, XML, <<"');">>]];
index ffaf551887cecbfc45e35424a14cf93270a0a2bb..6b996fa8b462a299e42089b5130ecb6b38652d5a 100644 (file)
@@ -77,7 +77,7 @@ process_default_set(LUser, LServer, {value, Name}) ->
                      end
                end
        end,
-    odbc_queries:sql_transaction(LServer, F);
+    sql_queries:sql_transaction(LServer, F);
 process_default_set(LUser, LServer, false) ->
     case catch sql_unset_default_privacy_list(LUser,
                                              LServer)
@@ -110,7 +110,7 @@ remove_privacy_list(LUser, LServer, Name) ->
                      end
                end
        end,
-    odbc_queries:sql_transaction(LServer, F).
+    sql_queries:sql_transaction(LServer, F).
 
 set_privacy_list(#privacy{us = {LUser, LServer},
                          default = Default,
@@ -131,7 +131,7 @@ set_privacy_list(#privacy{us = {LUser, LServer},
                          end
                  end, Lists)
        end,
-    odbc_queries:sql_transaction(LServer, F).
+    sql_queries:sql_transaction(LServer, F).
 
 set_privacy_list(LUser, LServer, Name, List) ->
     RItems = lists:map(fun item_to_raw/1, List),
@@ -147,7 +147,7 @@ set_privacy_list(LUser, LServer, Name, List) ->
                sql_set_privacy_list(ID, RItems),
                ok
        end,
-    odbc_queries:sql_transaction(LServer, F).
+    sql_queries:sql_transaction(LServer, F).
 
 get_user_list(LUser, LServer) ->
     case catch sql_get_default_privacy_list(LUser, LServer)
@@ -196,7 +196,7 @@ remove_user(LUser, LServer) ->
     sql_del_privacy_lists(LUser, LServer).
 
 export(Server) ->
-    case catch ejabberd_odbc:sql_query(jid:nameprep(Server),
+    case catch ejabberd_sql:sql_query(jid:nameprep(Server),
                                 [<<"select id from privacy_list order by "
                                    "id desc limit 1;">>]) of
         {selected, [<<"id">>], [[I]]} ->
@@ -208,9 +208,9 @@ export(Server) ->
       fun(Host, #privacy{us = {LUser, LServer}, lists = Lists,
                          default = Default})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
+              Username = ejabberd_sql:escape(LUser),
               if Default /= none ->
-                      SDefault = ejabberd_odbc:escape(Default),
+                      SDefault = ejabberd_sql:escape(Default),
                       [[<<"delete from privacy_default_list where ">>,
                         <<"username='">>, Username, <<"';">>],
                        [<<"insert into privacy_default_list(username, "
@@ -222,7 +222,7 @@ export(Server) ->
               end ++
                   lists:flatmap(
                     fun({Name, List}) ->
-                            SName = ejabberd_odbc:escape(Name),
+                            SName = ejabberd_sql:escape(Name),
                             RItems = lists:map(fun item_to_raw/1, List),
                             ID = jlib:integer_to_binary(get_id()),
                             [[<<"delete from privacy_list where username='">>,
@@ -329,8 +329,8 @@ item_to_raw(#listitem{type = Type, value = Value,
                        none -> {<<"n">>, <<"">>};
                        jid ->
                            {<<"j">>,
-                            ejabberd_odbc:escape(jid:to_string(Value))};
-                       group -> {<<"g">>, ejabberd_odbc:escape(Value)};
+                            ejabberd_sql:escape(jid:to_string(Value))};
+                       group -> {<<"g">>, ejabberd_sql:escape(Value)};
                        subscription ->
                            case Value of
                              none -> {<<"s">>, <<"none">>};
@@ -347,51 +347,51 @@ item_to_raw(#listitem{type = Type, value = Value,
      MatchMessage, MatchPresenceIn, MatchPresenceOut}.
 
 sql_get_default_privacy_list(LUser, LServer) ->
-    odbc_queries:get_default_privacy_list(LServer, LUser).
+    sql_queries:get_default_privacy_list(LServer, LUser).
 
 sql_get_default_privacy_list_t(LUser) ->
-    odbc_queries:get_default_privacy_list_t(LUser).
+    sql_queries:get_default_privacy_list_t(LUser).
 
 sql_get_privacy_list_names(LUser, LServer) ->
-    odbc_queries:get_privacy_list_names(LServer, LUser).
+    sql_queries:get_privacy_list_names(LServer, LUser).
 
 sql_get_privacy_list_names_t(LUser) ->
-    odbc_queries:get_privacy_list_names_t(LUser).
+    sql_queries:get_privacy_list_names_t(LUser).
 
 sql_get_privacy_list_id(LUser, LServer, Name) ->
-    odbc_queries:get_privacy_list_id(LServer, LUser, Name).
+    sql_queries:get_privacy_list_id(LServer, LUser, Name).
 
 sql_get_privacy_list_id_t(LUser, Name) ->
-    odbc_queries:get_privacy_list_id_t(LUser, Name).
+    sql_queries:get_privacy_list_id_t(LUser, Name).
 
 sql_get_privacy_list_data(LUser, LServer, Name) ->
-    odbc_queries:get_privacy_list_data(LServer, LUser, Name).
+    sql_queries:get_privacy_list_data(LServer, LUser, Name).
 
 sql_get_privacy_list_data_t(LUser, Name) ->
-    Username = ejabberd_odbc:escape(LUser),
-    SName = ejabberd_odbc:escape(Name),
-    odbc_queries:get_privacy_list_data_t(Username, SName).
+    Username = ejabberd_sql:escape(LUser),
+    SName = ejabberd_sql:escape(Name),
+    sql_queries:get_privacy_list_data_t(Username, SName).
 
 sql_get_privacy_list_data_by_id(ID, LServer) ->
-    odbc_queries:get_privacy_list_data_by_id(LServer, ID).
+    sql_queries:get_privacy_list_data_by_id(LServer, ID).
 
 sql_get_privacy_list_data_by_id_t(ID) ->
-    odbc_queries:get_privacy_list_data_by_id_t(ID).
+    sql_queries:get_privacy_list_data_by_id_t(ID).
 
 sql_set_default_privacy_list(LUser, Name) ->
-    odbc_queries:set_default_privacy_list(LUser, Name).
+    sql_queries:set_default_privacy_list(LUser, Name).
 
 sql_unset_default_privacy_list(LUser, LServer) ->
-    odbc_queries:unset_default_privacy_list(LServer, LUser).
+    sql_queries:unset_default_privacy_list(LServer, LUser).
 
 sql_remove_privacy_list(LUser, Name) ->
-    odbc_queries:remove_privacy_list(LUser, Name).
+    sql_queries:remove_privacy_list(LUser, Name).
 
 sql_add_privacy_list(LUser, Name) ->
-    odbc_queries:add_privacy_list(LUser, Name).
+    sql_queries:add_privacy_list(LUser, Name).
 
 sql_set_privacy_list(ID, RItems) ->
-    odbc_queries:set_privacy_list(ID, RItems).
+    sql_queries:set_privacy_list(ID, RItems).
 
 sql_del_privacy_lists(LUser, LServer) ->
-    odbc_queries:del_privacy_lists(LServer, LUser).
+    sql_queries:del_privacy_lists(LServer, LUser).
index 1b77c48b6d4b2f2460ef34d6dfec4f052e680895..6ec6c9df19405832c694851873c7700aa95352d0 100644 (file)
@@ -28,14 +28,14 @@ set_data(LUser, LServer, Data) ->
                lists:foreach(
                  fun({XMLNS, El}) ->
                          SData = fxml:element_to_binary(El),
-                         odbc_queries:set_private_data(
+                         sql_queries:set_private_data(
                            LServer, LUser, XMLNS, SData)
                  end, Data)
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 get_data(LUser, LServer, XMLNS) ->
-    case catch odbc_queries:get_private_data(LServer, LUser, XMLNS) of
+    case catch sql_queries:get_private_data(LServer, LUser, XMLNS) of
        {selected, [{SData}]} ->
            case fxml_stream:parse_element(SData) of
                Data when is_record(Data, xmlel) ->
@@ -48,7 +48,7 @@ get_data(LUser, LServer, XMLNS) ->
     end.
 
 get_all_data(LUser, LServer) ->
-    case catch odbc_queries:get_private_data(LServer, LUser) of
+    case catch sql_queries:get_private_data(LServer, LUser) of
         {selected, Res} ->
             lists:flatmap(
               fun({_, SData}) ->
@@ -64,18 +64,18 @@ get_all_data(LUser, LServer) ->
     end.
 
 remove_user(LUser, LServer) ->
-    odbc_queries:del_user_private_storage(LServer, LUser).
+    sql_queries:del_user_private_storage(LServer, LUser).
 
 export(_Server) ->
     [{private_storage,
       fun(Host, #private_storage{usns = {LUser, LServer, XMLNS},
                                  xml = Data})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
-              LXMLNS = ejabberd_odbc:escape(XMLNS),
+              Username = ejabberd_sql:escape(LUser),
+              LXMLNS = ejabberd_sql:escape(XMLNS),
               SData =
-                  ejabberd_odbc:escape(fxml:element_to_binary(Data)),
-              odbc_queries:set_private_data_sql(Username, LXMLNS,
+                  ejabberd_sql:escape(fxml:element_to_binary(Data)),
+              sql_queries:set_private_data_sql(Username, LXMLNS,
                                                 SData);
          (_Host, _R) ->
               []
index 247b9f8c4b9dcc531626c9ab94b0d88b44f2c142..e42d5c058e6106025b7df6a4b0ce00cd6695f286 100644 (file)
@@ -2527,7 +2527,7 @@ get_last_item(Host, Type, Nidx, LJID, mnesia) ->
        {result, {[LastItem|_], _}} -> LastItem;
        _ -> undefined
     end;
-get_last_item(Host, Type, Nidx, LJID, odbc) ->
+get_last_item(Host, Type, Nidx, LJID, sql) ->
     case node_action(Host, Type, get_last_items, [Nidx, LJID, 1]) of
        {result, [LastItem]} -> LastItem;
        _ -> undefined
@@ -2542,7 +2542,7 @@ get_last_items(Host, Type, Nidx, LJID, Number, mnesia) ->
        {result, {Items, _}} -> lists:sublist(Items, Number);
        _ -> []
     end;
-get_last_items(Host, Type, Nidx, LJID, Number, odbc) ->
+get_last_items(Host, Type, Nidx, LJID, Number, sql) ->
     case node_action(Host, Type, get_last_items, [Nidx, LJID, Number]) of
        {result, Items} -> Items;
        _ -> []
@@ -3012,7 +3012,7 @@ get_subscriptions_for_send_last(Host, PType, mnesia, JID, LJID, BJID) ->
        || {Node, Sub, SubId, SubJID} <- Subs,
            Sub =:= subscribed, (SubJID == LJID) or (SubJID == BJID),
            match_option(Node, send_last_published_item, on_sub_and_presence)];
-get_subscriptions_for_send_last(Host, PType, odbc, JID, LJID, BJID) ->
+get_subscriptions_for_send_last(Host, PType, sql, JID, LJID, BJID) ->
     case catch node_action(Host, PType,
            get_entity_subscriptions_for_send_last,
            [Host, JID])
@@ -3688,7 +3688,7 @@ filter_node_options(Options) ->
 
 node_owners_action(Host, Type, Nidx, []) ->
     case gen_mod:db_type(serverhost(Host), ?MODULE) of
-       odbc ->
+       sql ->
            case node_action(Host, Type, get_node_affiliations, [Nidx]) of
                {result, Affs} -> [LJID || {LJID, Aff} <- Affs, Aff =:= owner];
                _ -> []
@@ -3701,7 +3701,7 @@ node_owners_action(_Host, _Type, _Nidx, Owners) ->
 
 node_owners_call(Host, Type, Nidx, []) ->
     case gen_mod:db_type(serverhost(Host), ?MODULE) of
-       odbc ->
+       sql ->
            case node_call(Host, Type, get_node_affiliations, [Nidx]) of
                {result, Affs} -> [LJID || {LJID, Aff} <- Affs, Aff =:= owner];
                _ -> []
@@ -4066,14 +4066,14 @@ tree(_Host, <<"virtual">>) ->
 tree(Host, Name) ->
     case gen_mod:db_type(serverhost(Host), ?MODULE) of
        mnesia -> jlib:binary_to_atom(<<"nodetree_", Name/binary>>);
-       odbc -> jlib:binary_to_atom(<<"nodetree_", Name/binary, "_odbc">>);
+       sql -> jlib:binary_to_atom(<<"nodetree_", Name/binary, "_sql">>);
        _ -> Name
     end.
 
 plugin(Host, Name) ->
     case gen_mod:db_type(serverhost(Host), ?MODULE) of
        mnesia -> jlib:binary_to_atom(<<"node_", Name/binary>>);
-       odbc -> jlib:binary_to_atom(<<"node_", Name/binary, "_odbc">>);
+       sql -> jlib:binary_to_atom(<<"node_", Name/binary, "_sql">>);
        _ -> Name
     end.
 
@@ -4087,7 +4087,7 @@ plugins(Host) ->
 subscription_plugin(Host) ->
     case gen_mod:db_type(serverhost(Host), ?MODULE) of
        mnesia -> pubsub_subscription;
-       odbc -> pubsub_subscription_odbc;
+       sql -> pubsub_subscription_sql;
        _ -> none
     end.
 
@@ -4184,8 +4184,8 @@ tree_action(Host, Function, Args) ->
     case gen_mod:db_type(ServerHost, ?MODULE) of
        mnesia ->
            catch mnesia:sync_dirty(Fun);
-       odbc ->
-           case catch ejabberd_odbc:sql_bloc(ServerHost, Fun) of
+       sql ->
+           case catch ejabberd_sql:sql_bloc(ServerHost, Fun) of
                {atomic, Result} ->
                    Result;
                {aborted, Reason} ->
@@ -4244,7 +4244,7 @@ transaction(Host, Fun, Trans) ->
     ServerHost = serverhost(Host),
     DBType = gen_mod:db_type(ServerHost, ?MODULE),
     Retry = case DBType of
-       odbc -> 2;
+       sql -> 2;
        _ -> 1
     end,
     transaction_retry(Host, ServerHost, Fun, Trans, DBType, Retry).
@@ -4255,12 +4255,12 @@ transaction_retry(Host, ServerHost, Fun, Trans, DBType, Count) ->
     Res = case DBType of
        mnesia ->
            catch mnesia:Trans(Fun);
-       odbc ->
+       sql ->
            SqlFun = case Trans of
                transaction -> sql_transaction;
                _ -> sql_bloc
            end,
-           catch ejabberd_odbc:SqlFun(ServerHost, Fun);
+           catch ejabberd_sql:SqlFun(ServerHost, Fun);
        _ ->
            {unsupported, DBType}
     end,
index 82662865976ff5fef412adbe7e55dcbe649da5be..616d0ec60db7009806853921e2bd92cb5b4b3724 100644 (file)
@@ -28,28 +28,28 @@ init(_Host, _Opts) ->
     ok.
 
 read_roster_version(LUser, LServer) ->
-    case odbc_queries:get_roster_version(LServer, LUser) of
+    case sql_queries:get_roster_version(LServer, LUser) of
        {selected, [{Version}]} -> Version;
        {selected, []} -> error
     end.
 
 write_roster_version(LUser, LServer, InTransaction, Ver) ->
-    Username = ejabberd_odbc:escape(LUser),
-    EVer = ejabberd_odbc:escape(Ver),
+    Username = ejabberd_sql:escape(LUser),
+    EVer = ejabberd_sql:escape(Ver),
     if InTransaction ->
-           odbc_queries:set_roster_version(Username, EVer);
+           sql_queries:set_roster_version(Username, EVer);
        true ->
-           odbc_queries:sql_transaction(
+           sql_queries:sql_transaction(
              LServer,
              fun () ->
-                     odbc_queries:set_roster_version(Username, EVer)
+                     sql_queries:set_roster_version(Username, EVer)
              end)
     end.
 
 get_roster(LUser, LServer) ->
-    case catch odbc_queries:get_roster(LServer, LUser) of
+    case catch sql_queries:get_roster(LServer, LUser) of
         {selected, Items} when is_list(Items) ->
-            JIDGroups = case catch odbc_queries:get_roster_jid_groups(
+            JIDGroups = case catch sql_queries:get_roster_jid_groups(
                                      LServer, LUser) of
                             {selected, JGrps} when is_list(JGrps) ->
                                 JGrps;
@@ -80,7 +80,7 @@ get_roster(LUser, LServer) ->
 
 get_roster_by_jid(LUser, LServer, LJID) ->
     {selected, Res} =
-       odbc_queries:get_roster_by_jid(LServer, LUser, jid:to_string(LJID)),
+       sql_queries:get_roster_by_jid(LServer, LUser, jid:to_string(LJID)),
     case Res of
        [] ->
            #roster{usj = {LUser, LServer, LJID},
@@ -99,7 +99,7 @@ get_roster_by_jid(LUser, LServer, LJID) ->
     end.
 
 get_only_items(LUser, LServer) ->
-    case catch odbc_queries:get_roster(LServer, LUser) of
+    case catch sql_queries:get_roster(LServer, LUser) of
        {selected, Is} when is_list(Is) ->
            lists:map(fun(I) -> raw_to_record(LServer, I) end, Is);
        _ -> []
@@ -107,18 +107,18 @@ get_only_items(LUser, LServer) ->
 
 roster_subscribe(_LUser, _LServer, _LJID, Item) ->
     ItemVals = record_to_row(Item),
-    odbc_queries:roster_subscribe(ItemVals).
+    sql_queries:roster_subscribe(ItemVals).
 
 transaction(LServer, F) ->
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 get_roster_by_jid_with_groups(LUser, LServer, LJID) ->
     SJID = jid:to_string(LJID),
-    case odbc_queries:get_roster_by_jid(LServer, LUser, SJID) of
+    case sql_queries:get_roster_by_jid(LServer, LUser, SJID) of
        {selected, [I]} ->
             R = raw_to_record(LServer, I),
             Groups =
-                case odbc_queries:get_roster_groups(LServer, LUser, SJID) of
+                case sql_queries:get_roster_groups(LServer, LUser, SJID) of
                     {selected, JGrps} when is_list(JGrps) ->
                         [JGrp || {JGrp} <- JGrps];
                     _ -> []
@@ -130,23 +130,23 @@ get_roster_by_jid_with_groups(LUser, LServer, LJID) ->
     end.
 
 remove_user(LUser, LServer) ->
-    odbc_queries:del_user_roster_t(LServer, LUser),
+    sql_queries:del_user_roster_t(LServer, LUser),
     {atomic, ok}.
 
 update_roster(LUser, LServer, LJID, Item) ->
     SJID = jid:to_string(LJID),
     ItemVals = record_to_row(Item),
     ItemGroups = Item#roster.groups,
-    odbc_queries:update_roster(LServer, LUser, SJID, ItemVals,
+    sql_queries:update_roster(LServer, LUser, SJID, ItemVals,
                                ItemGroups).
 
 del_roster(LUser, LServer, LJID) ->
     SJID = jid:to_string(LJID),
-    odbc_queries:del_roster(LServer, LUser, SJID).
+    sql_queries:del_roster(LServer, LUser, SJID).
 
 read_subscription_and_groups(LUser, LServer, LJID) ->
     SJID = jid:to_string(LJID),
-    case catch odbc_queries:get_subscription(LServer, LUser, SJID) of
+    case catch sql_queries:get_subscription(LServer, LUser, SJID) of
        {selected, [{SSubscription}]} ->
            Subscription = case SSubscription of
                               <<"B">> -> both;
@@ -154,7 +154,7 @@ read_subscription_and_groups(LUser, LServer, LJID) ->
                               <<"F">> -> from;
                               _ -> none
                           end,
-           Groups = case catch odbc_queries:get_rostergroup_by_jid(
+           Groups = case catch sql_queries:get_rostergroup_by_jid(
                                  LServer, LUser, SJID) of
                         {selected, JGrps} when is_list(JGrps) ->
                             [JGrp || {JGrp} <- JGrps];
@@ -169,11 +169,11 @@ export(_Server) ->
     [{roster,
       fun(Host, #roster{usj = {LUser, LServer, LJID}} = R)
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
-              SJID = ejabberd_odbc:escape(jid:to_string(LJID)),
+              Username = ejabberd_sql:escape(LUser),
+              SJID = ejabberd_sql:escape(jid:to_string(LJID)),
               ItemVals = record_to_string(R),
               ItemGroups = groups_to_string(R),
-              odbc_queries:update_roster_sql(Username, SJID,
+              sql_queries:update_roster_sql(Username, SJID,
                                              ItemVals, ItemGroups);
         (_Host, _R) ->
               []
@@ -181,8 +181,8 @@ export(_Server) ->
      {roster_version,
       fun(Host, #roster_version{us = {LUser, LServer}, version = Ver})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
-              SVer = ejabberd_odbc:escape(Ver),
+              Username = ejabberd_sql:escape(LUser),
+              SVer = ejabberd_sql:escape(Ver),
               [[<<"delete from roster_version where username='">>,
                 Username, <<"';">>],
                [<<"insert into roster_version(username, version) values('">>,
@@ -196,10 +196,10 @@ import(LServer) ->
         "ask, askmessage, server, subscribe, type from rosterusers;">>,
       fun([LUser, JID|_] = Row) ->
               Item = raw_to_record(LServer, Row),
-              Username = ejabberd_odbc:escape(LUser),
-              SJID = ejabberd_odbc:escape(JID),
+              Username = ejabberd_sql:escape(LUser),
+              SJID = ejabberd_sql:escape(JID),
               {selected, _, Rows} =
-                  ejabberd_odbc:sql_query_t(
+                  ejabberd_sql:sql_query_t(
                     [<<"select grp from rostergroups where username='">>,
                      Username, <<"' and jid='">>, SJID, <<"'">>]),
               Groups = [Grp || [Grp] <- Rows],
@@ -252,10 +252,10 @@ raw_to_record(LServer,
 record_to_string(#roster{us = {User, _Server},
                         jid = JID, name = Name, subscription = Subscription,
                         ask = Ask, askmessage = AskMessage}) ->
-    Username = ejabberd_odbc:escape(User),
+    Username = ejabberd_sql:escape(User),
     SJID =
-       ejabberd_odbc:escape(jid:to_string(jid:tolower(JID))),
-    Nick = ejabberd_odbc:escape(Name),
+       ejabberd_sql:escape(jid:to_string(jid:tolower(JID))),
+    Nick = ejabberd_sql:escape(Name),
     SSubscription = case Subscription of
                      both -> <<"B">>;
                      to -> <<"T">>;
@@ -270,7 +270,7 @@ record_to_string(#roster{us = {User, _Server},
             in -> <<"I">>;
             none -> <<"N">>
           end,
-    SAskMessage = ejabberd_odbc:escape(AskMessage),
+    SAskMessage = ejabberd_sql:escape(AskMessage),
     [Username, SJID, Nick, SSubscription, SAsk, SAskMessage,
      <<"N">>, <<"">>, <<"item">>].
 
@@ -297,12 +297,12 @@ record_to_row(
 
 groups_to_string(#roster{us = {User, _Server},
                         jid = JID, groups = Groups}) ->
-    Username = ejabberd_odbc:escape(User),
+    Username = ejabberd_sql:escape(User),
     SJID =
-       ejabberd_odbc:escape(jid:to_string(jid:tolower(JID))),
+       ejabberd_sql:escape(jid:to_string(jid:tolower(JID))),
     lists:foldl(fun (<<"">>, Acc) -> Acc;
                    (Group, Acc) ->
-                       G = ejabberd_odbc:escape(Group),
+                       G = ejabberd_sql:escape(Group),
                        [[Username, SJID, G] | Acc]
                end,
                [], Groups).
index 21ea768af0319e730206b203f2fd47f2ca9b143f..bd123cd4afa81bdbf8b336d21093207d64910f5d 100644 (file)
@@ -29,69 +29,69 @@ init(_Host, _Opts) ->
     ok.
 
 list_groups(Host) ->
-    case ejabberd_odbc:sql_query(
+    case ejabberd_sql:sql_query(
           Host, [<<"select name from sr_group;">>]) of
        {selected, [<<"name">>], Rs} -> [G || [G] <- Rs];
        _ -> []
     end.
 
 groups_with_opts(Host) ->
-    case ejabberd_odbc:sql_query(Host,
+    case ejabberd_sql:sql_query(Host,
                                 [<<"select name, opts from sr_group;">>])
        of
       {selected, [<<"name">>, <<"opts">>], Rs} ->
-         [{G, mod_shared_roster:opts_to_binary(ejabberd_odbc:decode_term(Opts))}
+         [{G, mod_shared_roster:opts_to_binary(ejabberd_sql:decode_term(Opts))}
           || [G, Opts] <- Rs];
       _ -> []
     end.
 
 create_group(Host, Group, Opts) ->
-    SGroup = ejabberd_odbc:escape(Group),
-    SOpts = ejabberd_odbc:encode_term(Opts),
+    SGroup = ejabberd_sql:escape(Group),
+    SOpts = ejabberd_sql:encode_term(Opts),
     F = fun () ->
-               odbc_queries:update_t(<<"sr_group">>,
+               sql_queries:update_t(<<"sr_group">>,
                                      [<<"name">>, <<"opts">>], [SGroup, SOpts],
                                      [<<"name='">>, SGroup, <<"'">>])
        end,
-    ejabberd_odbc:sql_transaction(Host, F).
+    ejabberd_sql:sql_transaction(Host, F).
 
 delete_group(Host, Group) ->
-    SGroup = ejabberd_odbc:escape(Group),
+    SGroup = ejabberd_sql:escape(Group),
     F = fun () ->
-               ejabberd_odbc:sql_query_t([<<"delete from sr_group where name='">>,
+               ejabberd_sql:sql_query_t([<<"delete from sr_group where name='">>,
                                           SGroup, <<"';">>]),
-               ejabberd_odbc:sql_query_t([<<"delete from sr_user where grp='">>,
+               ejabberd_sql:sql_query_t([<<"delete from sr_user where grp='">>,
                                           SGroup, <<"';">>])
        end,
-    case ejabberd_odbc:sql_transaction(Host, F) of
+    case ejabberd_sql:sql_transaction(Host, F) of
         {atomic,{updated,_}} -> {atomic, ok};
         Res -> Res
     end.
 
 get_group_opts(Host, Group) ->
-    SGroup = ejabberd_odbc:escape(Group),
-    case catch ejabberd_odbc:sql_query(
+    SGroup = ejabberd_sql:escape(Group),
+    case catch ejabberd_sql:sql_query(
                 Host,
                 [<<"select opts from sr_group where name='">>,
                  SGroup, <<"';">>]) of
        {selected, [<<"opts">>], [[SOpts]]} ->
-           mod_shared_roster:opts_to_binary(ejabberd_odbc:decode_term(SOpts));
+           mod_shared_roster:opts_to_binary(ejabberd_sql:decode_term(SOpts));
        _ -> error
     end.
 
 set_group_opts(Host, Group, Opts) ->
-    SGroup = ejabberd_odbc:escape(Group),
-    SOpts = ejabberd_odbc:encode_term(Opts),
+    SGroup = ejabberd_sql:escape(Group),
+    SOpts = ejabberd_sql:encode_term(Opts),
     F = fun () ->
-               odbc_queries:update_t(<<"sr_group">>,
+               sql_queries:update_t(<<"sr_group">>,
                                      [<<"name">>, <<"opts">>], [SGroup, SOpts],
                                      [<<"name='">>, SGroup, <<"'">>])
        end,
-    ejabberd_odbc:sql_transaction(Host, F).
+    ejabberd_sql:sql_transaction(Host, F).
 
 get_user_groups(US, Host) ->
     SJID = make_jid_s(US),
-    case catch ejabberd_odbc:sql_query(
+    case catch ejabberd_sql:sql_query(
                 Host,
                 [<<"select grp from sr_user where jid='">>,
                  SJID, <<"';">>]) of
@@ -100,8 +100,8 @@ get_user_groups(US, Host) ->
     end.
 
 get_group_explicit_users(Host, Group) ->
-    SGroup = ejabberd_odbc:escape(Group),
-    case catch ejabberd_odbc:sql_query(
+    SGroup = ejabberd_sql:escape(Group),
+    case catch ejabberd_sql:sql_query(
                 Host,
                 [<<"select jid from sr_user where grp='">>,
                  SGroup, <<"';">>]) of
@@ -117,7 +117,7 @@ get_group_explicit_users(Host, Group) ->
 
 get_user_displayed_groups(LUser, LServer, GroupsOpts) ->
     SJID = make_jid_s(LUser, LServer),
-    case catch ejabberd_odbc:sql_query(
+    case catch ejabberd_sql:sql_query(
                 LServer,
                 [<<"select grp from sr_user where jid='">>,
                  SJID, <<"';">>]) of
@@ -129,8 +129,8 @@ get_user_displayed_groups(LUser, LServer, GroupsOpts) ->
 
 is_user_in_group(US, Group, Host) ->
     SJID = make_jid_s(US),
-    SGroup = ejabberd_odbc:escape(Group),
-    case catch ejabberd_odbc:sql_query(Host,
+    SGroup = ejabberd_sql:escape(Group),
+    case catch ejabberd_sql:sql_query(Host,
                                       [<<"select * from sr_user where jid='">>,
                                        SJID, <<"' and grp='">>, SGroup,
                                        <<"';">>]) of
@@ -140,32 +140,32 @@ is_user_in_group(US, Group, Host) ->
 
 add_user_to_group(Host, US, Group) ->
     SJID = make_jid_s(US),
-    SGroup = ejabberd_odbc:escape(Group),
+    SGroup = ejabberd_sql:escape(Group),
     F = fun () ->
-               odbc_queries:update_t(<<"sr_user">>,
+               sql_queries:update_t(<<"sr_user">>,
                                      [<<"jid">>, <<"grp">>], [SJID, SGroup],
                                      [<<"jid='">>, SJID, <<"' and grp='">>,
                                       SGroup, <<"'">>])
        end,
-    ejabberd_odbc:sql_transaction(Host, F).
+    ejabberd_sql:sql_transaction(Host, F).
 
 remove_user_from_group(Host, US, Group) ->
     SJID = make_jid_s(US),
-    SGroup = ejabberd_odbc:escape(Group),
+    SGroup = ejabberd_sql:escape(Group),
     F = fun () ->
-               ejabberd_odbc:sql_query_t([<<"delete from sr_user where jid='">>,
+               ejabberd_sql:sql_query_t([<<"delete from sr_user where jid='">>,
                                           SJID, <<"' and grp='">>, SGroup,
                                           <<"';">>]),
                ok
        end,
-    ejabberd_odbc:sql_transaction(Host, F).
+    ejabberd_sql:sql_transaction(Host, F).
 
 export(_Server) ->
     [{sr_group,
       fun(Host, #sr_group{group_host = {Group, LServer}, opts = Opts})
             when LServer == Host ->
-              SGroup = ejabberd_odbc:escape(Group),
-              SOpts = ejabberd_odbc:encode_term(Opts),
+              SGroup = ejabberd_sql:escape(Group),
+              SOpts = ejabberd_sql:encode_term(Opts),
               [[<<"delete from sr_group where name='">>, Group, <<"';">>],
                [<<"insert into sr_group(name, opts) values ('">>,
                 SGroup, <<"', '">>, SOpts, <<"');">>]];
@@ -175,8 +175,8 @@ export(_Server) ->
      {sr_user,
       fun(Host, #sr_user{us = {U, S}, group_host = {Group, LServer}})
             when LServer == Host ->
-              SGroup = ejabberd_odbc:escape(Group),
-              SJID = ejabberd_odbc:escape(
+              SGroup = ejabberd_sql:escape(Group),
+              SJID = ejabberd_sql:escape(
                        jid:to_string(
                          jid:tolower(
                            jid:make(U, S, <<"">>)))),
@@ -192,7 +192,7 @@ import(LServer) ->
     [{<<"select name, opts from sr_group;">>,
       fun([Group, SOpts]) ->
               #sr_group{group_host = {Group, LServer},
-                        opts = ejabberd_odbc:decode_term(SOpts)}
+                        opts = ejabberd_sql:decode_term(SOpts)}
       end},
      {<<"select jid, grp from sr_user;">>,
       fun([SJID, Group]) ->
@@ -207,6 +207,6 @@ import(_, _) ->
 %%% Internal functions
 %%%===================================================================
 make_jid_s(U, S) ->
-    ejabberd_odbc:escape(jid:to_string(jid:tolower(jid:make(U, S, <<"">>)))).
+    ejabberd_sql:escape(jid:to_string(jid:tolower(jid:make(U, S, <<"">>)))).
 
 make_jid_s({U, S}) -> make_jid_s(U, S).
index fff39091c54a1d99bab666b944045e07c4560504..9fcd5cd5eb407630a49a72bb7a3969658f343da5 100644 (file)
@@ -28,7 +28,7 @@ init(_Host, _Opts) ->
     ok.
 
 get_vcard(LUser, LServer) ->
-    case catch odbc_queries:get_vcard(LServer, LUser) of
+    case catch sql_queries:get_vcard(LServer, LUser) of
        {selected, [{SVCARD}]} ->
            case fxml_stream:parse_element(SVCARD) of
                {error, _Reason} -> error;
@@ -63,7 +63,7 @@ set_vcard(LUser, LServer, VCARD,
                        orgunit = OrgUnit,
                        lorgunit = LOrgUnit}) ->
     SVCARD = fxml:element_to_binary(VCARD),
-    odbc_queries:set_vcard(LServer, LUser, BDay, CTRY,
+    sql_queries:set_vcard(LServer, LUser, BDay, CTRY,
                           EMail, FN, Family, Given, LBDay,
                           LCTRY, LEMail, LFN, LFamily,
                           LGiven, LLocality, LMiddle,
@@ -81,7 +81,7 @@ search(LServer, Data, AllowReturnAll, MaxMatch) ->
                        Val ->
                            [<<" LIMIT ">>, jlib:integer_to_binary(Val)]
                    end,
-          case catch ejabberd_odbc:sql_query(
+          case catch ejabberd_sql:sql_query(
                        LServer,
                        [<<"select username, fn, family, given, "
                           "middle,        nickname, bday, ctry, "
@@ -100,12 +100,12 @@ search(LServer, Data, AllowReturnAll, MaxMatch) ->
     end.
 
 remove_user(LUser, LServer) ->
-    ejabberd_odbc:sql_transaction(
+    ejabberd_sql:sql_transaction(
       LServer,
       fun() ->
-              ejabberd_odbc:sql_query_t(
+              ejabberd_sql:sql_query_t(
                 ?SQL("delete from vcard where username=%(LUser)s")),
-              ejabberd_odbc:sql_query_t(
+              ejabberd_sql:sql_query_t(
                 ?SQL("delete from vcard_search where lusername=%(LUser)s"))
       end).
 
@@ -113,9 +113,9 @@ export(_Server) ->
     [{vcard,
       fun(Host, #vcard{us = {LUser, LServer}, vcard = VCARD})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
+              Username = ejabberd_sql:escape(LUser),
               SVCARD =
-                  ejabberd_odbc:escape(fxml:element_to_binary(VCARD)),
+                  ejabberd_sql:escape(fxml:element_to_binary(VCARD)),
               [[<<"delete from vcard where username='">>, Username, <<"';">>],
                [<<"insert into vcard(username, vcard) values ('">>,
                 Username, <<"', '">>, SVCARD, <<"');">>]];
@@ -135,30 +135,30 @@ export(_Server) ->
                               orgname = OrgName, lorgname = LOrgName,
                               orgunit = OrgUnit, lorgunit = LOrgUnit})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(User),
-              LUsername = ejabberd_odbc:escape(LUser),
-              SFN = ejabberd_odbc:escape(FN),
-              SLFN = ejabberd_odbc:escape(LFN),
-              SFamily = ejabberd_odbc:escape(Family),
-              SLFamily = ejabberd_odbc:escape(LFamily),
-              SGiven = ejabberd_odbc:escape(Given),
-              SLGiven = ejabberd_odbc:escape(LGiven),
-              SMiddle = ejabberd_odbc:escape(Middle),
-              SLMiddle = ejabberd_odbc:escape(LMiddle),
-              SNickname = ejabberd_odbc:escape(Nickname),
-              SLNickname = ejabberd_odbc:escape(LNickname),
-              SBDay = ejabberd_odbc:escape(BDay),
-              SLBDay = ejabberd_odbc:escape(LBDay),
-              SCTRY = ejabberd_odbc:escape(CTRY),
-              SLCTRY = ejabberd_odbc:escape(LCTRY),
-              SLocality = ejabberd_odbc:escape(Locality),
-              SLLocality = ejabberd_odbc:escape(LLocality),
-              SEMail = ejabberd_odbc:escape(EMail),
-              SLEMail = ejabberd_odbc:escape(LEMail),
-              SOrgName = ejabberd_odbc:escape(OrgName),
-              SLOrgName = ejabberd_odbc:escape(LOrgName),
-              SOrgUnit = ejabberd_odbc:escape(OrgUnit),
-              SLOrgUnit = ejabberd_odbc:escape(LOrgUnit),
+              Username = ejabberd_sql:escape(User),
+              LUsername = ejabberd_sql:escape(LUser),
+              SFN = ejabberd_sql:escape(FN),
+              SLFN = ejabberd_sql:escape(LFN),
+              SFamily = ejabberd_sql:escape(Family),
+              SLFamily = ejabberd_sql:escape(LFamily),
+              SGiven = ejabberd_sql:escape(Given),
+              SLGiven = ejabberd_sql:escape(LGiven),
+              SMiddle = ejabberd_sql:escape(Middle),
+              SLMiddle = ejabberd_sql:escape(LMiddle),
+              SNickname = ejabberd_sql:escape(Nickname),
+              SLNickname = ejabberd_sql:escape(LNickname),
+              SBDay = ejabberd_sql:escape(BDay),
+              SLBDay = ejabberd_sql:escape(LBDay),
+              SCTRY = ejabberd_sql:escape(CTRY),
+              SLCTRY = ejabberd_sql:escape(LCTRY),
+              SLocality = ejabberd_sql:escape(Locality),
+              SLLocality = ejabberd_sql:escape(LLocality),
+              SEMail = ejabberd_sql:escape(EMail),
+              SLEMail = ejabberd_sql:escape(LEMail),
+              SOrgName = ejabberd_sql:escape(OrgName),
+              SLOrgName = ejabberd_sql:escape(LOrgName),
+              SOrgUnit = ejabberd_sql:escape(OrgUnit),
+              SLOrgUnit = ejabberd_sql:escape(LOrgUnit),
               [[<<"delete from vcard_search where lusername='">>,
                 LUsername, <<"';">>],
                [<<"insert into vcard_search(        username, "
@@ -255,11 +255,11 @@ make_val(Match, Field, Val) ->
     Condition = case str:suffix(<<"*">>, Val) of
                  true ->
                      Val1 = str:substr(Val, 1, byte_size(Val) - 1),
-                     SVal = <<(ejabberd_odbc:escape_like(Val1))/binary,
+                     SVal = <<(ejabberd_sql:escape_like(Val1))/binary,
                               "%">>,
                      [Field, <<" LIKE '">>, SVal, <<"'">>];
                  _ ->
-                     SVal = ejabberd_odbc:escape(Val),
+                     SVal = ejabberd_sql:escape(Val),
                      [Field, <<" = '">>, SVal, <<"'">>]
                end,
     case Match of
index d580b1515d4068a32ec9a8d298df020d242ac09f..7f0079dd0ca7aa337e7487e9504f0492566daa2a 100644 (file)
@@ -21,19 +21,19 @@ init(_Host, _Opts) ->
     ok.
 
 add_xupdate(LUser, LServer, Hash) ->
-    Username = ejabberd_odbc:escape(LUser),
-    SHash = ejabberd_odbc:escape(Hash),
+    Username = ejabberd_sql:escape(LUser),
+    SHash = ejabberd_sql:escape(Hash),
     F = fun () ->
-               odbc_queries:update_t(<<"vcard_xupdate">>,
+               sql_queries:update_t(<<"vcard_xupdate">>,
                                      [<<"username">>, <<"hash">>],
                                      [Username, SHash],
                                      [<<"username='">>, Username, <<"'">>])
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 get_xupdate(LUser, LServer) ->
-    Username = ejabberd_odbc:escape(LUser),
-    case ejabberd_odbc:sql_query(LServer,
+    Username = ejabberd_sql:escape(LUser),
+    case ejabberd_sql:sql_query(LServer,
                                 [<<"select hash from vcard_xupdate where "
                                    "username='">>,
                                  Username, <<"';">>])
@@ -43,19 +43,19 @@ get_xupdate(LUser, LServer) ->
     end.
 
 remove_xupdate(LUser, LServer) ->
-    Username = ejabberd_odbc:escape(LUser),
+    Username = ejabberd_sql:escape(LUser),
     F = fun () ->
-               ejabberd_odbc:sql_query_t([<<"delete from vcard_xupdate where username='">>,
+               ejabberd_sql:sql_query_t([<<"delete from vcard_xupdate where username='">>,
                                           Username, <<"';">>])
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 export(_Server) ->
     [{vcard_xupdate,
       fun(Host, #vcard_xupdate{us = {LUser, LServer}, hash = Hash})
             when LServer == Host ->
-              Username = ejabberd_odbc:escape(LUser),
-              SHash = ejabberd_odbc:escape(Hash),
+              Username = ejabberd_sql:escape(LUser),
+              SHash = ejabberd_sql:escape(Hash),
               [[<<"delete from vcard_xupdate where username='">>,
                 Username, <<"';">>],
                [<<"insert into vcard_xupdate(username, "
similarity index 89%
rename from src/node_flat_odbc.erl
rename to src/node_flat_sql.erl
index 5dd52066889b2b6a021aa6608e8cb679d308735a..5baabcfcfaad3f08ad9e2b615ddceb251f3df6a3 100644 (file)
@@ -1,5 +1,5 @@
 %%%----------------------------------------------------------------------
-%%% File    : node_flat_odbc.erl
+%%% File    : node_flat_sql.erl
 %%% Author  : Christophe Romain <christophe.romain@process-one.net>
 %%% Purpose : Standard PubSub node plugin with ODBC backend
 %%% Created :  1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
@@ -29,7 +29,7 @@
 %%% types.</p>
 %%% <p>PubSub plugin nodes are using the {@link gen_node} behaviour.</p>
 
--module(node_flat_odbc).
+-module(node_flat_sql).
 -behaviour(gen_pubsub_node).
 -author('christophe.romain@process-one.net').
 
     encode_host/1]).
 
 init(_Host, _ServerHost, _Opts) ->
-    %%pubsub_subscription_odbc:init(),
+    %%pubsub_subscription_sql:init(),
     ok.
 
 terminate(_Host, _ServerHost) ->
     ok.
 
 options() ->
-    [{odbc, true}, {rsm, true} | node_flat:options()].
+    [{sql, true}, {rsm, true} | node_flat:options()].
 
 features() ->
     [<<"rsm">> | node_flat:features()].
@@ -74,14 +74,14 @@ create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access) ->
 create_node(Nidx, Owner) ->
     {_U, _S, _R} = OwnerKey = jid:tolower(jid:remove_resource(Owner)),
     State = #pubsub_state{stateid = {OwnerKey, Nidx}, affiliation = owner},
-    catch ejabberd_odbc:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
+    catch ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
                "values(">>, state_to_raw(Nidx, State), <<");">>]),
     {result, {default, broadcast}}.
 
 delete_node(Nodes) ->
     Reply = lists:map(fun (#pubsub_node{id = Nidx} = PubsubNode) ->
                    Subscriptions = case catch
-                       ejabberd_odbc:sql_query_t([<<"select jid, subscriptions "
+                       ejabberd_sql:sql_query_t([<<"select jid, subscriptions "
                                    "from pubsub_state where nodeid='">>, Nidx, <<"';">>])
                    of
                        {selected, [<<"jid">>, <<"subscriptions">>], RItems} ->
@@ -130,12 +130,12 @@ subscribe_node(Nidx, Sender, Subscriber, AccessModel,
        %%        % Requesting entity is anonymous
        %%        {error, ?ERR_FORBIDDEN};
        true ->
-           %%{result, SubId} = pubsub_subscription_odbc:subscribe_node(Subscriber, Nidx, Options),
+           %%{result, SubId} = pubsub_subscription_sql:subscribe_node(Subscriber, Nidx, Options),
            {NewSub, SubId} = case Subscriptions of
                [{subscribed, Id}|_] ->
                    {subscribed, Id};
                [] ->
-                   Id = pubsub_subscription_odbc:make_subid(),
+                   Id = pubsub_subscription_sql:make_subid(),
                    Sub = case AccessModel of
                        authorize -> pending;
                        _ -> subscribed
@@ -209,7 +209,7 @@ unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
 
 delete_subscription(SubKey, Nidx, {Subscription, SubId}, Affiliation, Subscriptions) ->
     NewSubs = Subscriptions -- [{Subscription, SubId}],
-    %%pubsub_subscription_odbc:unsubscribe_node(SubKey, Nidx, SubId),
+    %%pubsub_subscription_sql:unsubscribe_node(SubKey, Nidx, SubId),
     case {Affiliation, NewSubs} of
        {none, []} -> del_state(Nidx, SubKey);
        _ -> update_subscription(Nidx, SubKey, NewSubs)
@@ -296,12 +296,12 @@ get_entity_affiliations(Host, Owner) ->
     H = encode_host(Host),
     J = encode_jid(GenKey),
     Reply = case catch
-       ejabberd_odbc:sql_query_t([<<"select node, type, i.nodeid, affiliation "
+       ejabberd_sql:sql_query_t([<<"select node, type, i.nodeid, affiliation "
                    "from pubsub_state i, pubsub_node n where "
                    "i.nodeid = n.nodeid and jid='">>, J, <<"' and host='">>, H, <<"';">>])
     of
        {selected, [<<"node">>, <<"type">>, <<"nodeid">>, <<"affiliation">>], RItems} ->
-           [{nodetree_tree_odbc:raw_to_node(Host, [N, <<"">>, T, I]), decode_affiliation(A)}
+           [{nodetree_tree_sql:raw_to_node(Host, [N, <<"">>, T, I]), decode_affiliation(A)}
                || [N, T, I, A] <- RItems];
        _ ->
            []
@@ -310,7 +310,7 @@ get_entity_affiliations(Host, Owner) ->
 
 get_node_affiliations(Nidx) ->
     Reply = case catch
-       ejabberd_odbc:sql_query_t([<<"select jid, affiliation from pubsub_state "
+       ejabberd_sql:sql_query_t([<<"select jid, affiliation from pubsub_state "
                    "where nodeid='">>, Nidx, <<"';">>])
     of
        {selected, [<<"jid">>, <<"affiliation">>], RItems} ->
@@ -325,7 +325,7 @@ get_affiliation(Nidx, Owner) ->
     GenKey = jid:remove_resource(SubKey),
     J = encode_jid(GenKey),
     Reply = case catch
-       ejabberd_odbc:sql_query_t([<<"select affiliation from pubsub_state "
+       ejabberd_sql:sql_query_t([<<"select affiliation from pubsub_state "
                    "where nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>])
     of
        {selected, [<<"affiliation">>], [[A]]} ->
@@ -360,11 +360,11 @@ get_entity_subscriptions(Host, Owner) ->
                    "from pubsub_state i, pubsub_node n "
                    "where i.nodeid = n.nodeid and jid in ('">>, SJ, <<"', '">>, GJ, <<"') and host='">>, H, <<"';">>]
     end,
-    Reply = case catch ejabberd_odbc:sql_query_t(Query) of
+    Reply = case catch ejabberd_sql:sql_query_t(Query) of
        {selected,
                    [<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} ->
            lists:foldl(fun ([N, T, I, J, S], Acc) ->
-                       Node = nodetree_tree_odbc:raw_to_node(Host, [N, <<"">>, T, I]),
+                       Node = nodetree_tree_sql:raw_to_node(Host, [N, <<"">>, T, I]),
                        Jid = decode_jid(J),
                        case decode_subscriptions(S) of
                            [] ->
@@ -411,11 +411,11 @@ get_entity_subscriptions_for_send_last(Host, Owner) ->
                    "where i.nodeid = n.nodeid and n.nodeid = o.nodeid and name='send_last_published_item' "
                    "and val='on_sub_and_presence' and jid in ('">>, SJ, <<"', '">>, GJ, <<"') and host='">>, H, <<"';">>]
     end,
-    Reply = case catch ejabberd_odbc:sql_query_t(Query) of
+    Reply = case catch ejabberd_sql:sql_query_t(Query) of
        {selected,
                    [<<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>], RItems} ->
            lists:foldl(fun ([N, T, I, J, S], Acc) ->
-                       Node = nodetree_tree_odbc:raw_to_node(Host, [N, <<"">>, T, I]),
+                       Node = nodetree_tree_sql:raw_to_node(Host, [N, <<"">>, T, I]),
                        Jid = decode_jid(J),
                        case decode_subscriptions(S) of
                            [] ->
@@ -435,7 +435,7 @@ get_entity_subscriptions_for_send_last(Host, Owner) ->
 
 get_node_subscriptions(Nidx) ->
     Reply = case catch
-       ejabberd_odbc:sql_query_t([<<"select jid, subscriptions from pubsub_state "
+       ejabberd_sql:sql_query_t([<<"select jid, subscriptions from pubsub_state "
                    "where nodeid='">>, Nidx, <<"';">>])
     of
        {selected, [<<"jid">>, <<"subscriptions">>], RItems} ->
@@ -461,7 +461,7 @@ get_subscriptions(Nidx, Owner) ->
     SubKey = jid:tolower(Owner),
     J = encode_jid(SubKey),
     Reply = case catch
-       ejabberd_odbc:sql_query_t([<<"select subscriptions from pubsub_state where "
+       ejabberd_sql:sql_query_t([<<"select subscriptions from pubsub_state where "
                    "nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>])
     of
        {selected, [<<"subscriptions">>], [[S]]} ->
@@ -507,14 +507,14 @@ replace_subscription({Sub, SubId}, [{_, SubId} | T], Acc) ->
     replace_subscription({Sub, SubId}, T, [{Sub, SubId} | Acc]).
 
 new_subscription(_Nidx, _Owner, Subscription, SubState) ->
-    %%{result, SubId} = pubsub_subscription_odbc:subscribe_node(Owner, Nidx, []),
-    SubId = pubsub_subscription_odbc:make_subid(),
+    %%{result, SubId} = pubsub_subscription_sql:subscribe_node(Owner, Nidx, []),
+    SubId = pubsub_subscription_sql:make_subid(),
     Subscriptions = [{Subscription, SubId} | SubState#pubsub_state.subscriptions],
     set_state(SubState#pubsub_state{subscriptions = Subscriptions}),
     {Subscription, SubId}.
 
 unsub_with_subid(Nidx, SubId, SubState) ->
-    %%pubsub_subscription_odbc:unsubscribe_node(SubState#pubsub_state.stateid, Nidx, SubId),
+    %%pubsub_subscription_sql:unsubscribe_node(SubState#pubsub_state.stateid, Nidx, SubId),
     NewSubs = [{S, Sid}
            || {S, Sid} <- SubState#pubsub_state.subscriptions,
                SubId =/= Sid],
@@ -561,7 +561,7 @@ get_nodes_helper(NodeTree, #pubsub_state{stateid = {_, N}, subscriptions = Subs}
 
 get_states(Nidx) ->
     case catch
-       ejabberd_odbc:sql_query_t([<<"select jid, affiliation, subscriptions "
+       ejabberd_sql:sql_query_t([<<"select jid, affiliation, subscriptions "
                    "from pubsub_state where nodeid='">>, Nidx, <<"';">>])
     of
        {selected,
@@ -591,7 +591,7 @@ get_state(Nidx, JID) ->
 get_state_without_itemids(Nidx, JID) ->
     J = encode_jid(JID),
     case catch
-       ejabberd_odbc:sql_query_t([<<"select jid, affiliation, subscriptions "
+       ejabberd_sql:sql_query_t([<<"select jid, affiliation, subscriptions "
                    "from pubsub_state where jid='">>, J, <<"' and nodeid='">>, Nidx, <<"';">>])
     of
        {selected,
@@ -613,14 +613,14 @@ set_state(Nidx, State) ->
     S = encode_subscriptions(State#pubsub_state.subscriptions),
     A = encode_affiliation(State#pubsub_state.affiliation),
     case catch
-       ejabberd_odbc:sql_query_t([<<"update pubsub_state set subscriptions='">>, S, <<"', affiliation='">>, A,
+       ejabberd_sql:sql_query_t([<<"update pubsub_state set subscriptions='">>, S, <<"', affiliation='">>, A,
                <<"' where nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>])
     of
        {updated, 1} ->
            ok;
        _ ->
            catch
-           ejabberd_odbc:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
+           ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
                        "values('">>,
                    Nidx, <<"', '">>, J, <<"', '">>, A, <<"', '">>, S, <<"');">>])
     end,
@@ -628,13 +628,13 @@ set_state(Nidx, State) ->
 
 del_state(Nidx, JID) ->
     J = encode_jid(JID),
-    catch ejabberd_odbc:sql_query_t([<<"delete from pubsub_state where jid='">>,
+    catch ejabberd_sql:sql_query_t([<<"delete from pubsub_state where jid='">>,
            J, <<"' and nodeid='">>, Nidx, <<"';">>]),
     ok.
 
 %get_items(Nidx, _From) ->
 %    case catch
-%      ejabberd_odbc:sql_query_t([<<"select itemid, publisher, creation, modification, payload "
+%      ejabberd_sql:sql_query_t([<<"select itemid, publisher, creation, modification, payload "
 %                  "from pubsub_item where nodeid='">>, Nidx,
 %              <<"' order by modification desc;">>])
 %    of
@@ -647,7 +647,7 @@ del_state(Nidx, JID) ->
 
 get_items(Nidx, From, none) ->
     MaxItems = case catch
-       ejabberd_odbc:sql_query_t([<<"select val from pubsub_node_option "
+       ejabberd_sql:sql_query_t([<<"select val from pubsub_node_option "
                    "where nodeid='">>, Nidx, <<"' and name='max_items';">>])
     of
        {selected, [<<"val">>], [[Value]]} ->
@@ -659,7 +659,7 @@ get_items(Nidx, From, none) ->
     get_items(Nidx, From, #rsm_in{max = MaxItems});
 get_items(Nidx, _From,
            #rsm_in{max = M, direction = Direction, id = I, index = IncIndex}) ->
-    Max = ejabberd_odbc:escape(jlib:i2l(M)),
+    Max = ejabberd_sql:escape(jlib:i2l(M)),
     {Way, Order} = case Direction of
        %     aft -> {<<"<">>, <<"desc">>};
        %     before when I == <<>> -> {<<"is not">>, <<"asc">>};
@@ -672,11 +672,11 @@ get_items(Nidx, _From,
     [AttrName, Id] = case I of
        undefined when IncIndex =/= undefined ->
            case catch
-               ejabberd_odbc:sql_query_t([<<"select modification from pubsub_item pi "
+               ejabberd_sql:sql_query_t([<<"select modification from pubsub_item pi "
                            "where exists ( select count(*) as count1 "
                            "from pubsub_item where nodeid='">>, Nidx,
                        <<"' and modification > pi.modification having count1 = ">>,
-                       ejabberd_odbc:escape(jlib:i2l(IncIndex)), <<" );">>])
+                       ejabberd_sql:escape(jlib:i2l(IncIndex)), <<" );">>])
            of
                {selected, [_], [[O]]} ->
                    [<<"modification">>, <<"'", O/binary, "'">>];
@@ -688,36 +688,36 @@ get_items(Nidx, _From,
        <<>> ->
            [<<"modification">>, <<"null">>];
        I ->
-           [A, B] = str:tokens(ejabberd_odbc:escape(jlib:i2l(I)), <<"@">>),
+           [A, B] = str:tokens(ejabberd_sql:escape(jlib:i2l(I)), <<"@">>),
            [A, <<"'", B/binary, "'">>]
     end,
     Count = case catch
-       ejabberd_odbc:sql_query_t([<<"select count(*) from pubsub_item where nodeid='">>, Nidx, <<"';">>])
+       ejabberd_sql:sql_query_t([<<"select count(*) from pubsub_item where nodeid='">>, Nidx, <<"';">>])
     of
        {selected, [_], [[C]]} -> C;
        _ -> <<"0">>
     end,
     Query = fun(mssql, _) ->
-                   ejabberd_odbc:sql_query_t(
+                   ejabberd_sql:sql_query_t(
                      [<<"select top ">>, jlib:i2l(Max),
                       <<" itemid, publisher, creation, modification, payload "
                         "from pubsub_item where nodeid='">>, Nidx,
                       <<"' and ">>, AttrName, <<" ">>, Way, <<" ">>, Id, <<" order by ">>,
                       AttrName, <<" ">>, Order, <<";">>]);
               (_, _) ->
-                   ejabberd_odbc:sql_query_t(
+                   ejabberd_sql:sql_query_t(
                      [<<"select itemid, publisher, creation, modification, payload "
                         "from pubsub_item where nodeid='">>, Nidx,
                       <<"' and ">>, AttrName, <<" ">>, Way, <<" ">>, Id, <<" order by ">>,
                       AttrName, <<" ">>, Order, <<" limit ">>, jlib:i2l(Max), <<" ;">>])
            end,
-    case catch ejabberd_odbc:sql_query_t(Query) of
+    case catch ejabberd_sql:sql_query_t(Query) of
        {selected,
                    [<<"itemid">>, <<"publisher">>, <<"creation">>, <<"modification">>, <<"payload">>], RItems} ->
            case RItems of
                [[_, _, _, F, _]|_] ->
                    Index = case catch
-                       ejabberd_odbc:sql_query_t([<<"select count(*) from pubsub_item "
+                       ejabberd_sql:sql_query_t([<<"select count(*) from pubsub_item "
                                    "where nodeid='">>, Nidx, <<"' and ">>,
                                AttrName, <<" > '">>, F, <<"';">>])
                    of
@@ -771,18 +771,18 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId, RSM
 get_last_items(Nidx, _From, Count) ->
     Limit = jlib:i2l(Count),
     Query = fun(mssql, _) ->
-                   ejabberd_odbc:sql_query_t(
+                   ejabberd_sql:sql_query_t(
                      [<<"select top ">>, Limit,
                       <<" itemid, publisher, creation, modification, payload "
                         "from pubsub_item where nodeid='">>, Nidx,
                       <<"' order by modification desc ;">>]);
               (_, _) ->
-                   ejabberd_odbc:sql_query_t(
+                   ejabberd_sql:sql_query_t(
                      [<<"select itemid, publisher, creation, modification, payload "
                         "from pubsub_item where nodeid='">>, Nidx,
                       <<"' order by modification desc limit ">>, Limit, <<";">>])
            end,
-    case catch ejabberd_odbc:sql_query_t(Query) of
+    case catch ejabberd_sql:sql_query_t(Query) of
        {selected,
                    [<<"itemid">>, <<"publisher">>, <<"creation">>, <<"modification">>, <<"payload">>], RItems} ->
            {result, [raw_to_item(Nidx, RItem) || RItem <- RItems]};
@@ -791,9 +791,9 @@ get_last_items(Nidx, _From, Count) ->
     end.
 
 get_item(Nidx, ItemId) ->
-    I = ejabberd_odbc:escape(ItemId),
+    I = ejabberd_sql:escape(ItemId),
     case catch
-       ejabberd_odbc:sql_query_t([<<"select itemid, publisher, creation, "
+       ejabberd_sql:sql_query_t([<<"select itemid, publisher, creation, "
                    "modification, payload from pubsub_item "
                    "where nodeid='">>, Nidx, <<"' and itemid='">>, I, <<"';">>])
     of
@@ -839,17 +839,17 @@ get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, _Sub
 
 set_item(Item) ->
     {ItemId, Nidx} = Item#pubsub_item.itemid,
-    I = ejabberd_odbc:escape(ItemId),
+    I = ejabberd_sql:escape(ItemId),
     {C, _} = Item#pubsub_item.creation,
     {M, JID} = Item#pubsub_item.modification,
     P = encode_jid(JID),
     Payload = Item#pubsub_item.payload,
-    XML = ejabberd_odbc:escape(str:join([fxml:element_to_binary(X) || X<-Payload], <<>>)),
+    XML = ejabberd_sql:escape(str:join([fxml:element_to_binary(X) || X<-Payload], <<>>)),
     S = fun ({T1, T2, T3}) ->
            str:join([jlib:i2l(T1, 6), jlib:i2l(T2, 6), jlib:i2l(T3, 6)], <<":">>)
     end,
     case catch
-       ejabberd_odbc:sql_query_t([<<"update pubsub_item set publisher='">>, P,
+       ejabberd_sql:sql_query_t([<<"update pubsub_item set publisher='">>, P,
                <<"', modification='">>, S(M),
                <<"', payload='">>, XML,
                <<"' where nodeid='">>, Nidx, <<"' and itemid='">>, I, <<"';">>])
@@ -858,7 +858,7 @@ set_item(Item) ->
            ok;
        _ ->
            catch
-           ejabberd_odbc:sql_query_t([<<"insert into pubsub_item (nodeid, itemid, "
+           ejabberd_sql:sql_query_t([<<"insert into pubsub_item (nodeid, itemid, "
                        "publisher, creation, modification, payload) "
                        "values('">>, Nidx, <<"', '">>, I, <<"', '">>, P,
                    <<"', '">>, S(C), <<"', '">>, S(M),
@@ -867,8 +867,8 @@ set_item(Item) ->
     ok.
 
 del_item(Nidx, ItemId) ->
-    I = ejabberd_odbc:escape(ItemId),
-    catch ejabberd_odbc:sql_query_t([<<"delete from pubsub_item where itemid='">>,
+    I = ejabberd_sql:escape(ItemId),
+    catch ejabberd_sql:sql_query_t([<<"delete from pubsub_item where itemid='">>,
            I, <<"' and nodeid='">>, Nidx, <<"';">>]).
 
 del_items(_, []) ->
@@ -876,9 +876,9 @@ del_items(_, []) ->
 del_items(Nidx, [ItemId]) ->
     del_item(Nidx, ItemId);
 del_items(Nidx, ItemIds) ->
-    I = str:join([[<<"'">>, ejabberd_odbc:escape(X), <<"'">>] || X <- ItemIds], <<",">>),
+    I = str:join([[<<"'">>, ejabberd_sql:escape(X), <<"'">>] || X <- ItemIds], <<",">>),
     catch
-    ejabberd_odbc:sql_query_t([<<"delete from pubsub_item where itemid in (">>,
+    ejabberd_sql:sql_query_t([<<"delete from pubsub_item where itemid in (">>,
            I, <<") and nodeid='">>, Nidx, <<"';">>]).
 
 get_item_name(_Host, _Node, Id) ->
@@ -903,7 +903,7 @@ itemids(Nidx, {U, S, R}) ->
     itemids(Nidx, encode_jid({U, S, R}));
 itemids(Nidx, SJID) ->
     case catch
-       ejabberd_odbc:sql_query_t([<<"select itemid from pubsub_item where "
+       ejabberd_sql:sql_query_t([<<"select itemid from pubsub_item where "
                    "nodeid='">>, Nidx, <<"' and publisher like '">>, SJID,
                <<"%' order by modification desc;">>])
     of
@@ -916,7 +916,7 @@ itemids(Nidx, SJID) ->
 select_affiliation_subscriptions(Nidx, JID) ->
     J = encode_jid(JID),
     case catch
-       ejabberd_odbc:sql_query_t([<<"select affiliation,subscriptions from "
+       ejabberd_sql:sql_query_t([<<"select affiliation,subscriptions from "
                    "pubsub_state where nodeid='">>,
                Nidx, <<"' and jid='">>, J, <<"';">>])
     of
@@ -937,7 +937,7 @@ update_affiliation(Nidx, JID, Affiliation) ->
     J = encode_jid(JID),
     A = encode_affiliation(Affiliation),
     case catch
-       ejabberd_odbc:sql_query_t([<<"update pubsub_state set affiliation='">>,
+       ejabberd_sql:sql_query_t([<<"update pubsub_state set affiliation='">>,
                A, <<"' where nodeid='">>, Nidx,
                <<"' and jid='">>, J, <<"';">>])
     of
@@ -945,7 +945,7 @@ update_affiliation(Nidx, JID, Affiliation) ->
            ok;
        _ ->
            catch
-           ejabberd_odbc:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
+           ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
                        "values('">>, Nidx, <<"', '">>, J, <<"', '">>, A, <<"', '');">>])
     end.
 
@@ -953,14 +953,14 @@ update_subscription(Nidx, JID, Subscription) ->
     J = encode_jid(JID),
     S = encode_subscriptions(Subscription),
     case catch
-       ejabberd_odbc:sql_query_t([<<"update pubsub_state set subscriptions='">>, S,
+       ejabberd_sql:sql_query_t([<<"update pubsub_state set subscriptions='">>, S,
                <<"' where nodeid='">>, Nidx, <<"' and jid='">>, J, <<"';">>])
     of
        {updated, 1} ->
            ok;
        _ ->
            catch
-           ejabberd_odbc:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
+           ejabberd_sql:sql_query_t([<<"insert into pubsub_state(nodeid, jid, affiliation, subscriptions) "
                        "values('">>, Nidx, <<"', '">>, J, <<"', 'n', '">>, S, <<"');">>])
     end.
 
@@ -1009,14 +1009,14 @@ decode_subscriptions(Subscriptions) ->
     -> binary()
     ).
 encode_jid(JID) ->
-    ejabberd_odbc:escape(jid:to_string(JID)).
+    ejabberd_sql:escape(jid:to_string(JID)).
 
 -spec(encode_host/1 ::
     (   Host :: host())
     -> binary()
     ).
 encode_host({_U, _S, _R} = LJID) -> encode_jid(LJID);
-encode_host(Host) -> ejabberd_odbc:escape(Host).
+encode_host(Host) -> ejabberd_sql:escape(Host).
 
 -spec(encode_affiliation/1 ::
     (   Arg :: atom())
similarity index 69%
rename from src/node_hometree_odbc.erl
rename to src/node_hometree_sql.erl
index 6ac5c37b8bbabd66892004d14cfb94b8d215fa1c..4ce6f8554162683a8db8a30a9174fd73f6f0f0db 100644 (file)
@@ -1,5 +1,5 @@
 %%%----------------------------------------------------------------------
-%%% File    : node_hometree_odbc.erl
+%%% File    : node_hometree_sql.erl
 %%% Author  : Christophe Romain <christophe.romain@process-one.net>
 %%% Purpose : Standard tree ordered node plugin with ODBC backend
 %%% Created :  1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
@@ -23,7 +23,7 @@
 %%%
 %%%----------------------------------------------------------------------
 
--module(node_hometree_odbc).
+-module(node_hometree_sql).
 -behaviour(gen_pubsub_node).
 -author('christophe.romain@process-one.net').
 
     get_entity_subscriptions_for_send_last/2, get_last_items/3]).
 
 init(Host, ServerHost, Opts) ->
-    node_flat_odbc:init(Host, ServerHost, Opts),
+    node_flat_sql:init(Host, ServerHost, Opts),
     Owner = mod_pubsub:service_jid(Host),
     mod_pubsub:create_node(Host, ServerHost, <<"/home">>, Owner, <<"hometree">>),
     mod_pubsub:create_node(Host, ServerHost, <<"/home/", ServerHost/binary>>, Owner, <<"hometree">>),
     ok.
 
 terminate(Host, ServerHost) ->
-    node_flat_odbc:terminate(Host, ServerHost).
+    node_flat_sql:terminate(Host, ServerHost).
 
 options() ->
-    [{odbc, true}, {rsm, true} | node_hometree:options()].
+    [{sql, true}, {rsm, true} | node_hometree:options()].
 
 features() ->
     [<<"rsm">> | node_hometree:features()].
@@ -64,92 +64,92 @@ create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access) ->
     node_hometree:create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access).
 
 create_node(Nidx, Owner) ->
-    node_flat_odbc:create_node(Nidx, Owner).
+    node_flat_sql:create_node(Nidx, Owner).
 
 delete_node(Nodes) ->
-    node_flat_odbc:delete_node(Nodes).
+    node_flat_sql:delete_node(Nodes).
 
 subscribe_node(Nidx, Sender, Subscriber, AccessModel,
            SendLast, PresenceSubscription, RosterGroup, Options) ->
-    node_flat_odbc:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
+    node_flat_sql:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
        PresenceSubscription, RosterGroup, Options).
 
 unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
-    node_flat_odbc:unsubscribe_node(Nidx, Sender, Subscriber, SubId).
+    node_flat_sql:unsubscribe_node(Nidx, Sender, Subscriber, SubId).
 
 publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload) ->
-    node_flat_odbc:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
+    node_flat_sql:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
 
 remove_extra_items(Nidx, MaxItems, ItemIds) ->
-    node_flat_odbc:remove_extra_items(Nidx, MaxItems, ItemIds).
+    node_flat_sql:remove_extra_items(Nidx, MaxItems, ItemIds).
 
 delete_item(Nidx, Publisher, PublishModel, ItemId) ->
-    node_flat_odbc:delete_item(Nidx, Publisher, PublishModel, ItemId).
+    node_flat_sql:delete_item(Nidx, Publisher, PublishModel, ItemId).
 
 purge_node(Nidx, Owner) ->
-    node_flat_odbc:purge_node(Nidx, Owner).
+    node_flat_sql:purge_node(Nidx, Owner).
 
 get_entity_affiliations(Host, Owner) ->
-    node_flat_odbc:get_entity_affiliations(Host, Owner).
+    node_flat_sql:get_entity_affiliations(Host, Owner).
 
 get_node_affiliations(Nidx) ->
-    node_flat_odbc:get_node_affiliations(Nidx).
+    node_flat_sql:get_node_affiliations(Nidx).
 
 get_affiliation(Nidx, Owner) ->
-    node_flat_odbc:get_affiliation(Nidx, Owner).
+    node_flat_sql:get_affiliation(Nidx, Owner).
 
 set_affiliation(Nidx, Owner, Affiliation) ->
-    node_flat_odbc:set_affiliation(Nidx, Owner, Affiliation).
+    node_flat_sql:set_affiliation(Nidx, Owner, Affiliation).
 
 get_entity_subscriptions(Host, Owner) ->
-    node_flat_odbc:get_entity_subscriptions(Host, Owner).
+    node_flat_sql:get_entity_subscriptions(Host, Owner).
 
 get_entity_subscriptions_for_send_last(Host, Owner) ->
-    node_flat_odbc:get_entity_subscriptions_for_send_last(Host, Owner).
+    node_flat_sql:get_entity_subscriptions_for_send_last(Host, Owner).
 
 get_node_subscriptions(Nidx) ->
-    node_flat_odbc:get_node_subscriptions(Nidx).
+    node_flat_sql:get_node_subscriptions(Nidx).
 
 get_subscriptions(Nidx, Owner) ->
-    node_flat_odbc:get_subscriptions(Nidx, Owner).
+    node_flat_sql:get_subscriptions(Nidx, Owner).
 
 set_subscriptions(Nidx, Owner, Subscription, SubId) ->
-    node_flat_odbc:set_subscriptions(Nidx, Owner, Subscription, SubId).
+    node_flat_sql:set_subscriptions(Nidx, Owner, Subscription, SubId).
 
 get_pending_nodes(Host, Owner) ->
-    node_flat_odbc:get_pending_nodes(Host, Owner).
+    node_flat_sql:get_pending_nodes(Host, Owner).
 
 get_states(Nidx) ->
-    node_flat_odbc:get_states(Nidx).
+    node_flat_sql:get_states(Nidx).
 
 get_state(Nidx, JID) ->
-    node_flat_odbc:get_state(Nidx, JID).
+    node_flat_sql:get_state(Nidx, JID).
 
 set_state(State) ->
-    node_flat_odbc:set_state(State).
+    node_flat_sql:set_state(State).
 
 get_items(Nidx, From, RSM) ->
-    node_flat_odbc:get_items(Nidx, From, RSM).
+    node_flat_sql:get_items(Nidx, From, RSM).
 
 get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
-    node_flat_odbc:get_items(Nidx, JID, AccessModel,
+    node_flat_sql:get_items(Nidx, JID, AccessModel,
        PresenceSubscription, RosterGroup, SubId, RSM).
 
 get_item(Nidx, ItemId) ->
-    node_flat_odbc:get_item(Nidx, ItemId).
+    node_flat_sql:get_item(Nidx, ItemId).
 
 get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
-    node_flat_odbc:get_item(Nidx, ItemId, JID,
+    node_flat_sql:get_item(Nidx, ItemId, JID,
        AccessModel, PresenceSubscription, RosterGroup, SubId).
 
 set_item(Item) ->
-    node_flat_odbc:set_item(Item).
+    node_flat_sql:set_item(Item).
 
 get_item_name(Host, Node, Id) ->
-    node_flat_odbc:get_item_name(Host, Node, Id).
+    node_flat_sql:get_item_name(Host, Node, Id).
 
 get_last_items(Nidx, From, Count) ->
-    node_flat_odbc:get_last_items(Nidx, From, Count).
+    node_flat_sql:get_last_items(Nidx, From, Count).
 
 node_to_path(Node) ->
     node_hometree:node_to_path(Node).
similarity index 68%
rename from src/node_mix_odbc.erl
rename to src/node_mix_sql.erl
index e7cc6883ad16d774698a7d4f8fe278417fc4125f..45d471d0838b72142f960068549ea16682383875 100644 (file)
@@ -6,7 +6,7 @@
 %%% @end
 %%% Created :  8 Mar 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
 %%%-------------------------------------------------------------------
--module(node_mix_odbc).
+-module(node_mix_sql).
 
 -behaviour(gen_pubsub_node).
 
 %%% API
 %%%===================================================================
 init(Host, ServerHost, Opts) ->
-    node_flat_odbc:init(Host, ServerHost, Opts).
+    node_flat_sql:init(Host, ServerHost, Opts).
 
 terminate(Host, ServerHost) ->
-    node_flat_odbc:terminate(Host, ServerHost).
+    node_flat_sql:terminate(Host, ServerHost).
 
 options() ->
     [{deliver_payloads, true},
@@ -72,98 +72,98 @@ features() ->
        <<"subscription-notifications">>].
 
 create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access) ->
-    node_flat_odbc:create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access).
+    node_flat_sql:create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access).
 
 create_node(Nidx, Owner) ->
-    node_flat_odbc:create_node(Nidx, Owner).
+    node_flat_sql:create_node(Nidx, Owner).
 
 delete_node(Removed) ->
-    node_flat_odbc:delete_node(Removed).
+    node_flat_sql:delete_node(Removed).
 
 subscribe_node(Nidx, Sender, Subscriber, AccessModel,
            SendLast, PresenceSubscription, RosterGroup, Options) ->
-    node_flat_odbc:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
+    node_flat_sql:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
        PresenceSubscription, RosterGroup, Options).
 
 unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
-    node_flat_odbc:unsubscribe_node(Nidx, Sender, Subscriber, SubId).
+    node_flat_sql:unsubscribe_node(Nidx, Sender, Subscriber, SubId).
 
 publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload) ->
-    node_flat_odbc:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
+    node_flat_sql:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
 
 remove_extra_items(Nidx, MaxItems, ItemIds) ->
-    node_flat_odbc:remove_extra_items(Nidx, MaxItems, ItemIds).
+    node_flat_sql:remove_extra_items(Nidx, MaxItems, ItemIds).
 
 delete_item(Nidx, Publisher, PublishModel, ItemId) ->
-    node_flat_odbc:delete_item(Nidx, Publisher, PublishModel, ItemId).
+    node_flat_sql:delete_item(Nidx, Publisher, PublishModel, ItemId).
 
 purge_node(Nidx, Owner) ->
-    node_flat_odbc:purge_node(Nidx, Owner).
+    node_flat_sql:purge_node(Nidx, Owner).
 
 get_entity_affiliations(Host, Owner) ->
-    node_flat_odbc:get_entity_affiliations(Host, Owner).
+    node_flat_sql:get_entity_affiliations(Host, Owner).
 
 get_node_affiliations(Nidx) ->
-    node_flat_odbc:get_node_affiliations(Nidx).
+    node_flat_sql:get_node_affiliations(Nidx).
 
 get_affiliation(Nidx, Owner) ->
-    node_flat_odbc:get_affiliation(Nidx, Owner).
+    node_flat_sql:get_affiliation(Nidx, Owner).
 
 set_affiliation(Nidx, Owner, Affiliation) ->
-    node_flat_odbc:set_affiliation(Nidx, Owner, Affiliation).
+    node_flat_sql:set_affiliation(Nidx, Owner, Affiliation).
 
 get_entity_subscriptions(Host, Owner) ->
-    node_flat_odbc:get_entity_subscriptions(Host, Owner).
+    node_flat_sql:get_entity_subscriptions(Host, Owner).
 
 get_node_subscriptions(Nidx) ->
-    node_flat_odbc:get_node_subscriptions(Nidx).
+    node_flat_sql:get_node_subscriptions(Nidx).
 
 get_subscriptions(Nidx, Owner) ->
-    node_flat_odbc:get_subscriptions(Nidx, Owner).
+    node_flat_sql:get_subscriptions(Nidx, Owner).
 
 set_subscriptions(Nidx, Owner, Subscription, SubId) ->
-    node_flat_odbc:set_subscriptions(Nidx, Owner, Subscription, SubId).
+    node_flat_sql:set_subscriptions(Nidx, Owner, Subscription, SubId).
 
 get_pending_nodes(Host, Owner) ->
-    node_flat_odbc:get_pending_nodes(Host, Owner).
+    node_flat_sql:get_pending_nodes(Host, Owner).
 
 get_states(Nidx) ->
-    node_flat_odbc:get_states(Nidx).
+    node_flat_sql:get_states(Nidx).
 
 get_state(Nidx, JID) ->
-    node_flat_odbc:get_state(Nidx, JID).
+    node_flat_sql:get_state(Nidx, JID).
 
 set_state(State) ->
-    node_flat_odbc:set_state(State).
+    node_flat_sql:set_state(State).
 
 get_items(Nidx, From, RSM) ->
-    node_flat_odbc:get_items(Nidx, From, RSM).
+    node_flat_sql:get_items(Nidx, From, RSM).
 
 get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
-    node_flat_odbc:get_items(Nidx, JID, AccessModel,
+    node_flat_sql:get_items(Nidx, JID, AccessModel,
        PresenceSubscription, RosterGroup, SubId, RSM).
 
 get_item(Nidx, ItemId) ->
-    node_flat_odbc:get_item(Nidx, ItemId).
+    node_flat_sql:get_item(Nidx, ItemId).
 
 get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
-    node_flat_odbc:get_item(Nidx, ItemId, JID, AccessModel,
+    node_flat_sql:get_item(Nidx, ItemId, JID, AccessModel,
        PresenceSubscription, RosterGroup, SubId).
 
 set_item(Item) ->
-    node_flat_odbc:set_item(Item).
+    node_flat_sql:set_item(Item).
 
 get_item_name(Host, Node, Id) ->
-    node_flat_odbc:get_item_name(Host, Node, Id).
+    node_flat_sql:get_item_name(Host, Node, Id).
 
 node_to_path(Node) ->
-    node_flat_odbc:node_to_path(Node).
+    node_flat_sql:node_to_path(Node).
 
 path_to_node(Path) ->
-    node_flat_odbc:path_to_node(Path).
+    node_flat_sql:path_to_node(Path).
 
 get_entity_subscriptions_for_send_last(Host, Owner) ->
-    node_flat_odbc:get_entity_subscriptions_for_send_last(Host, Owner).
+    node_flat_sql:get_entity_subscriptions_for_send_last(Host, Owner).
 
 %%%===================================================================
 %%% Internal functions
similarity index 72%
rename from src/node_pep_odbc.erl
rename to src/node_pep_sql.erl
index 6eb0de040343afc9ce04285f63573e45ba0128a2..c5b31d15fab55f8179049bcc640642496740cae2 100644 (file)
@@ -1,5 +1,5 @@
 %%%----------------------------------------------------------------------
-%%% File    : node_pep_odbc.erl
+%%% File    : node_pep_sql.erl
 %%% Author  : Christophe Romain <christophe.romain@process-one.net>
 %%% Purpose : Standard PubSub PEP plugin with ODBC backend
 %%% Created :  1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
@@ -26,7 +26,7 @@
 %%% @doc The module <strong>{@module}</strong> is the pep PubSub plugin.
 %%% <p>PubSub plugin nodes are using the {@link gen_pubsub_node} behaviour.</p>
 
--module(node_pep_odbc).
+-module(node_pep_sql).
 -behaviour(gen_pubsub_node).
 -author('christophe.romain@process-one.net').
 
     get_entity_subscriptions_for_send_last/2, get_last_items/3]).
 
 init(Host, ServerHost, Opts) ->
-    node_flat_odbc:init(Host, ServerHost, Opts),
+    node_flat_sql:init(Host, ServerHost, Opts),
     complain_if_modcaps_disabled(ServerHost),
     ok.
 
 terminate(Host, ServerHost) ->
-    node_flat_odbc:terminate(Host, ServerHost),
+    node_flat_sql:terminate(Host, ServerHost),
     ok.
 
 options() ->
-    [{odbc, true}, {rsm, true} | node_pep:options()].
+    [{sql, true}, {rsm, true} | node_pep:options()].
 
 features() ->
     [<<"rsm">> | node_pep:features()].
@@ -67,56 +67,56 @@ create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access) ->
     node_pep:create_node_permission(Host, ServerHost, Node, ParentNode, Owner, Access).
 
 create_node(Nidx, Owner) ->
-    node_flat_odbc:create_node(Nidx, Owner),
+    node_flat_sql:create_node(Nidx, Owner),
     {result, {default, broadcast}}.
 
 delete_node(Nodes) ->
-    {result, {_, _, Result}} = node_flat_odbc:delete_node(Nodes),
+    {result, {_, _, Result}} = node_flat_sql:delete_node(Nodes),
     {result, {[], Result}}.
 
 subscribe_node(Nidx, Sender, Subscriber, AccessModel,
            SendLast, PresenceSubscription, RosterGroup, Options) ->
-    node_flat_odbc:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
+    node_flat_sql:subscribe_node(Nidx, Sender, Subscriber, AccessModel, SendLast,
        PresenceSubscription, RosterGroup, Options).
 
 
 unsubscribe_node(Nidx, Sender, Subscriber, SubId) ->
-    case node_flat_odbc:unsubscribe_node(Nidx, Sender, Subscriber, SubId) of
+    case node_flat_sql:unsubscribe_node(Nidx, Sender, Subscriber, SubId) of
        {error, Error} -> {error, Error};
        {result, _} -> {result, []}
     end.
 
 publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload) ->
-    node_flat_odbc:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
+    node_flat_sql:publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload).
 
 remove_extra_items(Nidx, MaxItems, ItemIds) ->
-    node_flat_odbc:remove_extra_items(Nidx, MaxItems, ItemIds).
+    node_flat_sql:remove_extra_items(Nidx, MaxItems, ItemIds).
 
 delete_item(Nidx, Publisher, PublishModel, ItemId) ->
-    node_flat_odbc:delete_item(Nidx, Publisher, PublishModel, ItemId).
+    node_flat_sql:delete_item(Nidx, Publisher, PublishModel, ItemId).
 
 purge_node(Nidx, Owner) ->
-    node_flat_odbc:purge_node(Nidx, Owner).
+    node_flat_sql:purge_node(Nidx, Owner).
 
 get_entity_affiliations(_Host, Owner) ->
     OwnerKey = jid:tolower(jid:remove_resource(Owner)),
-    node_flat_odbc:get_entity_affiliations(OwnerKey, Owner).
+    node_flat_sql:get_entity_affiliations(OwnerKey, Owner).
 
 get_node_affiliations(Nidx) ->
-    node_flat_odbc:get_node_affiliations(Nidx).
+    node_flat_sql:get_node_affiliations(Nidx).
 
 get_affiliation(Nidx, Owner) ->
-    node_flat_odbc:get_affiliation(Nidx, Owner).
+    node_flat_sql:get_affiliation(Nidx, Owner).
 
 set_affiliation(Nidx, Owner, Affiliation) ->
-    node_flat_odbc:set_affiliation(Nidx, Owner, Affiliation).
+    node_flat_sql:set_affiliation(Nidx, Owner, Affiliation).
 
 get_entity_subscriptions(_Host, Owner) ->
     SubKey = jid:tolower(Owner),
     GenKey = jid:remove_resource(SubKey),
-    Host = node_flat_odbc:encode_host(element(2, SubKey)),
-    SJ = node_flat_odbc:encode_jid(SubKey),
-    GJ = node_flat_odbc:encode_jid(GenKey),
+    Host = node_flat_sql:encode_host(element(2, SubKey)),
+    SJ = node_flat_sql:encode_jid(SubKey),
+    GJ = node_flat_sql:encode_jid(GenKey),
     Query = case SubKey of
        GenKey ->
            [<<"select host, node, type, i.nodeid, jid, "
@@ -129,16 +129,16 @@ get_entity_subscriptions(_Host, Owner) ->
                    "where i.nodeid = n.nodeid and jid "
                    "in ('">>, SJ, <<"', '">>, GJ, <<"') and host like '%@">>, Host, <<"';">>]
     end,
-    Reply = case catch ejabberd_odbc:sql_query_t(Query) of
+    Reply = case catch ejabberd_sql:sql_query_t(Query) of
        {selected,
                    [<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>],
                    RItems} ->
            lists:map(fun ([H, N, T, I, J, S]) ->
-                       O = node_flat_odbc:decode_jid(H),
-                       Node = nodetree_tree_odbc:raw_to_node(O, [N, <<"">>, T, I]),
+                       O = node_flat_sql:decode_jid(H),
+                       Node = nodetree_tree_sql:raw_to_node(O, [N, <<"">>, T, I]),
                        {Node,
-                           node_flat_odbc:decode_subscriptions(S),
-                           node_flat_odbc:decode_jid(J)}
+                           node_flat_sql:decode_subscriptions(S),
+                           node_flat_sql:decode_jid(J)}
                end,
                RItems);
        _ ->
@@ -149,9 +149,9 @@ get_entity_subscriptions(_Host, Owner) ->
 get_entity_subscriptions_for_send_last(_Host, Owner) ->
     SubKey = jid:tolower(Owner),
     GenKey = jid:remove_resource(SubKey),
-    Host = node_flat_odbc:encode_host(element(2, SubKey)),
-    SJ = node_flat_odbc:encode_jid(SubKey),
-    GJ = node_flat_odbc:encode_jid(GenKey),
+    Host = node_flat_sql:encode_host(element(2, SubKey)),
+    SJ = node_flat_sql:encode_jid(SubKey),
+    GJ = node_flat_sql:encode_jid(GenKey),
     Query = case SubKey of
        GenKey ->
            [<<"select host, node, type, i.nodeid, jid, "
@@ -168,16 +168,16 @@ get_entity_subscriptions_for_send_last(_Host, Owner) ->
                    "val='on_sub_and_presence' and jid in ",
                    "('">>, SJ, <<"', '">>, GJ, <<"') and host like '%@">>, Host, <<"';">>]
     end,
-    Reply = case catch ejabberd_odbc:sql_query_t(Query) of
+    Reply = case catch ejabberd_sql:sql_query_t(Query) of
        {selected,
                    [<<"host">>, <<"node">>, <<"type">>, <<"nodeid">>, <<"jid">>, <<"subscriptions">>],
                    RItems} ->
            lists:map(fun ([H, N, T, I, J, S]) ->
-                       O = node_flat_odbc:decode_jid(H),
-                       Node = nodetree_tree_odbc:raw_to_node(O, [N, <<"">>, T, I]),
+                       O = node_flat_sql:decode_jid(H),
+                       Node = nodetree_tree_sql:raw_to_node(O, [N, <<"">>, T, I]),
                        {Node,
-                           node_flat_odbc:decode_subscriptions(S),
-                           node_flat_odbc:decode_jid(J)}
+                           node_flat_sql:decode_subscriptions(S),
+                           node_flat_sql:decode_jid(J)}
                end,
                RItems);
        _ ->
@@ -186,54 +186,54 @@ get_entity_subscriptions_for_send_last(_Host, Owner) ->
     {result, Reply}.
 
 get_node_subscriptions(Nidx) ->
-    node_flat_odbc:get_node_subscriptions(Nidx).
+    node_flat_sql:get_node_subscriptions(Nidx).
 
 get_subscriptions(Nidx, Owner) ->
-    node_flat_odbc:get_subscriptions(Nidx, Owner).
+    node_flat_sql:get_subscriptions(Nidx, Owner).
 
 set_subscriptions(Nidx, Owner, Subscription, SubId) ->
-    node_flat_odbc:set_subscriptions(Nidx, Owner, Subscription, SubId).
+    node_flat_sql:set_subscriptions(Nidx, Owner, Subscription, SubId).
 
 get_pending_nodes(Host, Owner) ->
-    node_flat_odbc:get_pending_nodes(Host, Owner).
+    node_flat_sql:get_pending_nodes(Host, Owner).
 
 get_states(Nidx) ->
-    node_flat_odbc:get_states(Nidx).
+    node_flat_sql:get_states(Nidx).
 
 get_state(Nidx, JID) ->
-    node_flat_odbc:get_state(Nidx, JID).
+    node_flat_sql:get_state(Nidx, JID).
 
 set_state(State) ->
-    node_flat_odbc:set_state(State).
+    node_flat_sql:set_state(State).
 
 get_items(Nidx, From, RSM) ->
-    node_flat_odbc:get_items(Nidx, From, RSM).
+    node_flat_sql:get_items(Nidx, From, RSM).
 
 get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, SubId, RSM) ->
-    node_flat_odbc:get_items(Nidx, JID, AccessModel,
+    node_flat_sql:get_items(Nidx, JID, AccessModel,
        PresenceSubscription, RosterGroup, SubId, RSM).
 
 get_last_items(Nidx, JID, Count) ->
-    node_flat_odbc:get_last_items(Nidx, JID, Count).
+    node_flat_sql:get_last_items(Nidx, JID, Count).
 
 get_item(Nidx, ItemId) ->
-    node_flat_odbc:get_item(Nidx, ItemId).
+    node_flat_sql:get_item(Nidx, ItemId).
 
 get_item(Nidx, ItemId, JID, AccessModel, PresenceSubscription, RosterGroup, SubId) ->
-    node_flat_odbc:get_item(Nidx, ItemId, JID, AccessModel,
+    node_flat_sql:get_item(Nidx, ItemId, JID, AccessModel,
        PresenceSubscription, RosterGroup, SubId).
 
 set_item(Item) ->
-    node_flat_odbc:set_item(Item).
+    node_flat_sql:set_item(Item).
 
 get_item_name(Host, Node, Id) ->
-    node_flat_odbc:get_item_name(Host, Node, Id).
+    node_flat_sql:get_item_name(Host, Node, Id).
 
 node_to_path(Node) ->
-    node_flat_odbc:node_to_path(Node).
+    node_flat_sql:node_to_path(Node).
 
 path_to_node(Path) ->
-    node_flat_odbc:path_to_node(Path).
+    node_flat_sql:path_to_node(Path).
 
 %%%
 %%% Internal
similarity index 82%
rename from src/nodetree_tree_odbc.erl
rename to src/nodetree_tree_sql.erl
index 6c139ad6cc614d99512902494068cb6fc8a2f584..b56543395a4cae3d37bf9bd8d1db144a71af0add 100644 (file)
@@ -1,5 +1,5 @@
 %%%----------------------------------------------------------------------
-%%% File    : nodetree_tree_odbc.erl
+%%% File    : nodetree_tree_sql.erl
 %%% Author  : Christophe Romain <christophe.romain@process-one.net>
 %%% Purpose : Standard node tree plugin with ODBC backend
 %%% Created :  1 Dec 2007 by Christophe Romain <christophe.romain@process-one.net>
@@ -33,7 +33,7 @@
 %%% useable and useful as is. Please, send us comments, feedback and
 %%% improvements.</p>
 
--module(nodetree_tree_odbc).
+-module(nodetree_tree_sql).
 -behaviour(gen_pubsub_nodetree).
 -author('christophe.romain@process-one.net').
 
@@ -55,7 +55,7 @@ terminate(_Host, _ServerHost) ->
     ok.
 
 options() ->
-    [{odbc, true} | nodetree_tree:options()].
+    [{sql, true} | nodetree_tree:options()].
 
 set_node(Record) when is_record(Record, pubsub_node) ->
     {Host, Node} = Record#pubsub_node.nodeid,
@@ -64,16 +64,16 @@ set_node(Record) when is_record(Record, pubsub_node) ->
        [First | _] -> First
     end,
     Type = Record#pubsub_node.type,
-    H = node_flat_odbc:encode_host(Host),
-    N = ejabberd_odbc:escape(Node),
-    P = ejabberd_odbc:escape(Parent),
+    H = node_flat_sql:encode_host(Host),
+    N = ejabberd_sql:escape(Node),
+    P = ejabberd_sql:escape(Parent),
     Nidx = case nodeidx(Host, Node) of
        {result, OldNidx} ->
            catch
-           ejabberd_odbc:sql_query_t([<<"delete from pubsub_node_option where "
+           ejabberd_sql:sql_query_t([<<"delete from pubsub_node_option where "
                        "nodeid='">>, OldNidx, <<"';">>]),
            catch
-           ejabberd_odbc:sql_query_t([<<"update pubsub_node set host='">>,
+           ejabberd_sql:sql_query_t([<<"update pubsub_node set host='">>,
                    H, <<"' node='">>, N,
                    <<"' parent='">>, P,
                    <<"' type='">>, Type,
@@ -82,7 +82,7 @@ set_node(Record) when is_record(Record, pubsub_node) ->
            OldNidx;
        _ ->
            catch
-           ejabberd_odbc:sql_query_t([<<"insert into pubsub_node(host, node, "
+           ejabberd_sql:sql_query_t([<<"insert into pubsub_node(host, node, "
                        "parent, type) values('">>,
                    H, <<"', '">>, N, <<"', '">>, P,
                    <<"', '">>, Type, <<"');">>]),
@@ -98,11 +98,11 @@ set_node(Record) when is_record(Record, pubsub_node) ->
        _ ->
            lists:foreach(fun ({Key, Value}) ->
                        SKey = iolist_to_binary(atom_to_list(Key)),
-                       SValue = ejabberd_odbc:escape(
+                       SValue = ejabberd_sql:escape(
                                list_to_binary(
                                    lists:flatten(io_lib:fwrite("~p", [Value])))),
                        catch
-                       ejabberd_odbc:sql_query_t([<<"insert into pubsub_node_option(nodeid, "
+                       ejabberd_sql:sql_query_t([<<"insert into pubsub_node_option(nodeid, "
                                    "name, val) values('">>,
                                Nidx, <<"', '">>,
                                SKey, <<"', '">>, SValue, <<"');">>])
@@ -115,10 +115,10 @@ get_node(Host, Node, _From) ->
     get_node(Host, Node).
 
 get_node(Host, Node) ->
-    H = node_flat_odbc:encode_host(Host),
-    N = ejabberd_odbc:escape(Node),
+    H = node_flat_sql:encode_host(Host),
+    N = ejabberd_sql:escape(Node),
     case catch
-       ejabberd_odbc:sql_query_t([<<"select node, parent, type, nodeid from "
+       ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from "
                    "pubsub_node where host='">>,
                H, <<"' and node='">>, N, <<"';">>])
     of
@@ -133,7 +133,7 @@ get_node(Host, Node) ->
 
 get_node(Nidx) ->
     case catch
-       ejabberd_odbc:sql_query_t([<<"select host, node, parent, type from "
+       ejabberd_sql:sql_query_t([<<"select host, node, parent, type from "
                    "pubsub_node where nodeid='">>,
                Nidx, <<"';">>])
     of
@@ -150,9 +150,9 @@ get_nodes(Host, _From) ->
     get_nodes(Host).
 
 get_nodes(Host) ->
-    H = node_flat_odbc:encode_host(Host),
+    H = node_flat_sql:encode_host(Host),
     case catch
-       ejabberd_odbc:sql_query_t([<<"select node, parent, type, nodeid from "
+       ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from "
                    "pubsub_node where host='">>, H, <<"';">>])
     of
        {selected,
@@ -177,10 +177,10 @@ get_subnodes(Host, Node, _From) ->
     get_subnodes(Host, Node).
 
 get_subnodes(Host, Node) ->
-    H = node_flat_odbc:encode_host(Host),
-    N = ejabberd_odbc:escape(Node),
+    H = node_flat_sql:encode_host(Host),
+    N = ejabberd_sql:escape(Node),
     case catch
-       ejabberd_odbc:sql_query_t([<<"select node, parent, type, nodeid from "
+       ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from "
                    "pubsub_node where host='">>,
                H, <<"' and parent='">>, N, <<"';">>])
     of
@@ -195,10 +195,10 @@ get_subnodes_tree(Host, Node, _From) ->
     get_subnodes_tree(Host, Node).
 
 get_subnodes_tree(Host, Node) ->
-    H = node_flat_odbc:encode_host(Host),
-    N = ejabberd_odbc:escape(Node),
+    H = node_flat_sql:encode_host(Host),
+    N = ejabberd_sql:escape(Node),
     case catch
-       ejabberd_odbc:sql_query_t([<<"select node, parent, type, nodeid from "
+       ejabberd_sql:sql_query_t([<<"select node, parent, type, nodeid from "
                    "pubsub_node where host='">>,
                H, <<"' and node like '">>, N, <<"%';">>])
     of
@@ -255,17 +255,17 @@ create_node(Host, Node, Type, Owner, Options, Parents) ->
     end.
 
 delete_node(Host, Node) ->
-    H = node_flat_odbc:encode_host(Host),
-    N = ejabberd_odbc:escape(Node),
+    H = node_flat_sql:encode_host(Host),
+    N = ejabberd_sql:escape(Node),
     Removed = get_subnodes_tree(Host, Node),
-    catch ejabberd_odbc:sql_query_t([<<"delete from pubsub_node where host='">>,
+    catch ejabberd_sql:sql_query_t([<<"delete from pubsub_node where host='">>,
            H, <<"' and node like '">>, N, <<"%';">>]),
     Removed.
 
 %% helpers
 raw_to_node(Host, [Node, Parent, Type, Nidx]) ->
     Options = case catch
-       ejabberd_odbc:sql_query_t([<<"select name,val from pubsub_node_option "
+       ejabberd_sql:sql_query_t([<<"select name,val from pubsub_node_option "
                    "where nodeid='">>, Nidx, <<"';">>])
     of
        {selected, [<<"name">>, <<"val">>], ROptions} ->
@@ -276,7 +276,7 @@ raw_to_node(Host, [Node, Parent, Type, Nidx]) ->
                            {RKey, RValue}
                    end,
                    ROptions),
-           Module = jlib:binary_to_atom(<<"node_", Type/binary, "_odbc">>),
+           Module = jlib:binary_to_atom(<<"node_", Type/binary, "_sql">>),
            StdOpts = Module:options(),
            lists:foldl(fun ({Key, Value}, Acc) ->
                        lists:keyreplace(Key, 1, Acc, {Key, Value})
@@ -294,10 +294,10 @@ raw_to_node(Host, [Node, Parent, Type, Nidx]) ->
        id = Nidx, type = Type, options = Options}.
 
 nodeidx(Host, Node) ->
-    H = node_flat_odbc:encode_host(Host),
-    N = ejabberd_odbc:escape(Node),
+    H = node_flat_sql:encode_host(Host),
+    N = ejabberd_sql:escape(Node),
     case catch
-       ejabberd_odbc:sql_query_t([<<"select nodeid from pubsub_node where "
+       ejabberd_sql:sql_query_t([<<"select nodeid from pubsub_node where "
                    "host='">>,
                H, <<"' and node='">>, N, <<"';">>])
     of
@@ -310,5 +310,5 @@ nodeidx(Host, Node) ->
     end.
 
 nodeowners(Nidx) ->
-    {result, Res} = node_flat_odbc:get_node_affiliations(Nidx),
+    {result, Res} = node_flat_sql:get_node_affiliations(Nidx),
     [LJID || {LJID, Aff} <- Res, Aff =:= owner].
similarity index 57%
rename from src/pubsub_db_odbc.erl
rename to src/pubsub_db_sql.erl
index cfdeda1ef602c0c7c800c4a1773dd5aa1454583c..b910a5e7db48bdda17fcaff4a377e49bb01a427b 100644 (file)
@@ -1,5 +1,5 @@
 %%%----------------------------------------------------------------------
-%%% File    : pubsub_db_odbc.erl
+%%% File    : pubsub_db_sql.erl
 %%% Author  : Pablo Polvorin <pablo.polvorin@process-one.net>
 %%% Purpose : Provide helpers for PubSub ODBC backend
 %%% Created :  7 Aug 2009 by Pablo Polvorin <pablo.polvorin@process-one.net>
@@ -23,7 +23,7 @@
 %%%
 %%%----------------------------------------------------------------------
 
--module(pubsub_db_odbc).
+-module(pubsub_db_sql).
 
 -author("pablo.polvorin@process-one.net").
 
 %% -spec read_subscription(SubID :: string()) -> {ok, #pubsub_subscription{}} |  notfound.
 read_subscription(SubID) ->
     case
-       ejabberd_odbc:sql_query_t([<<"select opt_name, opt_value from pubsub_subscr"
+       ejabberd_sql:sql_query_t([<<"select opt_name, opt_value from pubsub_subscr"
                    "iption_opt where subid = '">>,
-               ejabberd_odbc:escape(SubID), <<"'">>])
+               ejabberd_sql:escape(SubID), <<"'">>])
     of
        {selected, [<<"opt_name">>, <<"opt_value">>], []} ->
            notfound;
        {selected, [<<"opt_name">>, <<"opt_value">>], Options} ->
            {ok,
                #pubsub_subscription{subid = SubID,
-                   options = lists:map(fun subscription_opt_from_odbc/1, Options)}}
+                   options = lists:map(fun subscription_opt_from_sql/1, Options)}}
     end.
 
 %% -spec delete_subscription(SubID :: string()) -> ok.
@@ -54,19 +54,19 @@ delete_subscription(SubID) ->
     %% -spec update_subscription(#pubsub_subscription{}) -> ok .
     %% -spec add_subscription(#pubsub_subscription{}) -> ok.
     %% -------------- Internal utilities -----------------------
-    ejabberd_odbc:sql_query_t([<<"delete from pubsub_subscription_opt "
+    ejabberd_sql:sql_query_t([<<"delete from pubsub_subscription_opt "
                "where subid = '">>,
-           ejabberd_odbc:escape(SubID), <<"'">>]),
+           ejabberd_sql:escape(SubID), <<"'">>]),
     ok.
 
 update_subscription(#pubsub_subscription{subid = SubId} = Sub) ->
     delete_subscription(SubId), add_subscription(Sub).
 
 add_subscription(#pubsub_subscription{subid = SubId, options = Opts}) ->
-    EscapedSubId = ejabberd_odbc:escape(SubId),
+    EscapedSubId = ejabberd_sql:escape(SubId),
     lists:foreach(fun (Opt) ->
-               {OdbcOptName, OdbcOptValue} = subscription_opt_to_odbc(Opt),
-               ejabberd_odbc:sql_query_t([<<"insert into pubsub_subscription_opt(subid, "
+               {OdbcOptName, OdbcOptValue} = subscription_opt_to_sql(Opt),
+               ejabberd_sql:sql_query_t([<<"insert into pubsub_subscription_opt(subid, "
                            "opt_name, opt_value)values ('">>,
                        EscapedSubId, <<"','">>,
                        OdbcOptName, <<"','">>,
@@ -75,67 +75,67 @@ add_subscription(#pubsub_subscription{subid = SubId, options = Opts}) ->
        Opts),
     ok.
 
-subscription_opt_from_odbc({<<"DELIVER">>, Value}) ->
-    {deliver, odbc_to_boolean(Value)};
-subscription_opt_from_odbc({<<"DIGEST">>, Value}) ->
-    {digest, odbc_to_boolean(Value)};
-subscription_opt_from_odbc({<<"DIGEST_FREQUENCY">>, Value}) ->
-    {digest_frequency, odbc_to_integer(Value)};
-subscription_opt_from_odbc({<<"EXPIRE">>, Value}) ->
-    {expire, odbc_to_timestamp(Value)};
-subscription_opt_from_odbc({<<"INCLUDE_BODY">>, Value}) ->
-    {include_body, odbc_to_boolean(Value)};
+subscription_opt_from_sql({<<"DELIVER">>, Value}) ->
+    {deliver, sql_to_boolean(Value)};
+subscription_opt_from_sql({<<"DIGEST">>, Value}) ->
+    {digest, sql_to_boolean(Value)};
+subscription_opt_from_sql({<<"DIGEST_FREQUENCY">>, Value}) ->
+    {digest_frequency, sql_to_integer(Value)};
+subscription_opt_from_sql({<<"EXPIRE">>, Value}) ->
+    {expire, sql_to_timestamp(Value)};
+subscription_opt_from_sql({<<"INCLUDE_BODY">>, Value}) ->
+    {include_body, sql_to_boolean(Value)};
 %%TODO: might be > than 1 show_values value??.
 %%      need to use compact all in only 1 opt.
-subscription_opt_from_odbc({<<"SHOW_VALUES">>, Value}) ->
+subscription_opt_from_sql({<<"SHOW_VALUES">>, Value}) ->
     {show_values, Value};
-subscription_opt_from_odbc({<<"SUBSCRIPTION_TYPE">>, Value}) ->
+subscription_opt_from_sql({<<"SUBSCRIPTION_TYPE">>, Value}) ->
     {subscription_type,
        case Value of
            <<"items">> -> items;
            <<"nodes">> -> nodes
        end};
-subscription_opt_from_odbc({<<"SUBSCRIPTION_DEPTH">>, Value}) ->
+subscription_opt_from_sql({<<"SUBSCRIPTION_DEPTH">>, Value}) ->
     {subscription_depth,
        case Value of
            <<"all">> -> all;
-           N -> odbc_to_integer(N)
+           N -> sql_to_integer(N)
        end}.
 
-subscription_opt_to_odbc({deliver, Bool}) ->
-    {<<"DELIVER">>, boolean_to_odbc(Bool)};
-subscription_opt_to_odbc({digest, Bool}) ->
-    {<<"DIGEST">>, boolean_to_odbc(Bool)};
-subscription_opt_to_odbc({digest_frequency, Int}) ->
-    {<<"DIGEST_FREQUENCY">>, integer_to_odbc(Int)};
-subscription_opt_to_odbc({expire, Timestamp}) ->
-    {<<"EXPIRE">>, timestamp_to_odbc(Timestamp)};
-subscription_opt_to_odbc({include_body, Bool}) ->
-    {<<"INCLUDE_BODY">>, boolean_to_odbc(Bool)};
-subscription_opt_to_odbc({show_values, Values}) ->
+subscription_opt_to_sql({deliver, Bool}) ->
+    {<<"DELIVER">>, boolean_to_sql(Bool)};
+subscription_opt_to_sql({digest, Bool}) ->
+    {<<"DIGEST">>, boolean_to_sql(Bool)};
+subscription_opt_to_sql({digest_frequency, Int}) ->
+    {<<"DIGEST_FREQUENCY">>, integer_to_sql(Int)};
+subscription_opt_to_sql({expire, Timestamp}) ->
+    {<<"EXPIRE">>, timestamp_to_sql(Timestamp)};
+subscription_opt_to_sql({include_body, Bool}) ->
+    {<<"INCLUDE_BODY">>, boolean_to_sql(Bool)};
+subscription_opt_to_sql({show_values, Values}) ->
     {<<"SHOW_VALUES">>, Values};
-subscription_opt_to_odbc({subscription_type, Type}) ->
+subscription_opt_to_sql({subscription_type, Type}) ->
     {<<"SUBSCRIPTION_TYPE">>,
        case Type of
            items -> <<"items">>;
            nodes -> <<"nodes">>
        end};
-subscription_opt_to_odbc({subscription_depth, Depth}) ->
+subscription_opt_to_sql({subscription_depth, Depth}) ->
     {<<"SUBSCRIPTION_DEPTH">>,
        case Depth of
            all -> <<"all">>;
-           N -> integer_to_odbc(N)
+           N -> integer_to_sql(N)
        end}.
 
-integer_to_odbc(N) -> iolist_to_binary(integer_to_list(N)).
+integer_to_sql(N) -> iolist_to_binary(integer_to_list(N)).
 
-boolean_to_odbc(true) -> <<"1">>;
-boolean_to_odbc(false) -> <<"0">>.
+boolean_to_sql(true) -> <<"1">>;
+boolean_to_sql(false) -> <<"0">>.
 
-timestamp_to_odbc(T) -> jlib:now_to_utc_string(T).
+timestamp_to_sql(T) -> jlib:now_to_utc_string(T).
 
-odbc_to_integer(N) -> jlib:binary_to_integer(N).
+sql_to_integer(N) -> jlib:binary_to_integer(N).
 
-odbc_to_boolean(B) -> B == <<"1">>.
+sql_to_boolean(B) -> B == <<"1">>.
 
-odbc_to_timestamp(T) -> jlib:datetime_string_to_timestamp(T).
+sql_to_timestamp(T) -> jlib:datetime_string_to_timestamp(T).
similarity index 99%
rename from src/pubsub_subscription_odbc.erl
rename to src/pubsub_subscription_sql.erl
index afd31c81890567d13aef9cc4c0c3bac98917737f..1f82aa008ed51aac1168e33d2cb4188b3fd5e5d1 100644 (file)
@@ -1,5 +1,5 @@
 %%%----------------------------------------------------------------------
-%%% File    : pubsub_subscription_odbc.erl
+%%% File    : pubsub_subscription_sql.erl
 %%% Author  : Pablo Polvorin <pablo.polvorin@process-one.net>
 %%% Purpose : Handle pubsub subscriptions options with ODBC backend
 %%%           based on pubsub_subscription.erl by Brian Cully <bjc@kublai.com>
@@ -24,7 +24,7 @@
 %%%
 %%%----------------------------------------------------------------------
 
--module(pubsub_subscription_odbc).
+-module(pubsub_subscription_sql).
 -author("pablo.polvorin@process-one.net").
 
 %% API
@@ -66,7 +66,7 @@
 -define(SUBSCRIPTION_DEPTH_VALUE_ONE_LABEL, <<"Receive notification from direct child nodes only">>).
 -define(SUBSCRIPTION_DEPTH_VALUE_ALL_LABEL, <<"Receive notification from all descendent nodes">>).
 
--define(DB_MOD, pubsub_db_odbc).
+-define(DB_MOD, pubsub_db_sql).
 %%====================================================================
 %% API
 %%====================================================================
similarity index 88%
rename from src/odbc_queries.erl
rename to src/sql_queries.erl
index c12931c6e06e4e7608f470905d8018b1ee80e828..98530a4cfcbad7a5d0ddc4e7e45f4de83b5962da 100644 (file)
@@ -1,5 +1,5 @@
 %%%----------------------------------------------------------------------
-%%% File    : odbc_queries.erl
+%%% File    : sql_queries.erl
 %%% Author  : Mickael Remond <mremond@process-one.net>
 %%% Purpose : ODBC queries dependind on back-end
 %%% Created : by Mickael Remond <mremond@process-one.net>
@@ -23,7 +23,7 @@
 %%%
 %%%----------------------------------------------------------------------
 
--module(odbc_queries).
+-module(sql_queries).
 
 -compile([{parse_transform, ejabberd_sql_pt}]).
 
@@ -78,13 +78,13 @@ update_t(Table, Fields, Vals, Where) ->
                                   <<A/binary, "='", B/binary, "'">>
                           end,
                           Fields, Vals),
-    case ejabberd_odbc:sql_query_t([<<"update ">>, Table,
+    case ejabberd_sql:sql_query_t([<<"update ">>, Table,
                                    <<" set ">>, join(UPairs, <<", ">>),
                                    <<" where ">>, Where, <<";">>])
        of
       {updated, 1} -> ok;
       _ ->
-               Res = ejabberd_odbc:sql_query_t([<<"insert into ">>, Table,
+               Res = ejabberd_sql:sql_query_t([<<"insert into ">>, Table,
                                     <<"(">>, join(Fields, <<", ">>),
                                     <<") values ('">>, join(Vals, <<"', '">>),
                                     <<"');">>]),
@@ -99,14 +99,14 @@ update(LServer, Table, Fields, Vals, Where) ->
                                   <<A/binary, "='", B/binary, "'">>
                           end,
                           Fields, Vals),
-    case ejabberd_odbc:sql_query(LServer,
+    case ejabberd_sql:sql_query(LServer,
                                 [<<"update ">>, Table, <<" set ">>,
                                  join(UPairs, <<", ">>), <<" where ">>, Where,
                                  <<";">>])
        of
       {updated, 1} -> ok;
       _ ->
-               Res = ejabberd_odbc:sql_query(LServer,
+               Res = ejabberd_sql:sql_query(LServer,
                                  [<<"insert into ">>, Table, <<"(">>,
                                   join(Fields, <<", ">>), <<") values ('">>,
                                   join(Vals, <<"', '">>), <<"');">>]),
@@ -118,12 +118,12 @@ update(LServer, Table, Fields, Vals, Where) ->
 
 %% 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)
+%% wrapper from the ejabberd_sql module to this one (sql_queries)
 sql_transaction(LServer, F) ->
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 get_last(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(seconds)d, @(state)s from last"
            " where username=%(LUser)s")).
@@ -135,24 +135,24 @@ set_last_t(LServer, LUser, TimeStamp, Status) ->
                  "state=%(Status)s"]).
 
 del_last(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("delete from last where username=%(LUser)s")).
 
 get_password(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(password)s from users where username=%(LUser)s")).
 
 get_password_scram(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(password)s, @(serverkey)s, @(salt)s, @(iterationcount)d"
            " from users"
            " where username=%(LUser)s")).
 
 set_password_t(LServer, LUser, Password) ->
-    ejabberd_odbc:sql_transaction(
+    ejabberd_sql:sql_transaction(
       LServer,
       fun () ->
               ?SQL_UPSERT_T(
@@ -163,7 +163,7 @@ set_password_t(LServer, LUser, Password) ->
 
 set_password_scram_t(LServer, LUser,
                      StoredKey, ServerKey, Salt, IterationCount) ->
-    ejabberd_odbc:sql_transaction(
+    ejabberd_sql:sql_transaction(
       LServer,
       fun () ->
               ?SQL_UPSERT_T(
@@ -176,14 +176,14 @@ set_password_scram_t(LServer, LUser,
       end).
 
 add_user(LServer, LUser, Password) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("insert into users(username, password) "
            "values (%(LUser)s, %(Password)s)")).
 
 add_user_scram(LServer, LUser,
                StoredKey, ServerKey, Salt, IterationCount) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("insert into users(username, password, serverkey, salt, "
            "iterationcount) "
@@ -191,21 +191,21 @@ add_user_scram(LServer, LUser,
            " %(Salt)s, %(IterationCount)d)")).
 
 del_user(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("delete from users where username=%(LUser)s")).
 
 del_user_return_password(_LServer, LUser, Password) ->
     P =
-       ejabberd_odbc:sql_query_t(
+       ejabberd_sql:sql_query_t(
           ?SQL("select @(password)s from users where username=%(LUser)s")),
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("delete from users"
            " where username=%(LUser)s and password=%(Password)s")),
     P.
 
 list_users(LServer) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(username)s from users")).
 
@@ -222,7 +222,7 @@ list_users(LServer,
                {offset, Start - 1}]);
 list_users(LServer, [{limit, Limit}, {offset, Offset}])
     when is_integer(Limit) and is_integer(Offset) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(username)s from users "
            "order by username "
@@ -231,9 +231,9 @@ list_users(LServer,
           [{prefix, Prefix}, {limit, Limit}, {offset, Offset}])
     when is_binary(Prefix) and is_integer(Limit) and
           is_integer(Offset) ->
-    SPrefix = ejabberd_odbc:escape_like_arg(Prefix),
+    SPrefix = ejabberd_sql:escape_like_arg(Prefix),
     SPrefix2 = <<SPrefix/binary, $%>>,
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(username)s from users "
            "where username like %(SPrefix2)s "
@@ -241,7 +241,7 @@ list_users(LServer,
            "limit %(Limit)d offset %(Offset)d")).
 
 users_number(LServer) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       fun(pgsql, _) ->
               case
@@ -250,100 +250,99 @@ users_number(LServer) ->
                     fun(V) when is_boolean(V) -> V end,
                     false) of
                   true ->
-                      ejabberd_odbc:sql_query_t(
+                      ejabberd_sql:sql_query_t(
                         ?SQL("select @(reltuples :: bigint)d from pg_class"
                              " where oid = 'users'::regclass::oid"));
                   _ ->
-                      ejabberd_odbc:sql_query_t(
+                      ejabberd_sql:sql_query_t(
                         ?SQL("select @(count(*))d from users"))
          end;
          (_Type, _) ->
-              ejabberd_odbc:sql_query_t(
+              ejabberd_sql:sql_query_t(
                 ?SQL("select @(count(*))d from users"))
       end).
 
 users_number(LServer, [{prefix, Prefix}])
     when is_binary(Prefix) ->
-    SPrefix = ejabberd_odbc:escape_like_arg(Prefix),
+    SPrefix = ejabberd_sql:escape_like_arg(Prefix),
     SPrefix2 = <<SPrefix/binary, $%>>,
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(count(*))d from users "
            "where username like %(SPrefix2)s"));
 users_number(LServer, []) ->
     users_number(LServer).
 
-
 add_spool_sql(Username, XML) ->
     [<<"insert into spool(username, xml) values ('">>,
      Username, <<"', '">>, XML, <<"');">>].
 
 add_spool(LServer, Queries) ->
-    ejabberd_odbc:sql_transaction(LServer, Queries).
+    ejabberd_sql:sql_transaction(LServer, Queries).
 
 get_and_del_spool_msg_t(LServer, LUser) ->
     F = fun () ->
                Result =
-                   ejabberd_odbc:sql_query_t(
+                   ejabberd_sql:sql_query_t(
                       ?SQL("select @(username)s, @(xml)s from spool where "
                            "username=%(LUser)s order by seq;")),
-               ejabberd_odbc:sql_query_t(
+               ejabberd_sql:sql_query_t(
                   ?SQL("delete from spool where username=%(LUser)s;")),
                Result
        end,
-    ejabberd_odbc:sql_transaction(LServer, F).
+    ejabberd_sql:sql_transaction(LServer, F).
 
 del_spool_msg(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("delete from spool where username=%(LUser)s")).
 
 get_roster(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(username)s, @(jid)s, @(nick)s, @(subscription)s, "
            "@(ask)s, @(askmessage)s, @(server)s, @(subscribe)s, "
            "@(type)s from rosterusers where username=%(LUser)s")).
 
 get_roster_jid_groups(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(jid)s, @(grp)s from rostergroups where "
            "username=%(LUser)s")).
 
 get_roster_groups(_LServer, LUser, SJID) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("select @(grp)s from rostergroups"
            " where username=%(LUser)s and jid=%(SJID)s")).
 
 del_user_roster_t(LServer, LUser) ->
-    ejabberd_odbc:sql_transaction(
+    ejabberd_sql:sql_transaction(
       LServer,
       fun () ->
-              ejabberd_odbc:sql_query_t(
+              ejabberd_sql:sql_query_t(
                 ?SQL("delete from rosterusers where username=%(LUser)s")),
-              ejabberd_odbc:sql_query_t(
+              ejabberd_sql:sql_query_t(
                 ?SQL("delete from rostergroups where username=%(LUser)s"))
       end).
 
 get_roster_by_jid(_LServer, LUser, SJID) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("select @(username)s, @(jid)s, @(nick)s, @(subscription)s,"
            " @(ask)s, @(askmessage)s, @(server)s, @(subscribe)s,"
            " @(type)s from rosterusers"
            " where username=%(LUser)s and jid=%(SJID)s")).
 
 get_rostergroup_by_jid(LServer, LUser, SJID) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(grp)s from rostergroups"
            " where username=%(LUser)s and jid=%(SJID)s")).
 
 del_roster(_LServer, LUser, SJID) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("delete from rosterusers"
            " where username=%(LUser)s and jid=%(SJID)s")),
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("delete from rostergroups"
            " where username=%(LUser)s and jid=%(SJID)s")).
 
@@ -358,12 +357,12 @@ del_roster_sql(Username, SJID) ->
 update_roster(_LServer, LUser, SJID, ItemVals,
              ItemGroups) ->
     roster_subscribe(ItemVals),
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("delete from rostergroups"
            " where username=%(LUser)s and jid=%(SJID)s")),
     lists:foreach(
       fun(ItemGroup) ->
-              ejabberd_odbc:sql_query_t(
+              ejabberd_sql:sql_query_t(
                 ?SQL("insert into rostergroups(username, jid, grp) "
                      "values (%(LUser)s, %(SJID)s, %(ItemGroup)s)"))
       end,
@@ -403,7 +402,7 @@ roster_subscribe({LUser, SJID, Name, SSubscription, SAsk, AskMessage}) ->
         "type='item'"]).
 
 get_subscription(LServer, LUser, SJID) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(subscription)s from rosterusers "
            "where username=%(LUser)s and jid=%(SJID)s")).
@@ -424,19 +423,19 @@ set_private_data_sql(Username, LXMLNS, SData) ->
       <<"');">>]].
 
 get_private_data(LServer, LUser, XMLNS) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(data)s from private_storage"
            " where username=%(LUser)s and namespace=%(XMLNS)s")).
 
 get_private_data(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(namespace)s, @(data)s from private_storage"
            " where username=%(LUser)s")).
 
 del_user_private_storage(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("delete from private_storage"
            " where username=%(LUser)s")).
@@ -446,7 +445,7 @@ set_vcard(LServer, LUser, BDay, CTRY, EMail, FN,
          LFamily, LGiven, LLocality, LMiddle, LNickname,
          LOrgName, LOrgUnit, Locality, Middle, Nickname,
          OrgName, OrgUnit, SVCARD, User) ->
-    ejabberd_odbc:sql_transaction(
+    ejabberd_sql:sql_transaction(
       LServer,
       fun() ->
               ?SQL_UPSERT(LServer, "vcard",
@@ -480,45 +479,45 @@ set_vcard(LServer, LUser, BDay, CTRY, EMail, FN,
       end).
 
 get_vcard(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(vcard)s from vcard where username=%(LUser)s")).
 
 get_default_privacy_list(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(name)s from privacy_default_list "
            "where username=%(LUser)s")).
 
 get_default_privacy_list_t(LUser) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("select @(name)s from privacy_default_list "
            "where username=%(LUser)s")).
 
 get_privacy_list_names(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(name)s from privacy_list"
            " where username=%(LUser)s")).
 
 get_privacy_list_names_t(LUser) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("select @(name)s from privacy_list"
            " where username=%(LUser)s")).
 
 get_privacy_list_id(LServer, LUser, Name) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(id)d from privacy_list"
            " where username=%(LUser)s and name=%(Name)s")).
 
 get_privacy_list_id_t(LUser, Name) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("select @(id)d from privacy_list"
            " where username=%(LUser)s and name=%(Name)s")).
 
 get_privacy_list_data(LServer, LUser, Name) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
            "@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
@@ -530,7 +529,7 @@ get_privacy_list_data(LServer, LUser, Name) ->
 
 %% Not used?
 get_privacy_list_data_t(LUser, Name) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
            "@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
            "@(match_presence_out)b from privacy_list_data "
@@ -540,7 +539,7 @@ get_privacy_list_data_t(LUser, Name) ->
            "order by ord")).
 
 get_privacy_list_data_by_id(LServer, ID) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
            "@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
@@ -548,7 +547,7 @@ get_privacy_list_data_by_id(LServer, ID) ->
            "where id=%(ID)d order by ord")).
 
 get_privacy_list_data_by_id_t(ID) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("select @(t)s, @(value)s, @(action)s, @(ord)d, @(match_all)b, "
            "@(match_iq)b, @(match_message)b, @(match_presence_in)b, "
            "@(match_presence_out)b from privacy_list_data "
@@ -561,28 +560,28 @@ set_default_privacy_list(LUser, Name) ->
         "name=%(Name)s"]).
 
 unset_default_privacy_list(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("delete from privacy_default_list"
            " where username=%(LUser)s")).
 
 remove_privacy_list(LUser, Name) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("delete from privacy_list where"
            " username=%(LUser)s and name=%(Name)s")).
 
 add_privacy_list(LUser, Name) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("insert into privacy_list(username, name) "
            "values (%(LUser)s, %(Name)s)")).
 
 set_privacy_list(ID, RItems) ->
-    ejabberd_odbc:sql_query_t(
+    ejabberd_sql:sql_query_t(
       ?SQL("delete from privacy_list_data where id=%(ID)d")),
     lists:foreach(
       fun({SType, SValue, SAction, Order, MatchAll, MatchIQ,
            MatchMessage, MatchPresenceIn, MatchPresenceOut}) ->
-              ejabberd_odbc:sql_query_t(
+              ejabberd_sql:sql_query_t(
                 ?SQL("insert into privacy_list_data(id, t, "
                      "value, action, ord, match_all, match_iq, "
                      "match_message, match_presence_in, match_presence_out) "
@@ -594,14 +593,14 @@ set_privacy_list(ID, RItems) ->
                  RItems).
 
 del_privacy_lists(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("delete from privacy_list where username=%(LUser)s")),
     %US = <<LUser/binary, "@", LServer/binary>>,
-    %ejabberd_odbc:sql_query(
+    %ejabberd_sql:sql_query(
     %  LServer,
     %  ?SQL("delete from privacy_list_data where value=%(US)s")),
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("delete from privacy_default_list where username=%(LUser)s")).
 
@@ -618,12 +617,12 @@ escape(C) -> <<C>>.
 
 %% Count number of records in a table given a where clause
 count_records_where(LServer, Table, WhereClause) ->
-    ejabberd_odbc:sql_query(LServer,
+    ejabberd_sql:sql_query(LServer,
                            [<<"select count(*) from ">>, Table, <<" ">>,
                             WhereClause, <<";">>]).
 
 get_roster_version(LServer, LUser) ->
-    ejabberd_odbc:sql_query(
+    ejabberd_sql:sql_query(
       LServer,
       ?SQL("select @(version)s from roster_version"
            " where username = %(LUser)s")).
@@ -633,7 +632,7 @@ set_roster_version(LUser, Version) ->
             [<<"username">>, <<"version">>], [LUser, Version],
             [<<"username = '">>, LUser, <<"'">>]).
 
-opt_type(odbc_type) ->
+opt_type(sql_type) ->
     fun (pgsql) -> pgsql;
        (mysql) -> mysql;
        (sqlite) -> sqlite;
@@ -642,4 +641,4 @@ opt_type(odbc_type) ->
     end;
 opt_type(pgsql_users_number_estimate) ->
     fun (V) when is_boolean(V) -> V end;
-opt_type(_) -> [odbc_type, pgsql_users_number_estimate].
+opt_type(_) -> [sql_type, pgsql_users_number_estimate].
index 8cc1fd6887094359a607a00eafe48d13f1fc2882..e2f26807007f57c4096a03c23c0009fa33a3578f 100644 (file)
@@ -86,7 +86,7 @@ do_init_per_group(redis, Config) ->
     mod_muc:shutdown_rooms(?REDIS_VHOST),
     set_opt(server, ?REDIS_VHOST, Config);
 do_init_per_group(mysql, Config) ->
-    case catch ejabberd_odbc:sql_query(?MYSQL_VHOST, [<<"select 1;">>]) of
+    case catch ejabberd_sql:sql_query(?MYSQL_VHOST, [<<"select 1;">>]) of
         {selected, _, _} ->
             mod_muc:shutdown_rooms(?MYSQL_VHOST),
             create_sql_tables(mysql, ?config(base_dir, Config)),
@@ -95,7 +95,7 @@ do_init_per_group(mysql, Config) ->
             {skip, {mysql_not_available, Err}}
     end;
 do_init_per_group(pgsql, Config) ->
-    case catch ejabberd_odbc:sql_query(?PGSQL_VHOST, [<<"select 1;">>]) of
+    case catch ejabberd_sql:sql_query(?PGSQL_VHOST, [<<"select 1;">>]) of
         {selected, _, _} ->
             mod_muc:shutdown_rooms(?PGSQL_VHOST),
             create_sql_tables(pgsql, ?config(base_dir, Config)),
@@ -104,7 +104,7 @@ do_init_per_group(pgsql, Config) ->
             {skip, {pgsql_not_available, Err}}
     end;
 do_init_per_group(sqlite, Config) ->
-    case catch ejabberd_odbc:sql_query(?SQLITE_VHOST, [<<"select 1;">>]) of
+    case catch ejabberd_sql:sql_query(?SQLITE_VHOST, [<<"select 1;">>]) of
         {selected, _, _} ->
             mod_muc:shutdown_rooms(?SQLITE_VHOST),
             set_opt(server, ?SQLITE_VHOST, Config);
@@ -2248,7 +2248,7 @@ create_sql_tables(Type, BaseDir) ->
     SQLFile = filename:join([BaseDir, "sql", File]),
     CreationQueries = read_sql_queries(SQLFile),
     DropTableQueries = drop_table_queries(CreationQueries),
-    case ejabberd_odbc:sql_transaction(
+    case ejabberd_sql:sql_transaction(
            VHost, DropTableQueries ++ CreationQueries) of
         {atomic, ok} ->
             ok;
index 91e6caa64c8c1a7b441aa96b5050e07ebceb172f..bd7f958d3ae46ec50fdc537aa5368348e5a4352d 100644 (file)
@@ -1,33 +1,33 @@
 host_config: 
   "pgsql.localhost": 
-    odbc_username: "@@pgsql_user@@"
-    odbc_type: pgsql
-    odbc_server: "@@pgsql_server@@"
-    odbc_port: @@pgsql_port@@
-    odbc_pool_size: 1
-    odbc_password: "@@pgsql_pass@@"
-    odbc_database: "@@pgsql_db@@"
-    auth_method: odbc
-    sm_db_type: odbc
+    sql_username: "@@pgsql_user@@"
+    sql_type: pgsql
+    sql_server: "@@pgsql_server@@"
+    sql_port: @@pgsql_port@@
+    sql_pool_size: 1
+    sql_password: "@@pgsql_pass@@"
+    sql_database: "@@pgsql_db@@"
+    auth_method: sql
+    sm_db_type: sql
     modules: 
       mod_announce: 
-        db_type: odbc
+        db_type: sql
         access: local
       mod_blocking: []
       mod_caps: 
-        db_type: odbc
+        db_type: sql
       mod_last: 
-        db_type: odbc
+        db_type: sql
       mod_muc: 
-        db_type: odbc
+        db_type: sql
       mod_offline: 
-        db_type: odbc
+        db_type: sql
       mod_privacy: 
-        db_type: odbc
+        db_type: sql
       mod_private: 
-        db_type: odbc
+        db_type: sql
       mod_pubsub: 
-        db_type: odbc
+        db_type: sql
         access_createnode: pubsub_createnode
         ignore_pep_from_offline: true
         last_item_cache: false
@@ -39,13 +39,13 @@ host_config:
       mod_roster:
         versioning: true
         store_current_id: true
-        db_type: odbc
+        db_type: sql
       mod_mam:
-        db_type: odbc
+        db_type: sql
       mod_vcard: 
-        db_type: odbc
+        db_type: sql
       mod_vcard_xupdate:
-        db_type: odbc
+        db_type: sql
       mod_adhoc: []
       mod_configure: []
       mod_disco: []
@@ -60,28 +60,28 @@ Welcome to this XMPP server."
       mod_time: []
       mod_version: []
   "sqlite.localhost": 
-    odbc_type: sqlite
-    auth_method: odbc
-    sm_db_type: odbc
+    sql_type: sqlite
+    auth_method: sql
+    sm_db_type: sql
     modules: 
       mod_announce: 
-        db_type: odbc
+        db_type: sql
         access: local
       mod_blocking: []
       mod_caps: 
-        db_type: odbc
+        db_type: sql
       mod_last: 
-        db_type: odbc
+        db_type: sql
       mod_muc: 
-        db_type: odbc
+        db_type: sql
       mod_offline: 
-        db_type: odbc
+        db_type: sql
       mod_privacy: 
-        db_type: odbc
+        db_type: sql
       mod_private: 
-        db_type: odbc
+        db_type: sql
       mod_pubsub: 
-        db_type: odbc
+        db_type: sql
         access_createnode: pubsub_createnode
         ignore_pep_from_offline: true
         last_item_cache: false
@@ -93,13 +93,13 @@ Welcome to this XMPP server."
       mod_roster:
         versioning: true
         store_current_id: true
-        db_type: odbc
+        db_type: sql
       mod_mam:
-        db_type: odbc
+        db_type: sql
       mod_vcard: 
-        db_type: odbc
+        db_type: sql
       mod_vcard_xupdate:
-        db_type: odbc
+        db_type: sql
       mod_adhoc: []
       mod_configure: []
       mod_disco: []
@@ -114,34 +114,34 @@ Welcome to this XMPP server."
       mod_time: []
       mod_version: []
   "mysql.localhost": 
-    odbc_username: "@@mysql_user@@"
-    odbc_type: mysql
-    odbc_server: "@@mysql_server@@"
-    odbc_port: @@mysql_port@@
-    odbc_pool_size: 1
-    odbc_password: "@@mysql_pass@@"
-    odbc_database: "@@mysql_db@@"
-    auth_method: odbc
-    sm_db_type: odbc
+    sql_username: "@@mysql_user@@"
+    sql_type: mysql
+    sql_server: "@@mysql_server@@"
+    sql_port: @@mysql_port@@
+    sql_pool_size: 1
+    sql_password: "@@mysql_pass@@"
+    sql_database: "@@mysql_db@@"
+    auth_method: sql
+    sm_db_type: sql
     modules: 
       mod_announce: 
-        db_type: odbc
+        db_type: sql
         access: local
       mod_blocking: []
       mod_caps: 
-        db_type: odbc
+        db_type: sql
       mod_last: 
-        db_type: odbc
+        db_type: sql
       mod_muc: 
-        db_type: odbc
+        db_type: sql
       mod_offline: 
-        db_type: odbc
+        db_type: sql
       mod_privacy: 
-        db_type: odbc
+        db_type: sql
       mod_private: 
-        db_type: odbc
+        db_type: sql
       mod_pubsub: 
-        db_type: odbc
+        db_type: sql
         access_createnode: pubsub_createnode
         ignore_pep_from_offline: true
         last_item_cache: false
@@ -153,13 +153,13 @@ Welcome to this XMPP server."
       mod_roster: 
         versioning: true
         store_current_id: true
-        db_type: odbc
+        db_type: sql
       mod_mam:
-        db_type: odbc
+        db_type: sql
       mod_vcard: 
-        db_type: odbc
+        db_type: sql
       mod_vcard_xupdate:
-        db_type: odbc
+        db_type: sql
       mod_adhoc: []
       mod_configure: []
       mod_disco: []