25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Added sql_odbc_driver option for mssql db

Add an option to choose the ODBC driver when sql_type is set to mssql
This commit is contained in:
Jerome Sautret 2020-10-08 16:23:34 +02:00
parent e4d6007293
commit fdda572c9a
4 changed files with 23 additions and 11 deletions

View File

@ -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).

View File

@ -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

View File

@ -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 ->

View File

@ -96,7 +96,7 @@ init([Host]) ->
sqlite ->
check_sqlite_db(Host);
mssql ->
ejabberd_sql:init_mssql();
ejabberd_sql:init_mssql(Host);
_ ->
ok
end,