Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Commit

Permalink
Partial common params support in creating connection (#59)
Browse files Browse the repository at this point in the history
* raise exception with full DPI error
* add testcase catch_error_message
* add testcase catch_error_message_conn
* remove two debug prints in eunit
* fix broken fixture
* Added property utf8 when creating a new connection.
* fixed MARCO args formatting
* add a comma
* temporary files and folders
* read config from map - WIP
  • Loading branch information
c-bik authored and Karl Keiser committed Jun 19, 2019
1 parent c94b161 commit a190480
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 15 deletions.
41 changes: 39 additions & 2 deletions c_src/dpiConn_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,43 @@ DPI_NIF_FUN(conn_create)
return BADARG_EXCEPTION(2, "string/binary password");
if (!enif_inspect_binary(env, argv[3], &connectString))
return BADARG_EXCEPTION(3, "string/binary connectString");
if (!enif_get_map_size(env, argv[4], &commonParamsMapSize))
return BADARG_EXCEPTION(4, "map commonParams");

dpiCommonCreateParams commonParams;
RAISE_EXCEPTION_ON_DPI_ERROR(
contextRes->context,
dpiContext_initCommonCreateParams(contextRes->context, &commonParams),
NULL);

if (commonParamsMapSize > 0)
{
// lazy create
if (!(ATOM_encoding | ATOM_nencoding))
{
ATOM_encoding = enif_make_atom(env, "encoding");
ATOM_nencoding = enif_make_atom(env, "nencoding");
}

ERL_NIF_TERM mapval;
char encodeStr[128];
if (enif_get_map_value(env, argv[4], ATOM_encoding, &mapval)) {
if(
!enif_get_string(
env, mapval, encodeStr, sizeof(encodeStr), ERL_NIF_LATIN1)
) return BADARG_EXCEPTION(4, "string\0 commonParams.encoding");
commonParams.encoding = encodeStr;
}

char nencodeStr[128];
if (enif_get_map_value(env, argv[4], ATOM_nencoding, &mapval)) {
if(
!enif_get_string(
env, mapval, nencodeStr, sizeof(nencodeStr), ERL_NIF_LATIN1)
) return BADARG_EXCEPTION(4, "string\0 commonParams.nencoding");
commonParams.nencoding = nencodeStr;
}
}

dpiConn_res *connRes =
enif_alloc_resource(dpiConn_type, sizeof(dpiConn_res));
Expand All @@ -42,8 +79,8 @@ DPI_NIF_FUN(conn_create)
contextRes->context, userName.data, userName.size,
password.data, password.size, connectString.data,
connectString.size,
NULL, // TODO implement commonParams
NULL, // TODO implement createParams
&commonParams,
NULL, // TODO implement connCreateParams
&connRes->conn),
connRes);

Expand Down
43 changes: 30 additions & 13 deletions test/oranif_slave_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,7 @@ distributed(_) ->
ok = dpi:load(slave),
?debugFmt("Slave: ~p ~n", [get(dpi_node)]),

<<<<<<< HEAD:test/odpi_eunit.erl
{Tns, User, Password, _Encoding} = getTnsUserPass(),
=======
#{tns := Tns, user := User, password := Password} = getConfig(),
>>>>>>> re-work, clean WIP:test/oranif_slave_test.erl
Context = dpi:safe(dpi, context_create, [3, 0]),
Conn = dpi:safe(dpi, conn_create, [Context, User, Password, Tns, #{}, #{}]),

Expand Down Expand Up @@ -965,17 +961,38 @@ ref_cursor({_Context, Conn}) ->
dpi:data_release(DataRep1).

start() ->
#{tns := Tns, user := User, password := Password} = getConfig(),
ok = dpi:load_unsafe(),
Context = dpi:context_create(3, 0),
Connnnection = dpi:conn_create(
{Tns, User, Password} = getTnsUserPass(),
Context = dpi:context_create(3, 0),
try
Conn = dpi:conn_create(
Context, User, Password, Tns,
#{encoding => "AL32UTF8", nencoding => "AL32UTF8"}, #{}
),
{Context, Connnnection}.
#{encoding => "AL32UTF8", nencoding => "AL32UTF8"},
#{}
),
[Context, Conn]
catch
error:{error, CSrc, Line, Details} ->
?debugFmt(
"[~s:~p] ERROR ~p", [CSrc, Line, Details]),
throw(Details#{csrc => CSrc, line => Line});
Class:Exception ->
?debugFmt(
"Class ~p, Exception ~p, Context ~p",
[Class, Exception, Context]
),
throw({Class, Exception})
end.

s() ->
?debugMsg("Performing setup."),
%ok = dpi:load(?SLAVE_NAME),
ok = dpi:load_unsafe(),
?debugMsg("Performed setup."),
ok.

stop({Context, Connnnection}) ->
dpi:conn_release(Connnnection),
stop([Context, Conn]) ->
%?debugMsg("Teardown of test, but there is nothing to do (dtors should take care of freeing the resources)"),
dpi:conn_release(Conn),
dpi:context_destroy(Context),
ok.

Expand Down

0 comments on commit a190480

Please sign in to comment.