question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QueryFailedError (Invalid parameter) occurs at typeorm insert into table for sap (HANA) database

See original GitHub issue

Issue Description

Expected Behavior

No error shall occur, and a new record has been inserted into table "<HANA_SCHEMA>"."photo".

Actual Behavior

An error occurs at typeorm database operation. Though, the expected record has been inserted into the table. Server console output:

[Nest] 5090  - 08/02/2021, 7:15:24 PM   ERROR [ExceptionsHandler] Invalid parameter for function 'exec[ute](sql[, params][, options][, callback])'
QueryFailedError: Invalid parameter for function 'exec[ute](sql[, params][, options][, callback])'
    at QueryFailedError.TypeORMError [as constructor] (/home/niels/sap/issues/typeorm-hana-insert-into-table/src/error/TypeORMError.ts:7:9)
    at new QueryFailedError (/home/niels/sap/issues/typeorm-hana-insert-into-table/src/error/QueryFailedError.ts:9:9)
    at SapQueryRunner.<anonymous> (/home/niels/sap/issues/typeorm-hana-insert-into-table/src/driver/sap/SapQueryRunner.ts:221:34)
    at step (/home/niels/sap/issues/typeorm-hana-insert-into-table/node_modules/tslib/tslib.js:143:27)
    at Object.next (/home/niels/sap/issues/typeorm-hana-insert-into-table/node_modules/tslib/tslib.js:124:57)
    at /home/niels/sap/issues/typeorm-hana-insert-into-table/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/home/niels/sap/issues/typeorm-hana-insert-into-table/node_modules/tslib/tslib.js:113:16)
    at ArgParser.cbfunc (/home/niels/sap/issues/typeorm-hana-insert-into-table/src/driver/sap/SapQueryRunner.ts:219:82)
    at ConnectionExecCallback (/home/niels/sap/issues/typeorm-hana-insert-into-table/node_modules/@sap/hana-client/lib/index.js:489:22)

Steps to Reproduce

Prepare:

  1. Clone repository https://github.com/niels-schmitt/typeorm-hana-insert-into-table.
  2. npm install
  3. Get a running HANA instance, and credentials for user <HANA_USER> with authorization CREATE ANY on schema <HANA_SCHEMA>.
  4. cp template.env .env
  5. In file .env enter values for: HANA_HOST, HANA_PORT, HANA_USER, HANA_PASSWORD, HANA_SCHEMA

Reproduce Issue:

npm run start
curl -X POST -H 'Content-Type: application/json' -d '["Flower"]' localhost:3000/photos

or

curl -X POST -H 'Content-Type: application/json' -d '["Tree"]' localhost:3000/photosByQueryBuilder

My Environment

Dependency Version
Operating System Ubuntu 20.04.2
Node.js version v14.17.4
Typescript version @4.3.5
TypeORM version @0.2.36
@nestjs/core @8.0.5
@nestjs/typeorm @8.0.1
@sap/hana-client @2.9.23
hdb-pool @0.1.6

Additional Context

The error occurs since TypeORM version 0.2.35, it does not occur for TypeORM version 0.2.34.

POST for /photos executes

await this.photoRepository.manager.insert(Photo, photos);

POST for /photosByQueryBuilder executes

await this.photoRepository
  .createQueryBuilder()
  .insert()
  .into(Photo)
  .values(photos)
  .execute();

The issues occurs for both variants.

(Read all records by

curl localhost:3000/photos

)

The issue does not occur in case a postgres database is connected.

To verify, set postgres credentials and DB_TYPE=postgres in file .env.

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres no
react-native
sap yes
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.
  • ✖️ Yes, I have the time, but I don’t know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
imnotjamescommented, Aug 12, 2021

I was able to insert after https://github.com/typeorm/typeorm/pull/8072 was applied - can you confirm?

1reaction
richardscholtencommented, Aug 5, 2021

Same issue here when running migrations. The migration itself (create table) works without a problem, but registering the migration fails:

query: INSERT INTO "USR_XXX"."migrations"("timestamp", "name") VALUES (?, ?) -- PARAMETERS: [1627466631519,"CreateTableBodemverzoek1627466631519"]
query: SELECT CURRENT_IDENTITY_VALUE() FROM "SYS"."DUMMY"
query failed: INSERT INTO "USR_XXX"."migrations"("timestamp", "name") VALUES (?, ?) -- PARAMETERS: [1627466631519,"CreateTableBodemverzoek1627466631519"]
error: { QueryFailedError: Invalid parameter for function 'exec[ute](sql[, params][, options][, callback])'
    at QueryFailedError.TypeORMError [as constructor] (/xxx/node_modules/typeorm/error/TypeORMError.js:9:28)
    at new QueryFailedError (/xxx/node_modules/typeorm/error/QueryFailedError.js:13:28)
    at SapQueryRunner.<anonymous> (/xxx/node_modules/typeorm/driver/sap/SapQueryRunner.js:252:50)
    at step (/xxx/node_modules/tslib/tslib.js:143:27)
    at Object.next (/xxx/node_modules/tslib/tslib.js:124:57)
    at /xxx/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/xxx/node_modules/tslib/tslib.js:113:16)
    at ArgParser.cbfunc (/xxx/node_modules/typeorm/driver/sap/SapQueryRunner.js:249:108)
    at ConnectionExecCallback (/xxx/node_modules/@sap/hana-client/lib/index.js:489:22)
  query: 'SELECT CURRENT_IDENTITY_VALUE() FROM "SYS"."DUMMY"',
  parameters: [],
  driverError:
   { Error: Invalid parameter for function 'exec[ute](sql[, params][, options][, callback])'
       at Socket.<anonymous> (/xxx/node_modules/@sap/hana-client/lib/index.js:53:13)
       at Socket.emit (events.js:198:13)
       at addChunk (_stream_readable.js:288:12)
       at readableAddChunk (_stream_readable.js:269:11)
       at Socket.Readable.push (_stream_readable.js:224:10)
       at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) code: -20002, sqlState: 'HY000' },
  code: -20002,
  sqlState: 'HY000' }
typeorm: 0.2.36
@sap/hana-client: 2.9.28

This error does not occur on typeorm 0.2.34.

Read more comments on GitHub >

github_iconTop Results From Across the Web

XSODATA Multi Table Insert - SAP Community
i tried taking the user_id as IN parameter and writing my logic to INSERT records into the two tables (ABC & XYZ)for which...
Read more >
typeorm-1/CHANGELOG.md at master - GitHub
Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Read more >
TypeORM throws QueryFailedError Table already exists on ...
I am using a .env file to pass in some environment variables for connecting to my local database. Synchronize is set to true...
Read more >
typeorm: CHANGELOG
TypeORM now properly works when installed within different node_modules contexts (often happen if TypeORM is a dependency of another library or TypeORM is ......
Read more >
Source - GitHub
It's user responsibility to name tables short if their RDBMS limit table name length since it ... correctly handle multiple-row insert for SAP...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found