Skip to content

Commit 4f96b46

Browse files
committed
Raise error if the batcherrors exceeds 655535 for executeMany function in Thin mode
1 parent 47d254c commit 4f96b46

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

doc/src/release_notes.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ node-oracledb Release Notes
77

88
For deprecated and desupported features, see :ref:`Deprecations and desupported features <deprecations>`.
99

10+
node-oracledb `v6.4.0 <https://github.com/oracle/node-oracledb/compare/v6.3.0...v6.4.0>`__ (TBD)
11+
--------------------------------------------------------------------------------------------------------
12+
13+
Common Changes
14+
++++++++++++++
15+
16+
Thin Mode Changes
17+
++++++++++++++++++
18+
19+
#) Error ``NJS-141: errors in array DML exceed 65535`` is now raised
20+
when the number of batch errors exceed 65535 when calling
21+
:meth:`connection.executeMany()` with the parameter ``batchErrors``
22+
set to the value `true`. Note that in thick mode, this error is not raised
23+
unless the number of batch errors is a multiple of 65536; instead,
24+
the number of batch errors returned is modulo 65536.
25+
26+
Thick Mode Changes
27+
++++++++++++++++++
28+
1029
node-oracledb `v6.3.0 <https://github.com/oracle/node-oracledb/compare/v6.2.0...v6.3.0>`__ (21 Dec 2023)
1130
--------------------------------------------------------------------------------------------------------
1231

lib/errors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ const ERR_MISSING_BIND_VALUE = 137;
138138
const ERR_SERVER_VERSION_NOT_SUPPORTED = 138;
139139
const ERR_UNEXPECTED_XML_TYPE = 139;
140140
const ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY = 140;
141+
const ERR_TOO_MANY_BATCH_ERRORS = 141;
141142

142143
// Oracle Net layer errors start from 500
143144
const ERR_CONNECTION_CLOSED = 500;
@@ -403,6 +404,8 @@ messages.set(ERR_UNEXPECTED_XML_TYPE, // NJS-139
403404
'unexpected XML type with flag %d');
404405
messages.set(ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY, // NJS-140
405406
'user name must be enclosed in [] when using external authentication with a proxy user');
407+
messages.set(ERR_TOO_MANY_BATCH_ERRORS, // NJS-141
408+
'the number of batch errors from executemany() exceeds 65535');
406409

407410
// Oracle Net layer errors
408411

@@ -789,6 +792,7 @@ module.exports = {
789792
ERR_SERVER_VERSION_NOT_SUPPORTED,
790793
ERR_UNEXPECTED_XML_TYPE,
791794
ERR_WRONG_USER_FORMAT_EXTAUTH_PROXY,
795+
ERR_TOO_MANY_BATCH_ERRORS,
792796
ERR_CONNECTION_CLOSED_CODE: `${ERR_PREFIX}-${ERR_CONNECTION_CLOSED}`,
793797
WRN_COMPILATION_CREATE,
794798
assert,

lib/thin/protocol/messages/base.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ class Message {
9090
buf.skipBytesChunked();
9191
}
9292
// batch error codes
93-
let numEntries = buf.readUB2(); // batch error codes array
94-
if (numEntries > 0) {
93+
const numErrors = buf.readUB2(); // batch error codes array
94+
if (numErrors > 0) {
9595
this.errorInfo.batchErrors = [];
9696
const firstByte = buf.readUInt8();
97-
for (let i = 0; i < numEntries; i++) {
97+
for (let i = 0; i < numErrors; i++) {
9898
if (firstByte === constants.TNS_LONG_LENGTH_INDICATOR) {
9999
buf.skipUB4(); // chunk length ignored
100100
}
@@ -107,25 +107,32 @@ class Message {
107107
}
108108

109109
// batch error offset
110-
numEntries = buf.readUB2(); // batch error row offset array
111-
if (numEntries > 0) {
110+
const numOffsets = buf.readUB4(); // batch error row offset array
111+
if (numOffsets > 0) {
112+
if (numOffsets > 65535) {
113+
errors.throwErr(errors.ERR_TOO_MANY_BATCH_ERRORS);
114+
}
112115
const firstByte = buf.readUInt8();
113-
for (let i = 0; i < numEntries; i++) {
116+
let offset;
117+
for (let i = 0; i < numOffsets; i++) {
114118
if (firstByte === constants.TNS_LONG_LENGTH_INDICATOR) {
115119
buf.skipUB4(); // chunk length ignored
116120
}
117-
this.errorInfo.batchErrors[i].offset = buf.readUB4();
121+
offset = buf.readUB4();
122+
if (i < numErrors) {
123+
this.errorInfo.batchErrors[i].offset = offset;
124+
}
118125
}
119126
if (firstByte === constants.TNS_LONG_LENGTH_INDICATOR) {
120127
buf.skipBytes(1); // ignore end marker
121128
}
122129
}
123130

124131
// batch error messages
125-
numEntries = buf.readUB2(); // batch error messages array
126-
if (numEntries > 0) {
132+
const errMsgArr = buf.readUB2(); // batch error messages array
133+
if (errMsgArr > 0) {
127134
buf.skipBytes(1); // ignore packed size
128-
for (let i = 0; i < numEntries; i++) {
135+
for (let i = 0; i < errMsgArr; i++) {
129136
buf.skipUB2(); // skip chunk length
130137

131138
this.errorInfo.batchErrors[i].message = buf.readStr(constants.CSFRM_IMPLICIT);

0 commit comments

Comments
 (0)