Skip to content

Commit

Permalink
Merge pull request #1347 from tediousjs/arthur/fix-return-value-on-ex…
Browse files Browse the repository at this point in the history
…ecute

fix: do not specify `handle` as an output parameter when calling `sp_execute`/`sp_unprepare`
  • Loading branch information
arthurschreiber authored Sep 25, 2021
2 parents 7aea4fa + fe4bc69 commit 3eb0dcf
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 3eb0dcf

Please sign in to comment.