Skip to content
Merged
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
20 changes: 20 additions & 0 deletions test/common/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,26 @@ module.exports = (sql, driver) => {
}).catch(done)
},

'prepared statement with streaming and no callback' (done) {
const ps = new TestPreparedStatement()
ps.stream = true
ps.input('num', sql.Int)
ps.prepare('select @num as number').then(() => {
const req = ps.execute({ num: 123 })
const rows = []

req.on('row', row => rows.push(row))
req.on('error', err => {
ps.unprepare(() => done(err))
})
req.on('done', () => {
assert.strictEqual(rows.length, 1)
assert.strictEqual(rows[0].number, 123)
ps.unprepare(done)
})
}).catch(done)
},

'transaction with rollback' (done) {
let tbegin = false
let tcommit = false
Expand Down
20 changes: 20 additions & 0 deletions test/common/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1402,4 +1402,24 @@ describe('connection string auth - tedious', () => {
})
})
})

describe('PreparedStatement streaming', () => {
const BasePreparedStatement = require('../../lib/base/prepared-statement')
const ConnectionPool = require('../../lib/tedious/connection-pool')

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())
})
})
})
1 change: 1 addition & 0 deletions test/msnodesqlv8/msnodesqlv8.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('msnodesqlv8', function () {
it('prepared statement with affected rows', done => TESTS['prepared statement with affected rows'](done))
it('prepared statement in transaction', done => TESTS['prepared statement in transaction'](done))
it('prepared statement with duplicate output column names', done => TESTS['prepared statement with duplicate output column names'](done))
it('prepared statement with streaming and no callback', done => TESTS['prepared statement with streaming and no callback'](done))
it('transaction with rollback', done => TESTS['transaction with rollback'](done))
it('transaction with commit', done => TESTS['transaction with commit'](done))
it('transaction throws on bad isolation level', done => TESTS['transaction throws on bad isolation level'](done))
Expand Down
1 change: 1 addition & 0 deletions test/tedious/tedious.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('tedious', () => {
it('prepared statement with affected rows', done => TESTS['prepared statement with affected rows'](done))
it('prepared statement in transaction', done => TESTS['prepared statement in transaction'](done))
it('prepared statement with duplicate output column names', done => TESTS['prepared statement with duplicate output column names'](done))
it('prepared statement with streaming and no callback', done => TESTS['prepared statement with streaming and no callback'](done))
it('transaction with rollback', done => TESTS['transaction with rollback'](done))
it('transaction with commit', done => TESTS['transaction with commit'](done))
it('transaction throws on bad isolation level', done => TESTS['transaction throws on bad isolation level'](done))
Expand Down