diff options
author | Jerome Sautret <jerome.sautret@process-one.net> | 2020-10-08 16:23:34 +0200 |
---|---|---|
committer | Jerome Sautret <jerome.sautret@process-one.net> | 2020-10-08 16:23:34 +0200 |
commit | fdda572c9a7c1b51c07abff57976717ceb1d7635 (patch) | |
tree | fb3382f71548d8aa2e697661f79e77ac803a68f4 /src | |
parent | ejabberd_stun: Rename Logger filter (diff) |
Added sql_odbc_driver option for mssql db
Add an option to choose the ODBC driver when sql_type is set to mssql
Diffstat (limited to 'src')
-rw-r--r-- | src/ejabberd_option.erl | 8 | ||||
-rw-r--r-- | src/ejabberd_options.erl | 3 | ||||
-rw-r--r-- | src/ejabberd_sql.erl | 21 | ||||
-rw-r--r-- | src/ejabberd_sql_sup.erl | 2 |
4 files changed, 23 insertions, 11 deletions
diff --git a/src/ejabberd_option.erl b/src/ejabberd_option.erl index 030001ed8..907272761 100644 --- a/src/ejabberd_option.erl +++ b/src/ejabberd_option.erl @@ -137,6 +137,7 @@ -export([sql_database/0, sql_database/1]). -export([sql_keepalive_interval/0, sql_keepalive_interval/1]). -export([sql_password/0, sql_password/1]). +-export([sql_odbc_driver/0, sql_odbc_driver/1]). -export([sql_pool_size/0, sql_pool_size/1]). -export([sql_port/0, sql_port/1]). -export([sql_prepared_statements/0, sql_prepared_statements/1]). @@ -928,6 +929,13 @@ sql_password() -> sql_password(Host) -> ejabberd_config:get_option({sql_password, Host}). +-spec sql_odbc_driver() -> binary(). +sql_odbc_driver() -> + sql_odbc_driver(global). +-spec sql_odbc_driver(global | binary()) -> binary(). +sql_odbc_driver(Host) -> + ejabberd_config:get_option({sql_odbc_driver, Host}). + -spec sql_pool_size() -> pos_integer(). sql_pool_size() -> sql_pool_size(global). diff --git a/src/ejabberd_options.erl b/src/ejabberd_options.erl index e8b8cb890..a9ca961ae 100644 --- a/src/ejabberd_options.erl +++ b/src/ejabberd_options.erl @@ -371,6 +371,8 @@ opt_type(sql_keepalive_interval) -> econf:timeout(second); opt_type(sql_password) -> econf:binary(); +opt_type(sql_odbc_driver) -> + econf:binary(); opt_type(sql_pool_size) -> econf:pos_int(); opt_type(sql_port) -> @@ -645,6 +647,7 @@ options() -> {sql_database, undefined}, {sql_keepalive_interval, undefined}, {sql_password, <<"">>}, + {sql_odbc_driver, <<"libtdsodbc.so">>}, % default is FreeTDS driver {sql_pool_size, fun(Host) -> case ejabberd_config:get_option({sql_type, Host}) of diff --git a/src/ejabberd_sql.erl b/src/ejabberd_sql.erl index 8b952f4e0..0fd338222 100644 --- a/src/ejabberd_sql.erl +++ b/src/ejabberd_sql.erl @@ -52,7 +52,7 @@ encode_term/1, decode_term/1, odbcinst_config/0, - init_mssql/0, + init_mssql/1, keep_alive/2, to_list/2, to_array/2]). @@ -349,11 +349,11 @@ init([Host]) -> connecting(connect, #state{host = Host} = State) -> ConnectRes = case db_opts(Host) of - [mysql | Args] -> apply(fun mysql_connect/8, Args); - [pgsql | Args] -> apply(fun pgsql_connect/8, Args); - [sqlite | Args] -> apply(fun sqlite_connect/1, Args); - [mssql | Args] -> apply(fun odbc_connect/2, Args); - [odbc | Args] -> apply(fun odbc_connect/2, Args) + [mysql | Args] -> apply(fun mysql_connect/8, Args); + [pgsql | Args] -> apply(fun pgsql_connect/8, Args); + [sqlite | Args] -> apply(fun sqlite_connect/1, Args); + [mssql | Args] -> apply(fun odbc_connect/2, Args); + [odbc | Args] -> apply(fun odbc_connect/2, Args) end, case ConnectRes of {ok, Ref} -> @@ -1107,7 +1107,7 @@ db_opts(Host) -> SSLOpts = get_ssl_opts(Transport, Host), case Type of mssql -> - [mssql, <<"DRIVER=FreeTDS;SERVER=", Server/binary, ";UID=", User/binary, + [mssql, <<"DRIVER=ODBC;SERVER=", Server/binary, ";UID=", User/binary, ";DATABASE=", DB/binary ,";PWD=", Pass/binary, ";PORT=", (integer_to_binary(Port))/binary ,";CLIENT_CHARSET=UTF-8;">>, Timeout]; _ -> @@ -1151,9 +1151,10 @@ get_ssl_opts(ssl, Host) -> get_ssl_opts(tcp, _) -> []. -init_mssql() -> - ODBCINST = io_lib:fwrite("[FreeTDS]~n" - "Driver = libtdsodbc.so~n", []), +init_mssql(Host) -> + Driver = ejabberd_option:sql_odbc_driver(Host), + ODBCINST = io_lib:fwrite("[ODBC]~n" + "Driver = ~s~n", [Driver]), ?DEBUG("~ts:~n~ts", [odbcinst_config(), ODBCINST]), case filelib:ensure_dir(odbcinst_config()) of ok -> diff --git a/src/ejabberd_sql_sup.erl b/src/ejabberd_sql_sup.erl index ee37c7e61..6a3e979de 100644 --- a/src/ejabberd_sql_sup.erl +++ b/src/ejabberd_sql_sup.erl @@ -96,7 +96,7 @@ init([Host]) -> sqlite -> check_sqlite_db(Host); mssql -> - ejabberd_sql:init_mssql(); + ejabberd_sql:init_mssql(Host); _ -> ok end, |