Skip to content

SAP HANA cannot bind array parameter #11565

Open
@matthiass-bigcube

Description

@matthiass-bigcube

Issue description

SAP HANA cannot bind array parameter for prepared statement

Expected Behavior

The condition
https://github.com/typeorm/typeorm/blob/3c26cf18a77b5b0cd7c15c811fc3d0a43af32e47/src/driver/sap/SapQueryRunner.ts#L214C1-L219C14?plain=1

should be changed to:

if (parameters?.length > 0 && !parameters.some(Array.isArray)) {
	statement = await promisify(databaseConnection.prepare).call(
		databaseConnection,
		query,
	)
}

This will ensure:

  1. queries with parameters are prepared
  2. queries with no parameters are not prepared, as per SAP recommendation If a SQL statement does not take parameters, Connection.exec[ute] is recommended over Statement.exec[ute] as it requires fewer round trips to the server.
  3. queries with array(s) as parameters are not prepared

One could replace each individual item in the array as parameter (IN (?, ?) instead of IN (?)), but this could cause problems for large arrays.
The comment in the PR perf: improve SapQueryRunner performance #10198 was not added, but I assume the condition should be negated as per my recommendation.

Actual Behavior

Only queries with an array as a parameter will be executed as a prepared statement. This will result in the error Cannot bind parameter, because HANA does not support binding a parameter to an array.

https://github.com/typeorm/typeorm/blob/3c26cf18a77b5b0cd7c15c811fc3d0a43af32e47/src/driver/sap/SapQueryRunner.ts#L214C1-L219C14?plain=1

Steps to reproduce

Any query where the parameter is an array, e.g. .where('u.userId IN (:arrayValues)', { arrayValues: [1, 2] });

My Environment

Dependency Version
Operating System
Node.js version 22.13.0
Typescript version 5.8.2
TypeORM version 0.3.20

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions