Skip to content

Error: SQLSTATE=58004 SQLCODE=-901 using function in prepared SQL queries #186

@Phenry-Gaia

Description

@Phenry-Gaia

Hi,

The executeSync() function appears to fail when the bind parameter is enclosed to a SQL function (UPPER() in our case).

The documentation report a deprecated function bindParametersSync() remplaced by bindParameterSync() -> we kept bindParametersSync() as bindParameterSync() isn't recognise in the version we use.

Node.js version: v20.5.1
idb-connector version: v1.2.19
IBM i version: 4 7

import pkg from 'idb-connector';
const { dbconn: idbconn, dbstmt: dbstmt } = pkg;

// Original query
const sSql = "SELECT TRIM(TEXT_DESCRIPTION) AS NAME FROM QSYS2.USER_INFO SYS WHERE AUTHORIZATION_NAME = UPPER(?)";
// Alternative
//const sSql = "SELECT TRIM(TEXT_DESCRIPTION) AS NAME FROM QSYS2.USER_INFO SYS WHERE AUTHORIZATION_NAME = ?"

const connection = new idbconn();
connection.conn('*LOCAL');
const stmt = new dbstmt(connection);

// Username
const login = "po"; // your username

stmt.prepareSync(sSql);
// Original
stmt.bindParametersSync([login]);
// Alternative
//stmt.bindParametersSync([login.toUpperCase()]);
stmt.executeSync();

const row = stmt.fetchSync();

console.log(`Row:${JSON.stringify(row)}\n`);
console.log(row["NAME"]);

stmt.close();
connection.disconn();
connection.close();

Output:
stmt.executeSync();
^
Error: SQLSTATE=58004 SQLCODE=-901 Erreur système SQL.

Describe the bug
The executeSync() function appears to fail when the bind parameter is enclosed to a SQL function (UPPER() in our case).

To Reproduce
Steps to reproduce the behavior:

  1. copy paste provided code, adapt the login variable
  2. run in a node idb-connector environment
  3. uncomment/comment Alternative/Original scenario to see success/fail output

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions