Skip to content

Commit aca0e87

Browse files
committed
Internal code and test refactoring and formatting changes
1 parent 5eb11b9 commit aca0e87

File tree

10 files changed

+76
-18
lines changed

10 files changed

+76
-18
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ Thin Mode Changes
8686
#) Fixed bug where connections were not removed from the pool, when
8787
:meth:`connection.close()` method fails for some reason.
8888

89+
#) Internal protocol handling improvements.
90+
8991
Thick Mode Changes
9092
++++++++++++++++++
9193

lib/thin/protocol/messages/base.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Message {
8080
async postProcess() { }
8181

8282
writeFunctionHeader(buf) {
83+
this.writePiggybacks(buf);
8384
buf.writeUInt8(this.messageType);
8485
buf.writeUInt8(this.functionCode);
8586
buf.writeSeqNum();
@@ -328,6 +329,10 @@ class Message {
328329
}
329330

330331
writePiggybacks(buf) {
332+
// Don't write piggybacks if not authenticated yet
333+
if (this.connection._protocol.connInProgress)
334+
return;
335+
331336
if (this.connection._currentSchemaModified) {
332337
this._writeCurrentSchemaPiggyback(buf);
333338
}

lib/thin/protocol/messages/execute.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class ExecuteMessage extends MessageWithData {
115115
if (this.options.autoCommit) {
116116
options |= constants.TNS_EXEC_OPTION_COMMIT;
117117
}
118-
this.writePiggybacks(buf);
119118
this.writeFunctionHeader(buf);
120119
buf.writeUB4(options); // execute options
121120
buf.writeUB4(stmt.cursorId); // cursor id
@@ -258,7 +257,6 @@ class ExecuteMessage extends MessageWithData {
258257
}
259258
numIters = this.numExecs;
260259
}
261-
this.writePiggybacks(buf);
262260
this.writeFunctionHeader(buf);
263261
buf.writeUB4(stmt.cursorId);
264262
buf.writeUB4(numIters);

lib/thin/protocol/messages/logOff.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class LogOffMessage extends Message {
4444
}
4545

4646
encode(buf) {
47-
this.writePiggybacks(buf);
4847
this.writeFunctionHeader(buf);
4948
}
5049

lib/thin/protocol/messages/sessionRelease.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class SessionReleaseMessage extends Message {
4545
}
4646

4747
encode(buf) {
48-
this.writePiggybacks(buf);
4948
this.writeFunctionHeader(buf);
5049
buf.writeUInt8(0); // pointer (tag name)
5150
buf.writeUInt8(0); // tag name length

src/njsModule.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ typedef struct njsBaton njsBaton;
203203
typedef struct njsClassDef njsClassDef;
204204
typedef struct njsConnection njsConnection;
205205
typedef struct njsDataTypeInfo njsDataTypeInfo;
206+
typedef struct njsDbObject njsDbObject;
207+
typedef struct njsDbObjectType njsDbObjectType;
208+
typedef struct njsDbObjectAttr njsDbObjectAttr;
206209
typedef struct njsImplicitResult njsImplicitResult;
207210
typedef struct njsJsonBuffer njsJsonBuffer;
208211
typedef struct njsLob njsLob;
@@ -216,12 +219,9 @@ typedef struct njsSodaDocCursor njsSodaDocCursor;
216219
typedef struct njsSodaDocument njsSodaDocument;
217220
typedef struct njsSodaOperation njsSodaOperation;
218221
typedef struct njsSubscription njsSubscription;
222+
typedef struct njsTokenCallback njsTokenCallback;
219223
typedef struct njsVariable njsVariable;
220224
typedef struct njsVariableBuffer njsVariableBuffer;
221-
typedef struct njsDbObject njsDbObject;
222-
typedef struct njsDbObjectType njsDbObjectType;
223-
typedef struct njsDbObjectAttr njsDbObjectAttr;
224-
typedef struct njsTokenCallback njsTokenCallback;
225225

226226

227227
//-----------------------------------------------------------------------------

src/njsUtils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ bool njsUtils_validateArgs(napi_env env, napi_callback_info info,
878878
// njsUtils_setIntervalYM()
879879
// Set the value of the interval year-to-month(YM) value from a JavaScript
880880
// IntervalYM object. It includes the "year" and "month" properties. At this
881-
// point it is assumed that the property values are intergers.
881+
// point it is assumed that the property values are integers.
882882
//-----------------------------------------------------------------------------
883883
bool njsUtils_setIntervalYM(napi_env env, napi_value value,
884884
dpiIntervalYM *data)
@@ -898,7 +898,7 @@ bool njsUtils_setIntervalYM(napi_env env, napi_value value,
898898
// Set the value of the interval day-to-second(DS) value from a JavaScript
899899
// IntervalYM object. It includes the "days", "hours", "minutes", "seconds"
900900
// and "fseconds" (fractional seconds denoted in ns) properties. At this
901-
// point it is assumed that the property values are intergers.
901+
// point it is assumed that the property values are integers.
902902
//-----------------------------------------------------------------------------
903903
bool njsUtils_setIntervalDS(napi_env env, napi_value value,
904904
dpiIntervalDS *data)

test/bigInt.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ describe('300. bigInt.js', function() {
216216
// in JS Number.
217217
assert(result.outBinds.t.TESTNUMBER === num);
218218
assert(typeof result.outBinds.t.TESTNUMBER == 'bigint');
219-
console.log(BigInt.prototype.toJSON);
220219
BigInt.prototype.toJSON = function() {
221220
return this.toString();
222221
};

test/lobBindAsStringBuffer.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const dbConfig = require('./dbconfig.js');
3737
const fs = require('fs');
3838
const fsPromises = require('fs/promises');
3939
const random = require('./random.js');
40+
const { Readable } = require('stream');
4041

4142
describe('80. lobBindAsStringBuffer.js', function() {
4243
let connection;
@@ -486,6 +487,57 @@ describe('80. lobBindAsStringBuffer.js', function() {
486487
assert.strictEqual(result.outBinds.blob.toString('utf8', (resultLength2 - specStrLength), resultLength2), specialStr);
487488
}); // 80.3.2
488489

490+
it('80.3.3 PLSQL, BIND_INOUT, bind a 32K string using temp lob and a 32K buffer', async function() {
491+
const specialStr = "80.3.3";
492+
const size = 32768;
493+
const bigStr = random.getRandomString(size, specialStr);
494+
const clob = await connection.createLob(oracledb.CLOB);
495+
const inStream = Readable.from([bigStr]);
496+
inStream.pipe(clob);
497+
await new Promise((resolve, reject) => {
498+
inStream.on("error", reject);
499+
clob.on("error", reject);
500+
clob.on("finish", resolve);
501+
});
502+
const bufferStr = Buffer.from(bigStr, "utf-8");
503+
const blob = await connection.createLob(oracledb.CLOB);
504+
const inStream2 = Readable.from([bufferStr]);
505+
inStream2.pipe(blob);
506+
await new Promise((resolve, reject) => {
507+
inStream.on("error", reject);
508+
blob.on("error", reject);
509+
blob.on("finish", resolve);
510+
});
511+
512+
const bindVar = {
513+
clob: { dir: oracledb.BIND_INOUT, type: oracledb.CLOB, val: clob },
514+
blob: { dir: oracledb.BIND_INOUT, type: oracledb.BUFFER, val: bufferStr,
515+
maxSize: size }
516+
};
517+
const result = await connection.execute(sqlRun, bindVar);
518+
const cloboutstr = await result.outBinds.clob.getData();
519+
const specStrLength = specialStr.length;
520+
const resultLength1 = result.outBinds.clob.length;
521+
assert.strictEqual(resultLength1, size);
522+
assert.strictEqual(cloboutstr.substring(0, specStrLength), specialStr);
523+
assert.strictEqual(cloboutstr.substring(resultLength1 - specStrLength,
524+
resultLength1), specialStr);
525+
const resultLength2 = result.outBinds.blob.length;
526+
assert.strictEqual(resultLength2, size);
527+
assert.strictEqual(result.outBinds.blob.toString('utf8',
528+
0, specStrLength), specialStr);
529+
assert.strictEqual(result.outBinds.blob.toString('utf8',
530+
(resultLength2 - specStrLength), resultLength2), specialStr);
531+
await new Promise((resolve) => {
532+
clob.once('close', resolve);
533+
clob.destroy();
534+
});
535+
await new Promise((resolve) => {
536+
blob.once('close', resolve);
537+
blob.destroy();
538+
});
539+
}); // 80.3.3
540+
489541
}); // 80.3
490542

491543
});

test/lobClose.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
const oracledb = require('oracledb');
3535
const assert = require('assert');
3636
const dbConfig = require('./dbconfig.js');
37+
const testUtil = require('./testsUtil.js');
3738
const fs = require('fs');
3839

3940
describe('54. lobClose.js', function() {
@@ -107,18 +108,20 @@ describe('54. lobClose.js', function() {
107108

108109
it('54.5 temp LOBs should be freed in next rpc', async function() {
109110
const conn2 = await oracledb.getConnection(dbConfig);
111+
const sid = await testUtil.getSid(conn2);
110112
const tempLOBArray = [];
111113
const numLOBs = 20;
112-
const query = "select cache_lobs+nocache_lobs from v$temporary_lobs where sid = sys_context('USERENV','SID')";
114+
const query = "select cache_lobs+nocache_lobs from v$temporary_lobs where sid = :SID";
113115

114116
// Create multiple temp LOB's
115117
for (let i = 0; i < numLOBs; i++) {
116118
tempLOBArray[i] = await conn2.createLob(oracledb.CLOB);
117119
}
118120

119121
// Check number of opened temp LOB's
120-
let result = await conn2.execute(query);
121-
let numTempLOBs = result.rows[0][0];
122+
await conn2.ping();
123+
let result = await conn.execute(query, {SID: sid});
124+
const numTempLOBs = result.rows[0][0];
122125
assert.strictEqual(numTempLOBs, numLOBs);
123126

124127
// Destroy multiple temp LOB's
@@ -129,10 +132,11 @@ describe('54. lobClose.js', function() {
129132
});
130133
}
131134

132-
// temp LOB's should be freed on roundtrip (like execute) as piggybacks are sent for closing temp LOB's
133-
result = await conn2.execute(query);
134-
numTempLOBs = result.rows[0][0];
135-
assert.strictEqual(numTempLOBs, 0);
135+
// temp LOB's should be freed on roundtrip (like ping) as piggybacks are sent for closing temp LOB's
136+
await conn2.ping();
137+
result = await conn.execute(query, {SID: sid});
138+
// if no temp lobs exist, the query will not return any rows
139+
assert.strictEqual(result.rows.length, 0);
136140
await conn2.close();
137141
}); // 54.5
138142

0 commit comments

Comments
 (0)