aboutsummaryrefslogtreecommitdiff
path: root/src/ejd2odbc.erl
diff options
context:
space:
mode:
authorMickaël Rémond <mickael.remond@process-one.net>2006-11-20 13:20:47 +0000
committerMickaël Rémond <mickael.remond@process-one.net>2006-11-20 13:20:47 +0000
commit86da0b3e1beeb34cbca660ce39adec44a1358bb4 (patch)
treebbcada424fd63f04b9ffceaa7ebb81d1a7bd62c9 /src/ejd2odbc.erl
parent* src/mod_muc/mod_muc_room.erl: API improvement: It is now easier to extract (diff)
2006-11-20 Mickael Remond <mickael.remond@process-one.net>
* src/ejd2odbc.erl: Copy mod_private data from Mnesia to relational database. * src/odbc/odbc_queries.erl: Refactoring. * src/odbc/mssql.sql: Likewise. * doc/guide.tex: Update to mention mod_private_odbc. * src/odbc/mysql.sql: Started integration of mod_privacy_odbc for MySQL and MSSQL. * src/odbc/mssql.sql: Likewise. SVN Revision: 678
Diffstat (limited to 'src/ejd2odbc.erl')
-rw-r--r--src/ejd2odbc.erl33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/ejd2odbc.erl b/src/ejd2odbc.erl
index 8a7f6ada0..6dfc3a406 100644
--- a/src/ejd2odbc.erl
+++ b/src/ejd2odbc.erl
@@ -16,7 +16,8 @@
export_offline/2,
export_last/2,
export_vcard/2,
- export_vcard_search/2]).
+ export_vcard_search/2,
+ export_private_storage/2]).
-include("ejabberd.hrl").
-include("jlib.hrl").
@@ -39,17 +40,24 @@
orgname, lorgname,
orgunit, lorgunit
}).
+-record(private_storage, {usns, xml}).
-define(MAX_RECORDS_PER_TRANSACTION, 1000).
%%%----------------------------------------------------------------------
%%% API
%%%----------------------------------------------------------------------
+%%% How to use:
+%%% 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
+%%% database or "Filename" to export to text file.
export_passwd(Server, Output) ->
export_common(
Server, passwd, Output,
- fun(Host, {passwd, {LUser, LServer}, Password} = R)
+ fun(Host, {passwd, {LUser, LServer}, Password} = _R)
when LServer == Host ->
Username = ejabberd_odbc:escape(LUser),
Pass = ejabberd_odbc:escape(Password),
@@ -219,6 +227,20 @@ export_vcard_search(Server, Output) ->
[]
end).
+export_private_storage(Server, Output) ->
+ export_common(
+ Server, private_storage, Output,
+ fun(Host, #private_storage{usns = {LUser, LServer, XMLNS},
+ xml = Data})
+ when LServer == Host ->
+ Username = ejabberd_odbc:escape(LUser),
+ LXMLNS = ejabberd_odbc:escape(XMLNS),
+ SData = ejabberd_odbc:escape(Data),
+ odbc_queries:set_private_data_sql(Username, LXMLNS, SData);
+ (_Host, _R) ->
+ []
+ end).
+
%%%----------------------------------------------------------------------
%%% Internal functions
%%%----------------------------------------------------------------------
@@ -246,6 +268,7 @@ export_common(Server, Table, Output, ConvertFun) ->
N < ?MAX_RECORDS_PER_TRANSACTION - 1 ->
{N + 1, [SQL | SQLs]};
true ->
+ %% Execute full SQL transaction
output(LServer, IO,
["begin;",
lists:reverse([SQL | SQLs]),
@@ -254,6 +277,7 @@ export_common(Server, Table, Output, ConvertFun) ->
end
end
end, {0, []}, Table),
+ %% Execute SQL transaction with remaining records
output(LServer, IO,
["begin;",
lists:reverse(SQLs),
@@ -268,7 +292,7 @@ output(LServer, IO, SQL) ->
file:write(IO, [SQL, $;, $\n])
end.
-record_to_string(#roster{usj = {User, Server, JID},
+record_to_string(#roster{usj = {User, _Server, JID},
name = Name,
subscription = Subscription,
ask = Ask,
@@ -299,7 +323,7 @@ record_to_string(#roster{usj = {User, Server, JID},
"'", AskMessage, "',"
"'N', '', 'item')"].
-groups_to_string(#roster{usj = {User, Server, JID},
+groups_to_string(#roster{usj = {User, _Server, JID},
groups = Groups}) ->
Username = ejabberd_odbc:escape(User),
SJID = ejabberd_odbc:escape(jlib:jid_to_string(JID)),
@@ -307,4 +331,3 @@ groups_to_string(#roster{usj = {User, Server, JID},
"'", Username, "',"
"'", SJID, "',"
"'", ejabberd_odbc:escape(Group), "')"] || Group <- Groups].
-