* src/odbc/odbc_queries.erl: Likewise.
* src/odbc/mysql.sql: Likewise.
* src/odbc/mssql.sql: Likewise.
SVN Revision: 674
+2006-11-05 Mickael Remond <mickael.remond@process-one.net>
+
+ * src/mod_private_odbc.erl: Support for MySQL and MSSQL.
+ * src/odbc/odbc_queries.erl: Likewise.
+ * src/odbc/mysql.sql: Likewise.
+ * src/odbc/mssql.sql: Likewise.
+
2006-11-04 Mickael Remond <mickael.remond@process-one.net>
* src/eldap_utils.erl: Fixed missing export.
set_data(LUser, LServer, El)
end, Els)
end,
- ejabberd_odbc:sql_transaction(LServer, F),
+ odbc_queries:sql_transaction(LServer, F),
IQ#iq{type = result,
sub_el = [{xmlelement, Name, Attrs, []}]};
get ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
end.
-set_data(LUser, _LServer, El) ->
+set_data(LUser, LServer, El) ->
case El of
{xmlelement, _Name, Attrs, _Els} ->
XMLNS = xml:get_attr_s("xmlns", Attrs),
LXMLNS = ejabberd_odbc:escape(XMLNS),
SData = ejabberd_odbc:escape(
lists:flatten(xml:element_to_string(El))),
- ejabberd_odbc:sql_query_t(
- ["delete from private_storage "
- "where username='", Username, "' and "
- "namespace='", LXMLNS, "';"]),
- ejabberd_odbc:sql_query_t(
- ["insert into private_storage(username, namespace, data) "
- "values ('", Username, "', '", LXMLNS, "', "
- "'", SData, "');"])
+ odbc_queries:set_private_data(LServer, Username, LXMLNS, SData)
end;
_ ->
ignore
XMLNS = xml:get_attr_s("xmlns", Attrs),
Username = ejabberd_odbc:escape(LUser),
LXMLNS = ejabberd_odbc:escape(XMLNS),
- case catch ejabberd_odbc:sql_query(
- LServer,
- ["select data from private_storage "
- "where username='", Username, "' and "
- "namespace='", LXMLNS, "';"]) of
+ case catch odbc_queries:get_private_data(LServer, Username, LXMLNS) of
{selected, ["data"], [{SData}]} ->
case xml_stream:parse_element(SData) of
Data when element(1, Data) == xmlelement ->
get_data(LUser, LServer, Els,
[Data | Res])
end;
+ %% MREMOND: I wonder when the query could return a vcard ?
{selected, ["vcard"], []} ->
get_data(LUser, LServer, Els,
[El | Res])
LUser = jlib:nodeprep(User),
LServer = jlib:nameprep(Server),
Username = ejabberd_odbc:escape(LUser),
- ejabberd_odbc:sql_transaction(
- LServer,
- ["delete from private_storage where username='", Username, "';"]).
-
-
+ odbc_queries:del_user_private_storage(LServer, Username).
drop table [dbo].[vcard]\r
GO\r
\r
+if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[private_storage]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)\r
+drop table [dbo].[private_storage]\r
+GO\r
+\r
CREATE TABLE [dbo].[last] (\r
[username] [varchar] (250) NOT NULL ,\r
[seconds] [varchar] (50) NOT NULL ,\r
) ON [PRIMARY]\r
GO\r
\r
+CREATE TABLE [dbo].[private_storage] (\r
+ [username] [varchar] (250) NOT NULL ,\r
+ [namespace] [varchar] (250) NOT NULL ,\r
+ [data] [text] NOT NULL\r
+) ON [PRIMARY]\r
+GO\r
+\r
ALTER TABLE [dbo].[last] WITH NOCHECK ADD \r
CONSTRAINT [PK_last] PRIMARY KEY CLUSTERED \r
(\r
CREATE INDEX [IK_Spool_Created] ON [dbo].[spool]([created]) WITH FILLFACTOR = 90 ON [PRIMARY]\r
GO\r
\r
+ CREATE INDEX [IX_private_user] ON [dbo].[private_storage]([username]) WITH FILLFACTOR = 90 ON [PRIMARY]\r
+GO\r
+ CREATE INDEX [IX_private_user_ns] ON [dbo].[private_storage]([username], [namespace]) WITH FILLFACTOR = 90 ON [PRIMARY]\r
+GO\r
+\r
+\r
/*********************************************************/\r
/** These store procedures are for use with ejabberd **/\r
/** 1.1 and Microsoft Sql Server 2000 **/\r
END\r
END\r
GO\r
+\r
/******************************************************************/\r
/****** Object: StoredProcedure [dbo].[get_password] **/\r
/** Retrive the user password **/\r
DELETE FROM rostergroups \r
WITH (ROWLOCK)\r
WHERE (rostergroups.username = @Username) AND (rostergroups.jid = @JID);\r
-\r
COMMIT\r
END\r
GO\r
DELETE FROM rostergroups \r
WITH (ROWLOCK)\r
WHERE rostergroups.username = @Username;\r
-\r
COMMIT\r
END\r
GO\r
/** Retrive the user roster **/\r
/******************************************************************/\r
CREATE PROCEDURE [dbo].[get_roster]\r
- @Username varchar(200)\r
+ @Username varchar(250)\r
AS\r
DECLARE\r
@vRosterusers table( username varchar(1), \r
\r
/******************************************************************/\r
/****** Object: StoredProcedure [dbo].[list_users] **/\r
-/** Retrive a list of all users **/\r
+/** Retrieve a list of all users **/\r
/******************************************************************/\r
CREATE PROCEDURE [dbo].[list_users]\r
AS\r
END\r
END\r
GO\r
+\r
+/******************************************************************/\r
+/****** Object: StoredProcedure [dbo].[set_private_data] **/\r
+/** store user private data by namespace **/\r
+/******************************************************************/\r
+CREATE PROCEDURE [dbo].[set_private_data]\r
+ @Username varchar(250),\r
+ @Namespace varchar(250),\r
+ @Data varchar(8000)\r
+AS\r
+BEGIN\r
+ IF EXISTS (SELECT username FROM private_storage with (nolock) WHERE private_storage.username = @Username AND private_storage.namespace = @Namespace)\r
+ BEGIN\r
+ UPDATE [private_storage]\r
+ SET [private_storage].username = @Username,\r
+ [private_storage].namespace = @Namespace,\r
+ [private_storage].data = @Data\r
+ WHERE private_storage.username = @Username AND private_storage.namespace = @Namespace;\r
+ END\r
+ ELSE\r
+ BEGIN\r
+ INSERT INTO [private_storage]\r
+ ( [private_storage].username,\r
+ [private_storage].namespace,\r
+ [private_storage].data\r
+ )\r
+ VALUES\r
+ ( @Username,\r
+ @Namespace,\r
+ @Data\r
+ )\r
+ END\r
+END\r
+GO\r
+\r
+ejabberd_odbc:sql_query_t(\r
+ ["delete from private_storage "\r
+ "where username='", Username, "' and "\r
+ "namespace='", LXMLNS, "';"]),\r
+ ejabberd_odbc:sql_query_t(\r
+ ["insert into private_storage(username, namespace, data) "\r
+ "values ('", Username, "', '", LXMLNS, "', "\r
+ "'", SData, "');"]).\r
+\r
+/******************************************************************/\r
+/****** Object: StoredProcedure [dbo].[get_private_data] **/\r
+/** Retrieve user private data by namespace **/\r
+/******************************************************************/\r
+CREATE PROCEDURE [dbo].[get_private_data]\r
+ @Username varchar(250),\r
+ @Namespace varchar(250)\r
+AS\r
+BEGIN\r
+ SELECT private_storage.data AS data\r
+ FROM private_storage WITH (NOLOCK)\r
+ WHERE username=@Username and namespace=@Namespace;\r
+END\r
+GO\r
+\r
+/***************************************************************/\r
+/****** Object: StoredProcedure [dbo].[del_user_storage] ******/\r
+/** Delete private storage area for a given user **/\r
+/***************************************************************/\r
+CREATE PROCEDURE [dbo].[del_user_storage]\r
+ @Username varchar(250)\r
+AS\r
+BEGIN\r
+ DELETE FROM [private_storage]\r
+ WITH (ROWLOCK)\r
+ WHERE [private_storage].username=@Username;\r
+END\r
+GO\r
+\r
CREATE INDEX i_vcard_search_lorgname ON vcard_search(lorgname);
CREATE INDEX i_vcard_search_lorgunit ON vcard_search(lorgunit);
+CREATE TABLE private_storage (
+ username varchar(250) NOT NULL,
+ namespace varchar(250) NOT NULL,
+ data text NOT NULL
+) CHARACTER SET utf8;
+
+CREATE INDEX i_private_storage_username USING BTREE ON private_storage(username);
+CREATE UNIQUE INDEX i_private_storage_username_namespace USING BTREE ON private_storage(username, namespace);
+
--- To update from 1.x:
-- ALTER TABLE rosterusers ADD COLUMN askmessage text AFTER ask;
-- UPDATE rosterusers SET askmessage = '';
update_roster_sql/4,
roster_subscribe/4,
get_subscription/3,
+ set_private_data/4,
+ get_private_data/3,
+ del_user_private_storage/2,
escape/1]).
%-define(generic, true).
"where username='", Username, "' "
"and jid='", SJID, "'"]).
+set_private_data(_LServer, Username, LXMLNS, SData) ->
+ ejabberd_odbc:sql_query_t(
+ ["delete from private_storage "
+ "where username='", Username, "' and "
+ "namespace='", LXMLNS, "';"]),
+ ejabberd_odbc:sql_query_t(
+ ["insert into private_storage(username, namespace, data) "
+ "values ('", Username, "', '", LXMLNS, "', "
+ "'", SData, "');"]).
+
+get_private_data(LServer, Username, LXMLNS) ->
+ ejabberd_odbc:sql_query(
+ LServer,
+ ["select data from private_storage "
+ "where username='", Username, "' and "
+ "namespace='", LXMLNS, "';"]).
+
+del_user_private_storage(LServer, Username) ->
+ ejabberd_odbc:sql_transaction(
+ LServer,
+ ["delete from private_storage where username='", Username, "';"]).
+
%% Characters to escape
escape($\0) -> "\\0";
escape($\n) -> "\\n";
ejabberd_odbc:sql_query(
LServer,
["EXECUTE dbo.get_subscription '", Username, "' , '", SJID, "'"]).
+
+set_private_data(_LServer, Username, LXMLNS, SData) ->
+ ejabberd_odbc:sql_query(
+ LServer,
+ ["EXECUTE dbo.set_private_data '", Username, "' , '", LXMLNS, "' , '", SData, "'"]).
+
+get_private_data(LServer, Username, LXMLNS) ->
+ ejabberd_odbc:sql_query(
+ LServer,
+ ["EXECUTE dbo.get_private_data '", Username, "' , '", LXMLNS, "'"]).
+
+del_user_private_storage(LServer, Username) ->
+ ejabberd_odbc:sql_query(
+ LServer,
+ ["EXECUTE dbo.del_user_storage '", Username, "'"]).
%% Characters to escape
escape($\0) -> "\\0";