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

Commit

Permalink
Resource counter API (#136)
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
* fixed MARCO args formatting
* add a comma
* re-work, clean WIP currently segfault
* warnings
* fix tuples in dpi:dafe call, add error handling to call macro, create an own connection for the ping test
* change error message test to use invalid password instead of TNS to avoid timeout
* catch everything in execStmt macro
* change execStmt into a function
* separate stmt and conn tests into their own fixtures
* adapt and fix old CT test cases, implement dpiData_setDouble
* Partial common params support in creating connection (#59)
* 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
* re-work, clean WIP currently segfault
* warnings
* fix tuples in dpi:dafe call, add error handling to call macro, create an own connection for the ping test
* change error message test to use invalid password instead of TNS to avoid timeout
* catch everything in execStmt macro
* change execStmt into a function
* separate stmt and conn tests into their own fixtures
* adapt and fix old CT test cases, implement dpiData_setDouble
* WIP
* implement common test infrastructure, implement test job insertIntoTable
* remove some unneeded macros
* data resource free fixes
* add bindData job, add setup for running tests on one persistent dpi slave
* local fix of a memory leak, fix merge changing of eunit tests by taking changes from a newer branch
* 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
* fixed MARCO args formatting
* add a comma
* re-work, clean WIP currently segfault
* warnings
* fix tuples in dpi:dafe call, add error handling to call macro, create an own connection for the ping test
* change error message test to use invalid password instead of TNS to avoid timeout
* catch everything in execStmt macro
* change execStmt into a function
* separate stmt and conn tests into their own fixtures
* adapt and fix old CT test cases, implement dpiData_setDouble
* Partial common params support in creating connection (#59)
* 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
* re-work, clean WIP currently segfault
* warnings
* fix tuples in dpi:dafe call, add error handling to call macro, create an own connection for the ping test
* change error message test to use invalid password instead of TNS to avoid timeout
* catch everything in execStmt macro
* change execStmt into a function
* separate stmt and conn tests into their own fixtures
* adapt and fix old CT test cases, implement dpiData_setDouble
* WIP
* implement common test infrastructure, implement test job insertIntoTable
* remove some unneeded macros
* add bindData job, add setup for running tests on one persistent dpi slave
* local fix of a memory leak, fix merge changing of eunit tests by taking changes from a newer branch
* formatting
* fix mangled rebase
* set test cases
* quick feature testing
* ignored ct reports eunit wanring fixes removed deprecated eunit
* ct sample config fix priv_dir look up for ct
* benchmarking WIP
* no tests
* sanitized
* indent to spaces
* removed files from common-test branch
* removed ct specific ignores
* reverted to master
* cosmetic fixes to master
* delete reverted
* reverted to master
* dataPtr_res reused
* test coverage WIP
* Full test coverage
* resource counting WIP
* res (de)alloc macrofied with counters eunit added
* all test pass typo fixed
* upgrade implemented
* data 100% cover renamed to cover dpi_eunit merged in
* WIP
* cosmetics
* error DPI_ORACLE_TYPE_NUM_FROM_ATOM no match
* major re-fectoring and cleanup
* run moved to test
* cosmetics
* no change
* cov files
* hardcoded seed for conract rand sequence
* escript fixed seed for const rand sequence
* read back
* test cosmetics
* debugging stmt release leak WIP
* print formatting fixes resource count fixes
* CRLF @ EOF
* removed un reachable code
  • Loading branch information
c-bik authored Sep 2, 2019
1 parent 313b71e commit 38a1ae0
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 106 deletions.
49 changes: 21 additions & 28 deletions c_src/dpiConn_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ DPI_NIF_FUN(conn_create)
dpiCommonCreateParams commonParams;
RAISE_EXCEPTION_ON_DPI_ERROR(
contextRes->context,
dpiContext_initCommonCreateParams(contextRes->context, &commonParams),
NULL);
dpiContext_initCommonCreateParams(contextRes->context, &commonParams));

if (commonParamsMapSize > 0)
{
Expand Down Expand Up @@ -71,10 +70,10 @@ DPI_NIF_FUN(conn_create)
}
}

dpiConn_res *connRes =
enif_alloc_resource(dpiConn_type, sizeof(dpiConn_res));
dpiConn_res *connRes;
ALLOC_RESOURCE(connRes, dpiConn);

RAISE_EXCEPTION_ON_DPI_ERROR(
RAISE_EXCEPTION_ON_DPI_ERROR_RESOURCE(
contextRes->context,
dpiConn_create(
contextRes->context, (const char *)userName.data, userName.size,
Expand All @@ -83,7 +82,7 @@ DPI_NIF_FUN(conn_create)
&commonParams,
NULL, // TODO implement connCreateParams
&connRes->conn),
connRes);
connRes, dpiConn);

// Save context into connection for access from dpiError
connRes->context = contextRes->context;
Expand Down Expand Up @@ -117,16 +116,16 @@ DPI_NIF_FUN(conn_prepareStmt)
if (!enif_inspect_binary(env, argv[3], &tag))
BADARG_EXCEPTION(3, "binary/string tag");

dpiStmt_res *stmtRes =
enif_alloc_resource(dpiStmt_type, sizeof(dpiStmt_res));
dpiStmt_res *stmtRes;
ALLOC_RESOURCE(stmtRes, dpiStmt);

RAISE_EXCEPTION_ON_DPI_ERROR(
RAISE_EXCEPTION_ON_DPI_ERROR_RESOURCE(
connRes->context,
dpiConn_prepareStmt(
connRes->conn, scrollable, (const char *)sql.data, sql.size,
tag.size > 0 ? (const char *)tag.data : NULL, tag.size,
&stmtRes->stmt),
stmtRes);
stmtRes, dpiStmt);

stmtRes->context = connRes->context;

Expand Down Expand Up @@ -175,16 +174,16 @@ DPI_NIF_FUN(conn_newVar)
if (enif_compare(argv[7], ATOM_NULL))
BADARG_EXCEPTION(7, "atom objType");

dpiVar_res *varRes =
enif_alloc_resource(dpiVar_type, sizeof(dpiVar_res));
dpiVar_res *varRes;
ALLOC_RESOURCE(varRes, dpiVar);

RAISE_EXCEPTION_ON_DPI_ERROR(
RAISE_EXCEPTION_ON_DPI_ERROR_RESOURCE(
connRes->context,
dpiConn_newVar(
connRes->conn, oracleTypeNum, nativeTypeNum, maxArraySize, size,
sizeIsBytes, isArray,
NULL, &varRes->var, &data),
varRes);
varRes, dpiVar);

varRes->context = connRes->context;

Expand All @@ -196,7 +195,7 @@ DPI_NIF_FUN(conn_newVar)
varRes->head = NULL;
for (int i = maxArraySize - 1; i >= 0; i--)
{
dataRes = enif_alloc_resource(dpiDataPtr_type, sizeof(dpiDataPtr_res));
ALLOC_RESOURCE(dataRes, dpiDataPtr);
dataRes->stmtRes = NULL;
dataRes->next = NULL;
dataRes->isQueryValue = 0;
Expand Down Expand Up @@ -234,9 +233,7 @@ DPI_NIF_FUN(conn_commit)
BADARG_EXCEPTION(0, "resource connection");

RAISE_EXCEPTION_ON_DPI_ERROR(
connRes->context,
dpiConn_commit(connRes->conn),
NULL);
connRes->context, dpiConn_commit(connRes->conn));

RETURNED_TRACE;
return ATOM_OK;
Expand All @@ -252,9 +249,7 @@ DPI_NIF_FUN(conn_rollback)
BADARG_EXCEPTION(0, "resource connection");

RAISE_EXCEPTION_ON_DPI_ERROR(
connRes->context,
dpiConn_rollback(connRes->conn),
NULL);
connRes->context, dpiConn_rollback(connRes->conn));

RETURNED_TRACE;
return ATOM_OK;
Expand All @@ -270,9 +265,7 @@ DPI_NIF_FUN(conn_ping)
BADARG_EXCEPTION(0, "resource connection");

RAISE_EXCEPTION_ON_DPI_ERROR(
connRes->context,
dpiConn_ping(connRes->conn),
NULL);
connRes->context, dpiConn_ping(connRes->conn));

RETURNED_TRACE;
return ATOM_OK;
Expand Down Expand Up @@ -314,8 +307,9 @@ DPI_NIF_FUN(conn_close)
dpiConn_close(
connRes->conn, mode,
tag.size > 0 ? (const char *)tag.data : NULL,
tag.size),
NULL);
tag.size));

RELEASE_RESOURCE(connRes, dpiConn);

RETURNED_TRACE;
return ATOM_OK;
Expand Down Expand Up @@ -389,8 +383,7 @@ DPI_NIF_FUN(conn_setClientIdentifier)
RAISE_EXCEPTION_ON_DPI_ERROR(
connRes->context,
dpiConn_setClientIdentifier(
connRes->conn, (const char *)value.data, value.size),
NULL);
connRes->conn, (const char *)value.data, value.size));

return ATOM_OK;
}
13 changes: 7 additions & 6 deletions c_src/dpiContext_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ DPI_NIF_FUN(context_create)
if (!enif_get_uint(env, argv[1], &minor))
BADARG_EXCEPTION(1, "uint minor");

dpiContext_res *contextRes =
enif_alloc_resource(dpiContext_type, sizeof(dpiContext_res));
dpiContext_res *contextRes;
ALLOC_RESOURCE(contextRes, dpiContext);

// RAISE_EXCEPTION_ON_DPI_ERROR macro can't be used since we need to return
// the error details too
// RAISE_EXCEPTION can't be used since we want to throw the error map
if (DPI_FAILURE ==
dpiContext_create(major, minor, &contextRes->context, &error))
{
enif_release_resource(contextRes);
RELEASE_RESOURCE(contextRes, dpiContext);

RETURNED_TRACE;
return enif_raise_exception(
env,
Expand All @@ -55,9 +56,9 @@ DPI_NIF_FUN(context_destroy)
BADARG_EXCEPTION(0, "resource context");

RAISE_EXCEPTION_ON_DPI_ERROR(
contextRes->context, dpiContext_destroy(contextRes->context), NULL);
contextRes->context, dpiContext_destroy(contextRes->context));

enif_release_resource(contextRes);
RELEASE_RESOURCE(contextRes, dpiContext);

RETURNED_TRACE;
return ATOM_OK;
Expand All @@ -76,7 +77,7 @@ DPI_NIF_FUN(context_getClientVersion)

RAISE_EXCEPTION_ON_DPI_ERROR(
contextRes->context,
dpiContext_getClientVersion(contextRes->context, &version), NULL);
dpiContext_getClientVersion(contextRes->context, &version));

ERL_NIF_TERM map = enif_make_new_map(env);

Expand Down
26 changes: 12 additions & 14 deletions c_src/dpiData_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,16 @@ void dpiData_res_dtor(ErlNifEnv *env, void *resource)
void dpiDataPtr_res_dtor(ErlNifEnv *env, void *resource)
{
CALL_TRACE;

dpiDataPtr_res *data = (dpiDataPtr_res *)resource;
if (data->stmtRes)
{
enif_release_resource(data->stmtRes);
data->stmtRes = NULL;
}

RETURNED_TRACE;
}

DPI_NIF_FUN(data_ctor)
{
CHECK_ARGCOUNT(0);

dpiData_res *data = enif_alloc_resource(dpiData_type, sizeof(dpiData_res));
dpiData_res *data;
ALLOC_RESOURCE(data, dpiData);

data->dpiData.isNull = 1; // starts out being null

// erlang process independent environment to persist data between NIF calls
Expand Down Expand Up @@ -351,7 +345,7 @@ DPI_NIF_FUN(data_get)
if (!stmtRes)
{
// first time
stmtRes = enif_alloc_resource(dpiStmt_type, sizeof(dpiStmt_res));
ALLOC_RESOURCE(stmtRes, dpiStmt);
dataRes->stmtRes = stmtRes;
}
stmtRes->stmt = data->value.asStmt;
Expand All @@ -364,8 +358,7 @@ DPI_NIF_FUN(data_get)
uint32_t stringlen;
RAISE_EXCEPTION_ON_DPI_ERROR(
dataRes->context,
dpiRowid_getStringValue(data->value.asRowid, &string, &stringlen),
NULL);
dpiRowid_getStringValue(data->value.asRowid, &string, &stringlen));
ErlNifBinary bin;
enif_alloc_binary(stringlen, &bin);
memcpy(bin.data, string, stringlen);
Expand Down Expand Up @@ -448,14 +441,19 @@ DPI_NIF_FUN(data_release)
if (enif_get_resource(env, argv[0], dpiData_type, (void **)&res.dataRes))
{
// nothing to set to NULL
enif_release_resource(res.dataRes);
RELEASE_RESOURCE(res.dataRes, dpiData);
}
else if (enif_get_resource(
env, argv[0], dpiDataPtr_type, (void **)&res.dataPtrRes))
{
if (res.dataPtrRes->stmtRes)
{
RELEASE_RESOURCE(res.dataPtrRes->stmtRes, dpiStmt);
res.dataPtrRes->stmtRes = NULL;
}
res.dataPtrRes->dpiDataPtr = NULL;
if (res.dataPtrRes->isQueryValue == 1)
enif_release_resource(res.dataPtrRes);
RELEASE_RESOURCE(res.dataPtrRes, dpiDataPtr);
}
else
BADARG_EXCEPTION(0, "resource data");
Expand Down
Loading

0 comments on commit 38a1ae0

Please sign in to comment.