Skip to content

Commit 165cd42

Browse files
authored
Merge pull request #12 from romanbalayan/release-6.0.3
Release-6.0.3
2 parents 01bef91 + 8a69681 commit 165cd42

30 files changed

+300
-197
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
# node-oracledb-prebuilt-for-lambda
22

33
- This module is forked from the currently un-maintained [node-oracledb-for-lambda](https://github.com/nalbion/node-oracledb-for-lambda).
4-
- Core oracledb libraries are derived from [node-oracledb](https://github.com/oracle/node-oracledb) v6.0.1
5-
- 6.0.1: Prebuilt for use with AWS Lambda nodejs16.x Runtime
6-
- Also tested to work with AWS Lambda nodejs14.x and nodejs18.x Runtime
4+
- Core oracledb libraries are derived from [node-oracledb](https://github.com/oracle/node-oracledb) v6.0.3
5+
- 6.0.3: Prebuilt for use with AWS Lambda nodejs18.x Runtime
6+
- Also tested to work with AWS Lambda nodejs14.x, nodejs16.x, and nodejs18.x Runtime
77

88
The scripts to reproduce the build process can be found at [node-oracledb-lambda-test](https://github.com/romanbalayan/node-oracledb-lambda-test).
99

1010
# Usage
1111

1212
```bash
13-
npm install --save oracledb-prebuilt-for-lambda@6.0.1
13+
npm install --save oracledb-prebuilt-for-lambda@6.0.3
1414
```
1515

1616
# Versioning
1717
- Changed release version to match that of underlying node-oracledb version.
18-
- i.e. for release based on oracledb 6.0.1, release will be oracledb-prebuilt-for-lambda@6.0.1
18+
- i.e. for release based on oracledb 6.0.3, release will be oracledb-prebuilt-for-lambda@6.0.3
1919

2020

2121
# Releases
2222
| node-oracledb | oracledb-prebuilt-for-lambda |
2323
| ------------------- | ---------- |
24+
| 6.0.3 | 6.0.3 |
2425
| 6.0.1 | 6.0.1 |
2526
| 5.5.0 | 5.5.0 |
2627
| 5.4.0 | 5.4.0 |
@@ -34,6 +35,7 @@ npm install --save oracledb-prebuilt-for-lambda@6.0.1
3435

3536

3637
# Changelog
38+
- v6.0.3: [node-oracledb v6.0.3 changelog](https://node-oracledb.readthedocs.io/en/latest/release_notes.html#node-oracledb-v6-0-3-12-jul-2023)
3739
- v6.0.1: [node-oracledb v6.0.1 changelog](https://node-oracledb.readthedocs.io/en/latest/release_notes.html#node-oracledb-v6-0-1-07-jun-2023)
3840
- v5.5.0: [node-oracledb v5.5.0 changelog](https://github.com/oracle/node-oracledb/blob/main/CHANGELOG.md#node-oracledb-v550-7-sep-2022)
3941
- v5.4.0: [node-oracledb v5.4.0 changelog](https://github.com/oracle/node-oracledb/blob/main/CHANGELOG.md#node-oracledb-v540-9-jun-2022)

index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1+
// Copyright (c) 2015, 2023, Oracle and/or its affiliates.
2+
3+
//-----------------------------------------------------------------------------
4+
//
5+
// This software is dual-licensed to you under the Universal Permissive License
6+
// (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7+
// 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8+
// either license.
9+
//
10+
// If you elect to accept the software under the Apache License, Version 2.0,
11+
// the following applies:
12+
//
13+
// Licensed under the Apache License, Version 2.0 (the "License");
14+
// you may not use this file except in compliance with the License.
15+
// You may obtain a copy of the License at
16+
//
17+
// https://www.apache.org/licenses/LICENSE-2.0
18+
//
19+
// Unless required by applicable law or agreed to in writing, software
20+
// distributed under the License is distributed on an "AS IS" BASIS,
21+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
// See the License for the specific language governing permissions and
23+
// limitations under the License.
24+
//
25+
//-----------------------------------------------------------------------------
26+
127
module.exports = require('./lib/oracledb.js');

lib/connection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class Connection extends EventEmitter {
146146
cls = this._buildDbObjectClass(objType);
147147
cls._connection = this;
148148
cls._objType = objType;
149+
objType._connection = this._impl;
149150
this._dbObjectClasses.set(objType, cls);
150151
}
151152
return (cls);

lib/errors.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ const ERR_INVALID_SID = 519;
161161
const ERR_TNS_NAMES_FILE_MISSING = 520;
162162
const ERR_CONNECTION_EOF = 521;
163163

164-
// define mapping for ODPI-C errors that need to be wrapped with NJS errors
164+
// define mapping for ODPI-C, OCI & ORA errors that need to be wrapped
165+
// with NJS errors
165166
const adjustErrorXref = new Map();
166167
adjustErrorXref.set("DPI-1010", ERR_CONNECTION_CLOSED);
167168
adjustErrorXref.set("DPI-1024", [ERR_INVALID_COLL_INDEX_GET, 'at index ([0-9]+) does']);
@@ -327,7 +328,7 @@ messages.set(ERR_MISSING_CREDENTIALS, // NJS-101
327328
messages.set(ERR_UNEXPECTED_END_OF_DATA, // NJS-102
328329
'unexpected end of data: want %d bytes but only %d bytes are available');
329330
messages.set(ERR_UNEXPECTED_MESSAGE_TYPE, // NJS-103
330-
'unexpected message type %d received');
331+
'unexpected message type %d received at position %d of packet %d');
331332
messages.set(ERR_POOL_HAS_BUSY_CONNECTIONS, // NJS-104
332333
'connection pool cannot be closed because connections are busy');
333334
messages.set(ERR_NAN_VALUE, // NJS-105
@@ -343,9 +344,9 @@ messages.set(ERR_INVALID_TYPE_NUM, // NJS-109
343344
messages.set(ERR_INVALID_ORACLE_TYPE_NUM, // NJS-110
344345
'invalid Oracle type number %d [csfrm: %d]');
345346
messages.set(ERR_UNEXPECTED_NEGATIVE_INTEGER, // NJS-111
346-
'internal error: read a negative integer when expecting a positive integer');
347+
'internal error: read a negative integer when expecting a positive integer at position %d of packet %d');
347348
messages.set(ERR_INTEGER_TOO_LARGE, // NJS-112
348-
'internal error: read integer of length %d when expecting integer of no more than length %d');
349+
'internal error: read integer of length %d when expecting integer of no more than length %d at position %d of packet %d');
349350
messages.set(ERR_UNEXPECTED_DATA, // NJS-113
350351
'unexpected data received: %s');
351352
messages.set(ERR_OSON_FIELD_NAME_LIMITATION, // NJS-114

lib/pool.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Pool extends EventEmitter {
4747
this._timeOfReset = this._createdDate = Date.now();
4848
this._sessionCallback = undefined;
4949
this._connRequestQueue = [];
50+
this._connectionClass = settings.connectionClass;
5051
}
5152

5253
//---------------------------------------------------------------------------
@@ -376,7 +377,9 @@ class Pool extends EventEmitter {
376377
errors.assertParamValue(nodbUtil.isObject(a1), 1);
377378
options = this._verifyGetConnectionOptions(a1);
378379
}
379-
settings.addToOptions(options, "connectionClass");
380+
381+
// get connection class value from pool
382+
options.connectionClass = this._connectionClass;
380383

381384
// if pool is draining/closed, throw an appropriate error
382385
this._checkPoolOpen(true);

lib/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Settings {
6969
// database are returned as though they used the JavaScript time zone
7070
// setting. TIMESTAMP WITH TIME ZONE and TIMESTAMP WITH LOCAL TIME ZONE data
7171
// are returned in native JavaScript format (since they contain time zone
72-
// information).
72+
// information). This is used only in Thick mode (from node-oracledb 6.0.0).
7373
//---------------------------------------------------------------------------
7474
_getDateComponents(useLocal, date) {
7575
if (useLocal) {

lib/thin/dbObject.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ const { GrowableBuffer } = require('./protocol/buffer.js');
3535

3636
class DbObjectPickleBuffer extends GrowableBuffer {
3737

38+
//---------------------------------------------------------------------------
39+
// _readBytesWithLength()
40+
//
41+
// Helper function that processes the number of bytes (if needed) and then
42+
// acquires the specified number of bytes from the buffer.
43+
//---------------------------------------------------------------------------
44+
_readBytesWithLength(numBytes) {
45+
if (numBytes === constants.TNS_LONG_LENGTH_INDICATOR) {
46+
numBytes = this.readUInt32BE();
47+
}
48+
return this.readBytes(numBytes);
49+
}
50+
3851
//---------------------------------------------------------------------------
3952
// getIsAtomicNull()
4053
//
@@ -349,12 +362,12 @@ class ThinDbObjectImpl extends DbObjectImpl {
349362
return buf.readBinaryInteger();
350363
case types.DB_TYPE_VARCHAR:
351364
case types.DB_TYPE_CHAR:
352-
return buf.readStr(constants.TNS_CS_IMPLICIT);
365+
return buf.readStr(constants.CSFRM_IMPLICIT);
353366
case types.DB_TYPE_NVARCHAR:
354367
case types.DB_TYPE_NCHAR:
355-
return buf.readStr(constants.TNS_CS_NCHAR);
368+
return buf.readStr(constants.CSFRM_NCHAR);
356369
case types.DB_TYPE_RAW:
357-
return buf.readBytesWithLength();
370+
return Buffer.from(buf.readBytesWithLength());
358371
case types.DB_TYPE_BINARY_DOUBLE:
359372
return buf.readBinaryDouble();
360373
case types.DB_TYPE_BINARY_FLOAT:
@@ -365,7 +378,6 @@ class ThinDbObjectImpl extends DbObjectImpl {
365378
case types.DB_TYPE_TIMESTAMP_LTZ:
366379
case types.DB_TYPE_TIMESTAMP_TZ:
367380
return buf.readOracleDate(false);
368-
case types.DB_TYPE_BLOB:
369381
case types.DB_TYPE_BOOLEAN:
370382
return buf.readBool();
371383
case types.DB_TYPE_OBJECT:
@@ -374,7 +386,7 @@ class ThinDbObjectImpl extends DbObjectImpl {
374386
return null;
375387
obj = new ThinDbObjectImpl(typeClass);
376388
if (obj._objType.isCollection || this._objType.isCollection) {
377-
obj.packedData = buf.readBytesWithLength();
389+
obj.packedData = Buffer.from(buf.readBytesWithLength());
378390
} else {
379391
obj._unpackDataFromBuf(buf);
380392
}

lib/thin/lob.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ class ThinLobImpl extends LobImpl {
121121
}
122122

123123
getCsfrm() {
124-
if (this.dbType._csfrm !== constants.TNS_CS_NCHAR) {
124+
if (this.dbType._csfrm !== constants.CSFRM_NCHAR) {
125125
if (this._locator[constants.TNS_LOB_LOC_OFFSET_FLAG_3] &
126126
constants.TNS_LOB_LOC_FLAGS_VAR_LENGTH_CHARSET) {
127-
return constants.TNS_CS_NCHAR;
127+
return constants.CSFRM_NCHAR;
128128
}
129129
}
130130
return this.dbType._csfrm;

lib/thin/pool.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ class ThinPoolImpl extends PoolImpl {
144144
}
145145

146146
//---------------------------------------------------------------------------
147-
// get connection from pool
147+
// credentials are obfuscated and stored in an object(userConfig) during
148+
// pool creation. _getConnAttrs() method is used to deobfuscate encrypted
149+
// credentials for creating new connections
148150
//---------------------------------------------------------------------------
149-
async _connect(connAttrs) {
151+
async _getConnAttrs() {
150152
let accessToken;
151-
const conn = new ThinConnectionImpl();
152-
conn._pool = this;
153-
let clonedAttrs = Object.assign({}, connAttrs);
153+
const clonedAttrs = Object.assign({}, this._userConfig);
154154
if (clonedAttrs.password === null) {
155155
clonedAttrs.password = protocolUtil.getDeobfuscatedValue(this._password,
156156
this._obfuscatedPassword);
@@ -204,19 +204,14 @@ class ThinPoolImpl extends PoolImpl {
204204
protocolUtil.getDeobfuscatedValue(this._privateKey,
205205
this._obfuscatedPrivateKey);
206206
}
207-
await conn.connect(clonedAttrs);
208-
clonedAttrs = null;
209-
return conn;
207+
return clonedAttrs;
210208
}
211209

212210
//---------------------------------------------------------------------------
213211
// return available connection if present in pool else
214212
// create new connection and return it
215213
//---------------------------------------------------------------------------
216214
async getConnection() {
217-
if (settings.connectionClass !== '') {
218-
this._userConfig.connectionClass = settings.connectionClass;
219-
}
220215
return await this.acquire();
221216
}
222217

@@ -318,8 +313,11 @@ class ThinPoolImpl extends PoolImpl {
318313
// Grows the pool to include the specified number of connections.
319314
//---------------------------------------------------------------------------
320315
async _growPool(numConns) {
316+
const clonedAttrs = await this._getConnAttrs();
321317
while (numConns > 0) {
322-
let conn = await this._connect(this._userConfig);
318+
const conn = new ThinConnectionImpl();
319+
conn._pool = this;
320+
await conn.connect(clonedAttrs);
323321
conn._newSession = true;
324322
conn._dropSess = false;
325323
conn._lastTimeUsed = Date.now();

lib/thin/protocol/buffer.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ class BaseBuffer {
9292
return 0;
9393
} else if (size & 0x80) {
9494
if (!signed) {
95-
errors.throwErr(errors.ERR_UNEXPECTED_NEGATIVE_INTEGER);
95+
errors.throwErr(errors.ERR_UNEXPECTED_NEGATIVE_INTEGER, this.pos, this.packetNum);
9696
}
9797
isNegative = true;
9898
size = size & 0x7f;
9999
}
100100
if (size > maxSize) {
101-
errors.throwErr(errors.ERR_INTEGER_TOO_LARGE, size, maxSize);
101+
errors.throwErr(errors.ERR_INTEGER_TOO_LARGE, size, maxSize, this.pos, this.packetNum);
102102
}
103103
if (skip) {
104104
this.skipBytes(size);
@@ -375,18 +375,18 @@ class BaseBuffer {
375375
const obj = {};
376376
let numBytes = this.readUB4();
377377
if (numBytes > 0)
378-
obj.toid = this.readBytesWithLength();
378+
obj.toid = Buffer.from(this.readBytesWithLength());
379379
numBytes = this.readUB4();
380380
if (numBytes > 0)
381-
obj.oid = this.readBytesWithLength();
381+
obj.oid = Buffer.from(this.readBytesWithLength());
382382
numBytes = this.readUB4();
383383
if (numBytes > 0)
384-
obj.snapshot = this.readBytesWithLength();
384+
obj.snapshot = Buffer.from(this.readBytesWithLength());
385385
this.skipUB2(); // version
386386
numBytes = this.readUB4();
387387
this.skipUB2(); // flags
388388
if (numBytes > 0)
389-
obj.packedData = this.readBytesWithLength();
389+
obj.packedData = Buffer.from(this.readBytesWithLength());
390390
return obj;
391391
}
392392

@@ -465,7 +465,7 @@ class BaseBuffer {
465465
if (!buf) {
466466
return null;
467467
}
468-
if (csfrm === constants.TNS_CS_IMPLICIT)
468+
if (csfrm === constants.CSFRM_IMPLICIT)
469469
return buf.toString();
470470

471471
// need a copy of the buffer since swap16() changes the buffer in place and
@@ -748,7 +748,7 @@ class BaseBuffer {
748748
const ptr = this.reserveBytes(length);
749749
if (type === types.DB_TYPE_DATE || type == types.DB_TYPE_TIMESTAMP) {
750750
const year = date.getFullYear();
751-
ptr[0] = Math.floor(year / 100) + 100;
751+
ptr[0] = Math.trunc(year / 100) + 100;
752752
ptr[1] = year % 100 + 100;
753753
ptr[2] = date.getMonth() + 1;
754754
ptr[3] = date.getDate();
@@ -757,7 +757,7 @@ class BaseBuffer {
757757
ptr[6] = date.getSeconds() + 1;
758758
} else {
759759
const year = date.getUTCFullYear();
760-
ptr[0] = Math.floor(year / 100) + 100;
760+
ptr[0] = Math.trunc(year / 100) + 100;
761761
ptr[1] = year % 100 + 100;
762762
ptr[2] = date.getUTCMonth() + 1;
763763
ptr[3] = date.getUTCDate();

0 commit comments

Comments
 (0)