Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/base/prepared-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions test/common/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
})
})