Skip to content

Commit

Permalink
fix: do not specify handle as an output parameter when calling `sp_…
Browse files Browse the repository at this point in the history
…execute`/`sp_unprepare`

This was causing unexpected `returnValue` events.
  • Loading branch information
arthurschreiber committed Sep 20, 2021
1 parent 7aea4fa commit fe4bc69
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3011,7 +3011,7 @@ class Connection extends EventEmitter {
name: 'handle',
// TODO: Abort if `request.handle` is not set
value: request.handle,
output: true,
output: false,
length: undefined,
precision: undefined,
scale: undefined
Expand All @@ -3037,7 +3037,7 @@ class Connection extends EventEmitter {
name: 'handle',
// TODO: Abort if `request.handle` is not set
value: request.handle,
output: true,
output: false,
length: undefined,
precision: undefined,
scale: undefined
Expand Down
46 changes: 46 additions & 0 deletions test/integration/prepare-execute-statements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,52 @@ describe('Prepare Execute Statement', function() {
});
});

it('does not cause unexpected `returnValue` events to be emitted', function(done) {
const config = getConfig();

const connection = new Connection(config);
connection.connect(function(err) {
if (err) {
return done(err);
}

/**
* @type {{ parameterName: string, value: unknown, metadata: import('../../src/metadata-parser').Metadata }[]}
*/
const returnValues = [];

const request = new Request('select @param', function(err) {
if (err) {
return done(err);
}

assert.lengthOf(returnValues, 1);

connection.close();
});
request.addParameter('param', TYPES.Int);

request.on('prepared', function() {
assert.ok(request.handle);

assert.lengthOf(returnValues, 1);
assert.strictEqual(returnValues[0].parameterName, 'handle');

connection.execute(request, { param: 8 });
});

request.on('returnValue', (parameterName, value, metadata) => {
returnValues.push({ parameterName, value, metadata });
});

connection.prepare(request);
});

connection.on('end', function() {
done();
});
});

it('does not leak memory via EventEmitter listeners when reusing a request many times', function(done) {
const config = getConfig();

Expand Down

0 comments on commit fe4bc69

Please sign in to comment.