Skip to content

SQL syntax error occurs by typeorm insert of multiple rows into table for sap (HANA) database #7899

@niels-schmitt

Description

@niels-schmitt

Issue Description

Expected Behavior

Two new records have been created in table "<HANA_SCHEMA>"."photo".

Actual Behavior

An error occurs at typeorm database operation. No records have been created on database. Server console output:

[Nest] 1032  - 07/13/2021, 8:27:38 AM   ERROR [ExceptionsHandler] sql syntax error: incorrect syntax near ",": line 1 col 48 (at pos 48)
Error: sql syntax error: incorrect syntax near ",": line 1 col 48 (at pos 48)
    at SapQueryRunner.<anonymous> (/home/niels/sap/issues/typeorm-hana-insert-multiple-rows/src/driver/sap/SapQueryRunner.ts:193:53)
    at step (/home/niels/sap/issues/typeorm-hana-insert-multiple-rows/node_modules/tslib/tslib.js:143:27)
    at Object.next (/home/niels/sap/issues/typeorm-hana-insert-multiple-rows/node_modules/tslib/tslib.js:124:57)
    at fulfilled (/home/niels/sap/issues/typeorm-hana-insert-multiple-rows/node_modules/tslib/tslib.js:114:62)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Steps to Reproduce

Prepare:

  1. Clone repository https://github.com/niels-schmitt/typeorm-hana-insert-multiple-rows.
  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 -w'\n' -X POST -H 'Content-Type: application/json' -d '["Flower","Tree"]' localhost:3000/photos

or

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

My Environment

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

Additional Context

Root cause seems to be that an incorrect SQL is created:

INSERT INTO "photo"("id", "name") VALUES (?, ?), (?, ?)

Correct SQL would be:

INSERT INTO "photo"("id", "name") VALUES ((?, ?), (?, ?))

The executed SQL is logged to the console in case of POST for /photosByQueryBuilder.

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.

The issue does not occur in case only one record is inserted:

curl -w'\n' -X POST -H 'Content-Type: application/json' -d '["Flower"]' localhost:3000/photos

or

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

For verification, read all records by

curl -w'\n' localhost:3000/photos

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

Relevant Database Driver(s)

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

Thanks for your help & kind regards
Niels Schmitt

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