Skip to content

Commit 3870ab1

Browse files
author
Christopher Jones
committed
Added binding support for DB_TYPE_BOOLEAN (Diego Arce)
1 parent 1372717 commit 3870ab1

File tree

7 files changed

+50
-13
lines changed

7 files changed

+50
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
- Added support for binding using the node-oracledb [Database Type
66
Constants](https://oracle.github.io/node-oracledb/doc/api.html#oracledbconstantsdbtype)
77
`DB_TYPE_DATE`, `DB_TYPE_CHAR`, `DB_TYPE_NCHAR`, `DB_TYPE_NVARCHAR`,
8-
`DB_TYPE_NCLOB`, `DB_TYPE_TIMESTAMP`, and `DB_TYPE_TIMESTAMP_TZ`.
8+
`DB_TYPE_NCLOB`, `DB_TYPE_BINARY_DOUBLE`, `DB_TYPE_BINARY_FLOAT`,
9+
`DB_TYPE_BINARY_INTEGER`, `DB_TYPE_TIMESTAMP`, and `DB_TYPE_TIMESTAMP_TZ`.
10+
11+
- Added support for binding using `DB_TYPE_BOOLEAN` (Diego Arce).
912

1013
- Added support for creating temporary NCLOBS with
1114
[`connection.createLob(oracledb.NCLOB)`](https://oracle.github.io/node-oracledb/doc/api.html#connectioncreatelob).

doc/api.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,13 +3127,14 @@ Lob | NCLOB | `oracledb.NCLOB` or `oracledb.D
31273127
String | ROWID | `oracledb.STRING` or `oracledb.DB_TYPE_VARCHAR` | |
31283128
String | UROWID | `oracledb.STRING` or `oracledb.DB_TYPE_VARCHAR` | |
31293129
String | XMLType | `oracledb.STRING` or `oracledb.DB_TYPE_VARCHAR` | Size is limited to the maximum database VARCHAR length |
3130+
Boolean | BOOLEAN | `oracledb.DB_TYPE_BOOLEAN` | This combination is supported from node-oracledb 4.2. Only supported for PL/SQL binds |
31303131
ResultSet | CURSOR | `oracledb.CURSOR` or `oracledb.DB_TYPE_CURSOR` | Only supported for OUT binds |
31313132
DbObject | Named type or collection | A string with the name of the Oracle Database object or collection, or a [DbObject](#dbobjectclass) | This combination is supported from node-oracledb 4.0 |
31323133

31333134
When binding LONG, LONG RAW, CLOB, NCLOB, and BLOB database types using string
31343135
or buffer bind types, then data is limited to a maxium size of 1 GB.
31353136

3136-
Binding Oracle Database INTERVAL types, BFILE, or BOOLEAN is not supported.
3137+
Binding Oracle Database INTERVAL types or BFILE not supported.
31373138

31383139
##### <a name="executebindparamval"></a> 4.2.6.2.5 `val`
31393140

@@ -11153,7 +11154,7 @@ For IN binds:
1115311154
- The `val` attribute may be a constant or a JavaScript variable.
1115411155

1115511156
- If `type` is omitted, it is derived from the bind data value. If it is set,
11156-
it can be one of the values in the [`type`](#executebindparamtype) table.
11157+
it can be one of the values in the [`type` table](#executebindparamtype).
1115711158
Typically `type` is one of `oracledb.STRING`, `oracledb.NUMBER`,
1115811159
`oracledb.DATE` or `oracledb.BUFFER` matching the standard Node.js type of the
1115911160
data being passed into the database. Use a bind type of `oracledb.BLOB` or
@@ -11248,9 +11249,9 @@ bind variable object containing [`dir`](#executebindparamdir),
1124811249
- The `val` parameter in needed when binding IN OUT to pass a value
1124911250
into the database. It is not used for OUT binds.
1125011251

11251-
- The `type` attribute can be one of the constants as discussed in [`execute()`
11252-
`bindParams` `type`](#executebindparamtype). This determines the mapping
11253-
between the database type and the JavaScript type.
11252+
- The `type` attribute can be one of the constants as discussed in the [`type`
11253+
table](#executebindparamtype). This determines the mapping between the
11254+
database type and the JavaScript type.
1125411255

1125511256
The attribute should be set for OUT binds. If `type` is not specified, then
1125611257
`oracledb.STRING` is assumed.
@@ -11260,11 +11261,10 @@ bind variable object containing [`dir`](#executebindparamdir),
1126011261
determined if the input data is null. The output data type will always be the
1126111262
same as the input data type.
1126211263

11263-
- A `maxSize` attribute should be set for `oracledb.STRING` or
11264-
`oracledb.BUFFER` OUT or IN OUT binds. This is the maximum number
11265-
of bytes the bind parameter will return. If the output value does
11266-
not fit in `maxSize` bytes, then an error such *ORA-06502: PL/SQL:
11267-
numeric or value error: character string buffer too small* or
11264+
- A `maxSize` attribute should be set for String and Buffer OUT or IN OUT binds.
11265+
This is the maximum number of bytes the bind parameter will return. If the
11266+
output value does not fit in `maxSize` bytes, then an error such *ORA-06502:
11267+
PL/SQL: numeric or value error: character string buffer too small* or
1126811268
*NJS-016: buffer is too small for OUT binds* occurs.
1126911269

1127011270
A default value of 200 bytes is used when `maxSize` is not provided for OUT

src/njsBaton.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ bool njsBaton_isBindValue(njsBaton *baton, napi_env env, napi_value value)
917917
return false;
918918
if (valueType != napi_undefined && valueType != napi_null &&
919919
valueType != napi_number && valueType != napi_string &&
920-
valueType != napi_object)
920+
valueType != napi_object && valueType != napi_boolean)
921921
return false;
922922
if (valueType != napi_object)
923923
return true;

src/njsConnection.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,12 @@ static bool njsConnection_getBindInfoFromValue(njsBaton *baton,
10881088
return true;
10891089
}
10901090

1091+
// booleans
1092+
if (valueType == napi_boolean) {
1093+
*bindType = NJS_DATATYPE_BOOLEAN;
1094+
return true;
1095+
}
1096+
10911097
// dates, LOBs, buffers and arrays are all objects
10921098
if (valueType == napi_object) {
10931099

src/njsDbObject.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ static bool njsDbObject_transformFromOracle(njsDbObject *obj, napi_env env,
826826
case DPI_ORACLE_TYPE_OBJECT:
827827
return njsDbObject_new(typeInfo->objectType, data->value.asObject,
828828
env, value);
829+
case DPI_ORACLE_TYPE_BOOLEAN:
830+
NJS_CHECK_NAPI(env, napi_get_boolean(env, data->value.asBoolean,
831+
value))
832+
return true;
829833
default:
830834
break;
831835
}
@@ -852,9 +856,9 @@ static bool njsDbObject_transformToOracle(njsDbObject *obj, napi_env env,
852856
napi_valuetype valueType;
853857
njsDbObjectType *objType;
854858
njsDbObject *valueObj;
859+
bool check, tempBool;
855860
void *bufferData;
856861
size_t length;
857-
bool check;
858862

859863
data->isNull = 0;
860864
*strBuffer = NULL;
@@ -885,6 +889,13 @@ static bool njsDbObject_transformToOracle(njsDbObject *obj, napi_env env,
885889
}
886890
return true;
887891

892+
// handle booleans
893+
case napi_boolean:
894+
NJS_CHECK_NAPI(env, napi_get_value_bool(env, value, &tempBool))
895+
*nativeTypeNum = DPI_NATIVE_TYPE_BOOLEAN;
896+
data->value.asBoolean = (int) tempBool;
897+
return true;
898+
888899
// several types of objects are supported
889900
case napi_object:
890901

src/njsModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
#define NJS_DATATYPE_CLOB DPI_ORACLE_TYPE_CLOB
134134
#define NJS_DATATYPE_NCLOB DPI_ORACLE_TYPE_NCLOB
135135
#define NJS_DATATYPE_BLOB DPI_ORACLE_TYPE_BLOB
136+
#define NJS_DATATYPE_BOOLEAN DPI_ORACLE_TYPE_BOOLEAN
136137
#define NJS_DATATYPE_OBJECT DPI_ORACLE_TYPE_OBJECT
137138

138139
// error messages used within the driver

src/njsVariable.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ bool njsVariable_createBuffer(njsVariable *var, njsConnection *conn,
9999
case DPI_ORACLE_TYPE_BLOB:
100100
var->nativeTypeNum = DPI_NATIVE_TYPE_LOB;
101101
break;
102+
case NJS_DATATYPE_BOOLEAN:
103+
var->nativeTypeNum = DPI_NATIVE_TYPE_BOOLEAN;
104+
break;
102105
case DPI_ORACLE_TYPE_OBJECT:
103106
var->nativeTypeNum = DPI_NATIVE_TYPE_OBJECT;
104107
break;
@@ -424,6 +427,10 @@ bool njsVariable_getScalarValue(njsVariable *var, njsVariableBuffer *buffer,
424427
NJS_CHECK_NAPI(env, napi_create_string_utf8(env, rowidValue,
425428
rowidValueLength, value))
426429
break;
430+
case DPI_NATIVE_TYPE_BOOLEAN:
431+
NJS_CHECK_NAPI(env, napi_get_boolean(env, data->value.asBoolean,
432+
value))
433+
break;
427434
case DPI_NATIVE_TYPE_OBJECT:
428435
if (!njsDbObject_new(var->objectType, data->value.asObject,
429436
env, value))
@@ -962,6 +969,15 @@ bool njsVariable_setScalarValue(njsVariable *var, uint32_t pos, napi_env env,
962969
return true;
963970
}
964971

972+
// handle binding booleans
973+
if (valueType == napi_boolean) {
974+
if (var->varTypeNum != DPI_ORACLE_TYPE_BOOLEAN)
975+
return njsVariable_setInvalidBind(var, pos, baton);
976+
NJS_CHECK_NAPI(env, napi_get_value_bool(env, value,
977+
(bool*) &data->value.asBoolean))
978+
return true;
979+
}
980+
965981
// handle binding objects
966982
if (valueType == napi_object) {
967983

0 commit comments

Comments
 (0)