Skip to content

PreparedStatement.execute() throws TypeError when stream=true and no callback provided #1848

@dhensby

Description

@dhensby

Description

PreparedStatement.execute(values) throws a TypeError at runtime when stream = true and no callback is provided.

Root Cause

In lib/base/prepared-statement.js, execute() has the condition:

if (this.stream || (typeof callback === 'function')) {
  return this._execute(values, callback)
}

When stream = true and no callback, this enters _execute(values, undefined). Inside _execute, the inner request completion handler unconditionally calls callback(null, result), which throws TypeError: callback is not a function.

Expected Behaviour

Calling ps.execute(values) with ps.stream = true and no callback should work — results should be consumed via row/error/done events on the underlying request, consistent with how Request.query() and Request.batch() handle streaming without a callback.

Steps to Reproduce

const sql = require('mssql')

const pool = await sql.connect(config)
const ps = new sql.PreparedStatement(pool)
ps.stream = true
ps.input('id', sql.Int)
await ps.prepare('SELECT @id AS id')

// This throws TypeError: callback is not a function
ps.execute({ id: 1 })

Workaround

Provide a no-op callback:

ps.execute({ id: 1 }, () => {})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions