Skip to content

Commit aa6d4db

Browse files
committed
Support NaN values in JSON Column Type
1 parent bedf901 commit aa6d4db

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Common Changes
2626
for the :meth:`sodaOperation.limit()` and :meth:`sodaOperation.skip()`
2727
methods in SODA operations.
2828

29+
#) Fixed bug that threw empty error message when NaN values were used
30+
in JSON binds.
31+
2932
Thin Mode Changes
3033
+++++++++++++++++
3134

lib/impl/datahandlers/oson.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,13 @@ class OsonTreeSegment extends GrowableBuffer {
549549

550550
// handle numbers
551551
} else if (typeof value === 'number') {
552-
this.writeUInt8(constants.TNS_JSON_TYPE_NUMBER_LENGTH_UINT8);
553-
this.writeOracleNumber(value.toString());
552+
if (Number.isNaN(value)) {
553+
this.writeUInt8(constants.TNS_JSON_TYPE_BINARY_DOUBLE);
554+
this.writeBinaryDouble(value);
555+
} else {
556+
this.writeUInt8(constants.TNS_JSON_TYPE_NUMBER_LENGTH_UINT8);
557+
this.writeOracleNumber(value.toString());
558+
}
554559

555560
// handle strings
556561
} else if (typeof value === 'string') {

src/njsJsonBuffer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,15 @@ static bool njsJsonBuffer_populateNode(njsJsonBuffer *buf, dpiJsonNode *node,
180180

181181
// handle numbers
182182
if (valueType == napi_number) {
183-
node->oracleTypeNum = DPI_ORACLE_TYPE_NUMBER;
184183
node->nativeTypeNum = DPI_NATIVE_TYPE_DOUBLE;
185184
NJS_CHECK_NAPI(env, napi_get_value_double(env, value,
186185
&node->value->asDouble))
186+
187+
// pass in NaN JSON value as Binary Double in OSON
188+
if (isnan(node->value->asDouble))
189+
node->oracleTypeNum = DPI_ORACLE_TYPE_NATIVE_DOUBLE;
190+
else
191+
node->oracleTypeNum = DPI_ORACLE_TYPE_NUMBER;
187192
return true;
188193
}
189194

src/njsModule.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@
4040
#include <stdlib.h>
4141
#include <stdio.h>
4242
#include <string.h>
43+
#include <math.h>
4344
#include "dpi.h"
4445
#include "uv.h"
4546

47+
#ifdef _WIN32
48+
#include <windows.h>
49+
#ifndef isnan
50+
#define isnan _isnan
51+
#endif
52+
#endif
53+
4654
// maximum length of error messages
4755
#define NJS_MAX_ERROR_MSG_LEN 256
4856

src/njsVariable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ bool njsVariable_setScalarValue(njsVariable *var, uint32_t pos, napi_env env,
903903
}
904904
if (dpiJson_setValue(data->value.asJson, &jsonBuffer.topNode) < 0) {
905905
njsJsonBuffer_free(&jsonBuffer);
906-
return false;
906+
return njsBaton_setErrorDPI(baton);
907907
}
908908
njsJsonBuffer_free(&jsonBuffer);
909909
return true;

test/dbType04.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ describe('241. dbType04.js', function() {
449449
assert.deepStrictEqual(result2.rows[0][1], jsonVal);
450450
}); // 241.20
451451

452-
it.skip('241.21 NaN', async () => {
452+
it('241.21 NaN', async () => {
453453
const jsonId = 21;
454454
const jsonVal = NaN;
455455
const sqlOne = `insert into ${TABLE} values (:1, :2)`;
@@ -458,12 +458,10 @@ describe('241. dbType04.js', function() {
458458
{ val: jsonVal, type: oracledb.DB_TYPE_JSON }
459459
];
460460
const result1 = await conn.execute(sqlOne, binds);
461-
//assert.strictEqual(result1.rowsAffected, 1);
462-
console.log(result1);
463-
// const sqlTwo = `select * from ${TABLE} where id = ${jsonId}`;
464-
// const result2 = await conn.execute(sqlTwo);
465-
// console.log(result2.rows[0][1]);
466-
// assert.strictEqual(result2.rows[0][1], jsonVal);
461+
assert.strictEqual(result1.rowsAffected, 1);
462+
const sqlTwo = `select * from ${TABLE} where id = ${jsonId}`;
463+
const result2 = await conn.execute(sqlTwo);
464+
assert.strictEqual(result2.rows[0][1], jsonVal);
467465
}); // 241.21
468466

469467
it('241.22 Negative - implicitly binding JSON', async () => {

0 commit comments

Comments
 (0)