ibmdb / node-ibm_db

IBM DB2 and IBM Informix bindings for node
MIT License
188 stars 151 forks source link

await ODBCStatement.executeNonQuery does not work as the callback version does #960

Closed gdelory closed 8 months ago

gdelory commented 8 months ago

Although the README says:

An asynchronous/synchronous interface for node.js to IBM DB2 and IBM Informix. Async APIs return promises if callback function is not used. Async APIs supports async-await programming style.

I feel like there is a bug with ODBCStatement.executeNonQuery which doesn't behave the same between the callback version and the promise version. The following code fails:

async function main() {
  try {
    const query = 'update THUB2_DEV."cus" set "stage"=? WHERE "id"=?;'
    const conn = await pool.open(cn)
    const stmt = await conn.prepare(query)
    const result = await stmt.executeNonQuery(['canceled', 1050])
    console.log(result)
    await conn.close()
  } catch(e) {
    console.log(e)
  }
}

main()

With the error:

[Error: [IBM][CLI Driver] CLI0100E  Wrong number of parameters. SQLSTATE=07001] {
  error: '[node-ibm_db] SQL_ERROR',
  sqlcode: -99999,
  state: '07001'
}

But the following code works as expected:

async function main() {
  try {
    const query = 'update THUB2_DEV."cus" set "stage"=? WHERE "id"=?;'
    const conn = await pool.open(cn)
    const stmt = await conn.prepare(query)
    const result = await promisify(stmt.executeNonQuery).bind(stmt)(['canceled', 1050])
    console.log(result)
    await conn.close()
  } catch(e) {
    console.log(e)
  }
}

main()

And returns:

1

Which BTW shows another bug with the TypeScript scripts, which returns a Promise for executeNonQuery (here). I already reported other TypeScript type issues in #958

ibm_db version: ibm_db@3.2.2

bimalkjha commented 8 months ago

@gdelory There was a bug in the code of executeNonQuery api causing this issue. Latest commit has fixed this issue. Also, updated test file to test it. You can install the latest code of ibm_db using command npm install git+https://git@github.com/ibmdb/node-ibm_db.git and verify it. Thanks.

gdelory commented 8 months ago

Thanks:

try {
  const query = 'update THUB2_DEV."cus" set "stage"=? WHERE "id"=?;'
  const conn = await pool.open(cn)
  const stmt = await conn.prepare(query)
  const result = await stmt.executeNonQuery(['canceled', 1050])
  console.log(result)
  await conn.close()
} catch(e) {
  console.log(e)
}

now works and displays 1 as expected, thanks!

Is there some automated commenting/labelling when this will be part of an official released version?

bimalkjha commented 8 months ago

Yes, this issue will get updated once released and you'll get notified.Thanks.

gdelory commented 7 months ago

This is officially fixed and validated on 3.2.3, thanks!