sapmentors / cds-pg

PostgreSQL adapter for SAP CDS (CAP)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query values must be an array ERROR

alessandro-pavan opened this issue · comments

Hi,
I'm facing an error and I can't find out a solution.
I'm trying to execute a plain sql statement (passing a sql string to db object) on postgres via SAP CAP for Nodejs.
The error is the following

Error: Query values must be an array at Query.submit (C:\Users\PVNLSN02D\Desktop\Projects\quotationcreation\node_modules\pg\lib\query.js:159:14) at Client._pulseQueryQueue (C:\Users\PVNLSN02D\Desktop\Projects\quotationcreation\node_modules\pg\lib\client.js:497:45) at Client.query (C:\Users\PVNLSN02D\Desktop\Projects\quotationcreation\node_modules\pg\lib\client.js:592:10) at Object.executePlainSQL [as sql] (C:\Users\PVNLSN02D\Desktop\Projects\quotationcreation\node_modules\cds-pg\lib\pg\execute.js:114:28) at PostgresDatabase.module.exports [as _CREATE] (C:\Users\PVNLSN02D\Desktop\Projects\quotationcreation\node_modules\@sap\cds\libx\_runtime\db\generic\create.js:11:41) at next (C:\Users\PVNLSN02D\Desktop\Projects\quotationcreation\node_modules\@sap\cds\lib\srv\srv-dispatch.js:75:36) at PostgresDatabase.handle (C:\Users\PVNLSN02D\Desktop\Projects\quotationcreation\node_modules\@sap\cds\lib\srv\srv-dispatch.js:79:6) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async SalesInfoImporter.importToDB (C:\Users\PVNLSN02D\Desktop\Projects\quotationcreation\srv\ImporterFactory.js:503:33) at async SalesInfoImporter.progressiveImportMethod (C:\Users\PVNLSN02D\Desktop\Projects\quotationcreation\srv\ImporterFactory.js:262:17)

The query I'm trying to execute is the following:

INSERT INTO db_SalesOrg (ID,name) VALUES ('Z700','Atos India Hydraulic') ON CONFLICT (ID) DO UPDATE SET name = EXCLUDED.name

Passed directly as a string to db.run method

Browsing through libraries in debug mode i found out that the problem seems to come from the method submit in pg\lib library

if (this.values && !Array.isArray(this.values)) {
      return new Error('Query values must be an array')
    }

this.values is valorized to {} from the request, so the check does not pass...

Any suggestion on how to solve this issue?