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 Jun 13, 2019
1 parent f9ef62f commit 32c7b87
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ c_src/oci_api/session
c_src/odpi
priv/
ebin/
\.*/
45 changes: 43 additions & 2 deletions c_src/dpiConn_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include "dpiQueryInfo_nif.h"
#include "stdio.h"

ERL_NIF_TERM ATOM_encoding = 0;
ERL_NIF_TERM ATOM_nencoding = 0;

ErlNifResourceType *dpiConn_type;

void dpiConn_res_dtor(ErlNifEnv *env, void *resource)
Expand All @@ -20,6 +23,7 @@ DPI_NIF_FUN(conn_create)

dpiContext_res *contextRes;
ErlNifBinary userName, password, connectString;
size_t commonParamsMapSize = 0;
if (!enif_get_resource(env, argv[0], dpiContext_type, &contextRes))
return BADARG_EXCEPTION(0, "resource context");
if (!enif_inspect_binary(env, argv[1], &userName))
Expand All @@ -28,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 @@ -38,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
21 changes: 19 additions & 2 deletions test/odpi_eunit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,25 @@ getTnsUserPass () ->
start() ->
{Tns, User, Password} = getTnsUserPass(),
Context = dpi:context_create(3, 0),
Conn = dpi:conn_create(Context, User, Password, Tns, #{}, #{}),
[Context, Conn].
try
Conn = dpi:conn_create(
Context, User, Password, Tns,
#{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."),
Expand Down

0 comments on commit 32c7b87

Please sign in to comment.