From 48c073abd27a9cf35d918dacc7721fc03945b709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20R=C3=A9mond?= Date: Sat, 10 Mar 2007 15:53:53 +0000 Subject: [PATCH] * src/odbc/ejabberd_odbc.erl: ejabberd admin can now choose the relational database port to user from ejabberd configuration file (EJAB-195). * src/doc/guide.tex: Likewise. SVN Revision: 740 --- ChangeLog | 7 +++++++ doc/guide.tex | 27 +++++++++++++++++++++++++++ src/odbc/ejabberd_odbc.erl | 19 +++++++++++++------ 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 174150585..303227d40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-03-10 Mickael Remond + + * src/odbc/ejabberd_odbc.erl: ejabberd admin can now choose the + relational database port to user from ejabberd configuration + file (EJAB-195). + * src/doc/guide.tex: Likewise. + 2007-03-02 Mickael Remond * src/mod_muc/mod_muc_log.erl: Fix wrong return on check access log. diff --git a/doc/guide.tex b/doc/guide.tex index 01b89ea93..88102293b 100644 --- a/doc/guide.tex +++ b/doc/guide.tex @@ -1037,6 +1037,20 @@ parameter: {odbc_server, {mysql, "localhost", "test", "root", "password"}}. \end{verbatim} +Optionally, it is possible to define the MySQL port to use. This +option is only useful, in very rare cases, when you are not running +MySQL with the default port setting. The \term{mysql} parameter +can thus take the following form: +\begin{verbatim} +{mysql, "Server", Port, "Database", "Username", "Password"} +\end{verbatim} + +The \term{Port} value should be an integer, without quotes. For example: +\begin{verbatim} +{odbc_server, {mysql, "localhost", Port, "test", "root", "password"}}. +\end{verbatim} + + \subsubsection{Storage} \label{mysqlstorage} \ind{MySQL!storage} @@ -1162,6 +1176,19 @@ form as parameter: {odbc_server, {pgsql, "localhost", "database", "ejabberd", "password"}}. \end{verbatim} +Optionally, it is possible to define the PostgreSQL port to use. This +option is only useful, in very rare cases, when you are not running +PostgreSQL with the default port setting. The \term{pgsql} parameter +can thus take the following form: +\begin{verbatim} +{pgsql, "Server", Port, "Database", "Username", "Password"} +\end{verbatim} + +The \term{Port} value should be an integer, without quotes. For example: +\begin{verbatim} +{odbc_server, {pgsql, "localhost", 5432, "database", "ejabberd", "password"}}. +\end{verbatim} + \subsubsection{Storage} \label{pgsqlstorage} \ind{PostgreSQL!storage} diff --git a/src/odbc/ejabberd_odbc.erl b/src/odbc/ejabberd_odbc.erl index b4fd41244..454c81708 100644 --- a/src/odbc/ejabberd_odbc.erl +++ b/src/odbc/ejabberd_odbc.erl @@ -34,6 +34,7 @@ -define(STATE_KEY, ejabberd_odbc_state). -define(MAX_TRANSACTION_RESTARTS, 10). +-define(PGSQL_PORT, 5432). -define(MYSQL_PORT, 3306). %%%---------------------------------------------------------------------- @@ -113,10 +114,16 @@ escape_like(C) -> odbc_queries:escape(C). init([Host]) -> SQLServer = ejabberd_config:get_local_option({odbc_server, Host}), case SQLServer of + %% Default pgsql port {pgsql, Server, DB, Username, Password} -> - pgsql_connect(Server, DB, Username, Password); + pgsql_connect(Server, ?PGSQL_PORT, DB, Username, Password); + {pgsql, Server, Port, DB, Username, Password} when is_integer(Port) -> + pgsql_connect(Server, Port, DB, Username, Password); + %% Default mysql port {mysql, Server, DB, Username, Password} -> - mysql_connect(Server, DB, Username, Password); + mysql_connect(Server, ?MYSQL_PORT, DB, Username, Password); + {mysql, Server, Port, DB, Username, Password} when is_integer(Port) -> + mysql_connect(Server, Port, DB, Username, Password); _ when is_list(SQLServer) -> odbc_connect(SQLServer) end. @@ -229,8 +236,8 @@ odbc_connect(SQLServer) -> %% part of init/1 %% Open a database connection to PostgreSQL -pgsql_connect(Server, DB, Username, Password) -> - case pgsql:connect(Server, DB, Username, Password) of +pgsql_connect(Server, Port, DB, Username, Password) -> + case pgsql:connect(Server, DB, Username, Password, Port) of {ok, Ref} -> {ok, #state{db_ref = Ref, db_type = pgsql}}; {error, Reason} -> @@ -267,9 +274,9 @@ pgsql_item_to_odbc(_) -> %% part of init/1 %% Open a database connection to MySQL -mysql_connect(Server, DB, Username, Password) -> +mysql_connect(Server, Port, DB, Username, Password) -> NoLogFun = fun(_Level,_Format,_Argument) -> ok end, - case mysql_conn:start(Server, ?MYSQL_PORT, Username, Password, DB, NoLogFun) of + case mysql_conn:start(Server, Port, Username, Password, DB, NoLogFun) of {ok, Ref} -> erlang:monitor(process, Ref), {ok, #state{db_ref = Ref, db_type = mysql}};