diff --git a/lib/base/prepared-statement.js b/lib/base/prepared-statement.js index b88967a8..02a0bea3 100644 --- a/lib/base/prepared-statement.js +++ b/lib/base/prepared-statement.js @@ -356,11 +356,10 @@ class PreparedStatement extends EventEmitter { } } - req.execute('sp_execute', (err, result) => { - if (err) return callback(err) - - callback(null, result) - }) + req.execute('sp_execute', typeof callback === 'function' + ? callback + : () => {} + ) return req } diff --git a/test/common/unit.js b/test/common/unit.js index 4757c253..e4733e87 100644 --- a/test/common/unit.js +++ b/test/common/unit.js @@ -1401,5 +1401,22 @@ describe('connection string auth - tedious', () => { assert.strictEqual(ps.overrides.requestTimeout, undefined) }) }) + + describe('PreparedStatement streaming', () => { + it('execute does not throw when stream=true and no callback provided', (done) => { + const pool = new ConnectionPool({ server: 'localhost' }) + const ps = new BasePreparedStatement(pool) + ps.stream = true + ps.prepared = true + ps._handle = 1 + + // Should not throw TypeError — returns the inner Request + const req = ps.execute({}) + assert.ok(req, 'execute() should return the inner Request') + // The request will error (no connection) — that's fine, + // the point is it doesn't throw TypeError + req.on('error', () => done()) + }) + }) }) })