Skip to content

Commit 1372717

Browse files
committed
Bind type updates with support for NCHAR and others
1 parent 0a5f30c commit 1372717

File tree

15 files changed

+1097
-342
lines changed

15 files changed

+1097
-342
lines changed

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
## node-oracledb v4.2.0 (DD MON YYYY)
44

5+
- Added support for binding using the node-oracledb [Database Type
6+
Constants](https://oracle.github.io/node-oracledb/doc/api.html#oracledbconstantsdbtype)
7+
`DB_TYPE_DATE`, `DB_TYPE_CHAR`, `DB_TYPE_NCHAR`, `DB_TYPE_NVARCHAR`,
8+
`DB_TYPE_NCLOB`, `DB_TYPE_TIMESTAMP`, and `DB_TYPE_TIMESTAMP_TZ`.
9+
10+
- Added support for creating temporary NCLOBS with
11+
[`connection.createLob(oracledb.NCLOB)`](https://oracle.github.io/node-oracledb/doc/api.html#connectioncreatelob).
12+
513
- Added [client initiated
6-
connections](https://oracle.github.io/node-oracledb/doc/api.html#consubscribeoptclientinitiated)
14+
connection](https://oracle.github.io/node-oracledb/doc/api.html#consubscribeoptclientinitiated)
715
support for Continuous Query Notification (CQN) and other subscription based
816
notifications.
917

@@ -19,6 +27,9 @@
1927
mode of `executeMany()` to show row `offset` values up to (2^32)-1 ([ODPI-C
2028
change](https://github.com/oracle/odpi/commit/294d5966cd513d0c29fdeec3bbbdfad376f81d4f)).
2129

30+
- Avoid intermediate conversion from the database national character set to the
31+
database character set when querying NCLOB columns as String.
32+
2233
- Fixed various execution failures with Node.js 13.2 due to Node.js NULL pointer behavior change ([ODPI-C
2334
change](https://github.com/oracle/odpi/commit/7693865bb6a98568546aa319cc0fdb9e208cf9d4)).
2435

@@ -33,7 +44,7 @@
3344

3445
- Updated Lob streaming documentation and examples. Applications should use the
3546
`end` event (for readable streams) and `finish` event (for writeable streams)
36-
instead of the `close` event. The node-oracledb's `lob.close()` method is now
47+
instead of the `close` event. The node-oracledb `lob.close()` method is now
3748
deprecated in favor of the more functional Node.js 8 Stream `destroy()`
3849
method.
3950

doc/api.md

Lines changed: 350 additions & 268 deletions
Large diffs are not rendered by default.

lib/connection.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved
1+
// Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved
22

33
//-----------------------------------------------------------------------------
44
//
@@ -244,6 +244,8 @@ function createLob(type, createLobCb) { //eslint-disable-line
244244
const self = this;
245245

246246
nodbUtil.checkAsyncArgs(arguments, 2, 2);
247+
nodbUtil.assert(typeof type === 'number', 'NJS-005', 1);
248+
nodbUtil.assert(typeof createLobCb === 'function', 'NJS-005', 2);
247249

248250
self._createLob.apply(self, arguments);
249251
}

src/njsConnection.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -463,14 +463,12 @@ static napi_value njsConnection_createLob(napi_env env,
463463
static bool njsConnection_createLobAsync(njsBaton *baton)
464464
{
465465
njsConnection *conn = (njsConnection*) baton->callingInstance;
466-
dpiOracleTypeNum typeNum;
467466

468-
typeNum = (baton->lobType == NJS_DATATYPE_CLOB) ? DPI_ORACLE_TYPE_CLOB :
469-
DPI_ORACLE_TYPE_BLOB;
470467
baton->lob = calloc(1, sizeof(njsLobBuffer));
471468
if (!baton->lob)
472469
return njsBaton_setError(baton, errInsufficientMemory);
473-
if (dpiConn_newTempLob(conn->handle, typeNum, &baton->lob->handle) < 0)
470+
if (dpiConn_newTempLob(conn->handle, baton->lobType,
471+
&baton->lob->handle) < 0)
474472
return njsBaton_setErrorDPI(baton);
475473
baton->lob->dataType = baton->lobType;
476474
if (!njsLob_populateBuffer(baton, baton->lob))
@@ -503,11 +501,10 @@ static bool njsConnection_createLobProcessArgs(njsBaton *baton,
503501
{
504502
if (!njsUtils_getUnsignedIntArg(env, args, 0, &baton->lobType))
505503
return false;
506-
if (baton->lobType != NJS_DATATYPE_CLOB &&
507-
baton->lobType != NJS_DATATYPE_BLOB) {
508-
njsUtils_throwError(env, errInvalidParameterValue, 1);
509-
return false;
510-
}
504+
if (baton->lobType != DPI_ORACLE_TYPE_CLOB &&
505+
baton->lobType != DPI_ORACLE_TYPE_BLOB &&
506+
baton->lobType != DPI_ORACLE_TYPE_NCLOB)
507+
return njsUtils_throwError(env, errInvalidParameterValue, 1);
511508

512509
return true;
513510
}
@@ -2309,17 +2306,17 @@ static bool njsConnection_scanExecuteBinds(njsBaton *baton, napi_env env,
23092306
}
23102307

23112308
// get bind information from value if it has not already been specified
2312-
if (var->bindDataType == NJS_DATATYPE_DEFAULT || !var->maxSize ||
2309+
if (var->varTypeNum == NJS_DATATYPE_DEFAULT || !var->maxSize ||
23132310
var->maxSize == NJS_MAX_OUT_BIND_SIZE) {
2314-
defaultBindType = var->bindDataType;
2311+
defaultBindType = var->varTypeNum;
23152312
defaultMaxSize = var->maxSize;
23162313
defaultObjectTypeHandle = var->dpiObjectTypeHandle;
23172314
if (!njsConnection_getBindInfoFromValue(baton, false, env,
23182315
bindValue, &defaultBindType, &defaultMaxSize,
23192316
&defaultObjectTypeHandle))
23202317
return false;
2321-
if (var->bindDataType == NJS_DATATYPE_DEFAULT)
2322-
var->bindDataType = defaultBindType;
2318+
if (var->varTypeNum == NJS_DATATYPE_DEFAULT)
2319+
var->varTypeNum = defaultBindType;
23232320
if (defaultMaxSize > var->maxSize)
23242321
var->maxSize = defaultMaxSize;
23252322
if (!var->dpiObjectTypeHandle && defaultObjectTypeHandle)
@@ -2331,7 +2328,7 @@ static bool njsConnection_scanExecuteBinds(njsBaton *baton, napi_env env,
23312328
// specified by the application; for OUT binds, the value from the
23322329
// application must be accepted as is as there is no way to
23332330
// validate it
2334-
if (var->bindDataType != NJS_DATATYPE_OBJECT) {
2331+
if (var->varTypeNum != DPI_ORACLE_TYPE_OBJECT) {
23352332

23362333
NJS_CHECK_NAPI(env, napi_is_array(env, bindValue, &check))
23372334
if (check) {
@@ -2415,7 +2412,7 @@ static bool njsConnection_scanExecuteBindUnit(njsBaton *baton,
24152412
if (!njsDbObjectType_getFromClass(env, value, &var->objectType))
24162413
return false;
24172414
var->dpiObjectTypeHandle = var->objectType->handle;
2418-
var->bindDataType = NJS_DATATYPE_OBJECT;
2415+
var->varTypeNum = DPI_ORACLE_TYPE_OBJECT;
24192416
okBindUnit = true;
24202417
} else if (valueType == napi_string) {
24212418

@@ -2447,11 +2444,11 @@ static bool njsConnection_scanExecuteBindUnit(njsBaton *baton,
24472444
dpiObjectType_release(objTypeHandle);
24482445
}
24492446
var->dpiObjectTypeHandle = var->objectType->handle;
2450-
var->bindDataType = NJS_DATATYPE_OBJECT;
2447+
var->varTypeNum = DPI_ORACLE_TYPE_OBJECT;
24512448
okBindUnit = true;
24522449
} else {
24532450
if (!njsBaton_getUnsignedIntFromArg(baton, env, args, 1, "type",
2454-
&var->bindDataType, &found))
2451+
&var->varTypeNum, &found))
24552452
return false;
24562453
if (found) {
24572454
okBindUnit = true;
@@ -2474,8 +2471,8 @@ static bool njsConnection_scanExecuteBindUnit(njsBaton *baton,
24742471
if (found) {
24752472
okBindUnit = true;
24762473
} else if (inExecuteMany) {
2477-
if (var->bindDataType == NJS_DATATYPE_STR ||
2478-
var->bindDataType == NJS_DATATYPE_BUFFER) {
2474+
if (var->varTypeNum == DPI_ORACLE_TYPE_VARCHAR ||
2475+
var->varTypeNum == DPI_ORACLE_TYPE_RAW) {
24792476
if (var->pos > 0)
24802477
return njsBaton_setError(baton, errMissingMaxSizeByPos,
24812478
var->pos);
@@ -2557,15 +2554,15 @@ static bool njsConnection_scanExecuteManyBinds(njsBaton *baton,
25572554
continue;
25582555

25592556
// otherwise, determine bind type and size by examining the value
2560-
defaultBindType = var->bindDataType;
2557+
defaultBindType = var->varTypeNum;
25612558
defaultMaxSize = var->maxSize;
25622559
defaultObjectTypeHandle = var->dpiObjectTypeHandle;
25632560
if (!njsConnection_getBindInfoFromValue(baton, true, env,
25642561
value, &defaultBindType, &defaultMaxSize,
25652562
&defaultObjectTypeHandle))
25662563
return false;
2567-
if (var->bindDataType == NJS_DATATYPE_DEFAULT)
2568-
var->bindDataType = defaultBindType;
2564+
if (var->varTypeNum == NJS_DATATYPE_DEFAULT)
2565+
var->varTypeNum = defaultBindType;
25692566
if (defaultMaxSize > var->maxSize)
25702567
var->maxSize = defaultMaxSize;
25712568
if (!var->dpiObjectTypeHandle && defaultObjectTypeHandle)

src/njsDbObject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, Oracle and/or its affilitates. All rights reserved.
1+
// Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -810,9 +810,7 @@ static bool njsDbObject_transformFromOracle(njsDbObject *obj, napi_env env,
810810
case DPI_ORACLE_TYPE_CLOB:
811811
case DPI_ORACLE_TYPE_NCLOB:
812812
case DPI_ORACLE_TYPE_BLOB:
813-
lobBuffer.dataType =
814-
(typeInfo->oracleTypeNum == DPI_ORACLE_TYPE_BLOB) ?
815-
NJS_DATATYPE_BLOB : NJS_DATATYPE_CLOB;
813+
lobBuffer.dataType = typeInfo->oracleTypeNum;
816814
lobBuffer.handle = data->value.asLOB;
817815
lobBuffer.isAutoClose = true;
818816
if (dpiLob_getChunkSize(lobBuffer.handle,

src/njsLob.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
1+
// Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -344,7 +344,8 @@ static bool njsLob_getDataPostAsync(njsBaton *baton, napi_env env,
344344

345345
if (!baton->bufferSize) {
346346
NJS_CHECK_NAPI(env, napi_get_null(env, &result))
347-
} else if (lob->dataType == NJS_DATATYPE_CLOB) {
347+
} else if (lob->dataType == DPI_ORACLE_TYPE_CLOB ||
348+
lob->dataType == DPI_ORACLE_TYPE_NCLOB) {
348349
NJS_CHECK_NAPI(env, napi_create_string_utf8(env, baton->bufferPtr,
349350
baton->bufferSize, &result))
350351
} else {
@@ -488,7 +489,8 @@ static bool njsLob_readPostAsync(njsBaton *baton, napi_env env,
488489

489490
if (!baton->bufferSize) {
490491
NJS_CHECK_NAPI(env, napi_get_null(env, &result))
491-
} else if (lob->dataType == NJS_DATATYPE_CLOB) {
492+
} else if (lob->dataType == DPI_ORACLE_TYPE_CLOB ||
493+
lob->dataType == DPI_ORACLE_TYPE_NCLOB) {
492494
NJS_CHECK_NAPI(env, napi_create_string_utf8(env, lob->bufferPtr,
493495
baton->bufferSize, &result))
494496
} else {

src/njsModule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
#define NJS_DATATYPE_CURSOR DPI_ORACLE_TYPE_STMT
132132
#define NJS_DATATYPE_BUFFER DPI_ORACLE_TYPE_RAW
133133
#define NJS_DATATYPE_CLOB DPI_ORACLE_TYPE_CLOB
134+
#define NJS_DATATYPE_NCLOB DPI_ORACLE_TYPE_NCLOB
134135
#define NJS_DATATYPE_BLOB DPI_ORACLE_TYPE_BLOB
135136
#define NJS_DATATYPE_OBJECT DPI_ORACLE_TYPE_OBJECT
136137

@@ -708,7 +709,6 @@ struct njsVariable {
708709
njsDbObjectType *objectType;
709710
dpiVar *dpiVarHandle;
710711
uint32_t bindDir;
711-
uint32_t bindDataType;
712712
uint32_t maxArraySize;
713713
uint32_t maxSize;
714714
uint32_t dbSizeInBytes;
@@ -1017,7 +1017,6 @@ bool njsVariable_createBuffer(njsVariable *var, njsConnection *conn,
10171017
void njsVariable_free(njsVariable *var);
10181018
bool njsVariable_getArrayValue(njsVariable *var, uint32_t pos, njsBaton *baton,
10191019
napi_env env, napi_value *value);
1020-
uint32_t njsVariable_getDataType(njsVariable *var);
10211020
bool njsVariable_getMetadataMany(njsVariable *vars, uint32_t numVars,
10221021
napi_env env, bool extended, napi_value *metadata);
10231022
bool njsVariable_getMetadataOne(njsVariable *var, napi_env env, bool extended,

src/njsOracleDb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ static njsConstant njsClassConstants[] = {
187187
{ "CURSOR", NJS_DATATYPE_CURSOR },
188188
{ "DATE", NJS_DATATYPE_DATE },
189189
{ "DEFAULT", NJS_DATATYPE_DEFAULT },
190+
{ "NCLOB", NJS_DATATYPE_NCLOB },
190191
{ "NUMBER", NJS_DATATYPE_NUM },
191192
{ "STRING", NJS_DATATYPE_STR },
192193

0 commit comments

Comments
 (0)