Skip to content

Commit 84f0fdd

Browse files
committed
Fix logical error handling with queryStream() (Issue #1391)
1 parent fb1d28a commit 84f0fdd

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
pool properties `user`, `connectString`, `edition`, `events`,
1313
`externalAuth`, and `homogeneous` on the Pool and PoolStatistics classes.
1414

15+
- Fixed `queryStream()` logical error handling ([Issue
16+
1391](https://github.com/oracle/node-oracledb/issues/1391)).
17+
18+
- Prevent intermingling of `queryStream()` streaming and `getRow()`/`getRows()`
19+
calls.
20+
1521
## node-oracledb v5.2.0 (7 Jun 2021)
1622

1723
- Connection pool changes:

lib/queryStream.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,20 @@ class QueryStream extends Readable {
8989
this._fetching = true;
9090
this._resultSet._allowGetRowCall = true;
9191
const row = await this._resultSet.getRow();
92-
this._fetching = false;
93-
if (!this._resultSet) {
94-
this.emit('_doneFetching');
95-
return;
96-
}
9792
if (row) {
9893
this.push(row);
9994
} else {
10095
this.push(null);
10196
}
10297
} catch (err) {
10398
this.destroy(err);
99+
} finally {
100+
this._fetching = false;
101+
if (this.resultSet) {
102+
this._resultSet._allowGetRowCall = false;
103+
} else {
104+
this.emit('_doneFetching');
105+
}
104106
}
105107
}
106108

test/list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ Overview of node-oracledb functional tests
329329
13.1.9 Read CLOBs after stream close
330330
13.1.10 meta data
331331
13.1.11 should emit events in the correct order
332+
13.1.12 query with logical error should throw error
332333
13.2 Testing QueryStream.destroy
333334
13.2.1 should be able to stop the stream early with destroy
334335
13.2.2 should be able to stop the stream before any data

test/stream1.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,26 @@ describe('13. stream1.js', function() {
483483
done(new Error('Test should not have thrown an error'));
484484
});
485485
});
486+
487+
it('13.1.12 query with logical error should throw error', function(done) {
488+
const sql = 'select 1 from dual union all select 1 from dual union all select 1/0 from dual';
489+
let stream = connection.queryStream(sql);
490+
491+
stream.on('error', function(error) {
492+
should.exist(error);
493+
should.strictEqual(error.message, 'ORA-01476: divisor is equal to zero');
494+
});
495+
496+
stream.on('data', function(data) {
497+
should.not.exist(data);
498+
});
499+
500+
stream.on('end', function() {
501+
stream.destroy();
502+
});
503+
504+
stream.on('close', done);
505+
});
486506
});
487507

488508
describe('13.2 Testing QueryStream.destroy', function() {

0 commit comments

Comments
 (0)