Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hana] cds.run does not return results for raw sql array #967

Open
dimrat opened this issue Jan 3, 2025 · 0 comments · May be fixed by #973
Open

[hana] cds.run does not return results for raw sql array #967

dimrat opened this issue Jan 3, 2025 · 0 comments · May be fixed by #973
Labels
bug Something isn't working

Comments

@dimrat
Copy link

dimrat commented Jan 3, 2025

Description of erroneous behaviour

cds.run does not return results for an array with "raw" sql. Sometimes we are executing multiple raw sql statements in parallel. Consider the below query:

  const result = await cds.run([
    `SELECT CURRENT_SCHEMA FROM DUMMY`,
    `SELECT CURRENT_SCHEMA FROM DUMMY`,
  ]);
  console.log(result);

Output with the new db adapter:

{ changes: 0 }

Output with the old db adapter

[
  [ { CURRENT_SCHEMA: '45DF5C626DFF4B8BABFE391A3B131002' } ],
  [ { CURRENT_SCHEMA: '45DF5C626DFF4B8BABFE391A3B131002' } ]
]

As far as i can see this comes from the dispatch method in @cap-js/hana/lib/HANAService.js that wraps the query with a DO BEGIN ... END So it might me related to hana only

  async dispatch(req) {
    // Look for deployment batch dispatch and execute as single query
    // When deployment is not executed in a batch it will fail to create views
    if (Array.isArray(req.query) && !req.query.find(q => typeof q !== 'string')) {
      req.query = `DO BEGIN ${req.query
        .map(
          q =>
            `EXEC '${q.replace(/'/g, "''").replace(';', '')}${
            // Add "PAGE LOADABLE" for all tables created to use NSE by default and reduce memory consumption
            /(^|')CREATE TABLE/.test(q) ? ' PAGE LOADABLE' : ''
            }';`,
        )
        .join('\n')} END;`
    }
    return super.dispatch(req)
  }

Detailed steps to reproduce

  1. run the code snippet below in any cap project that is connected to a hdi container

Details about your project

| ---------------------- | --------------------------------------------- |
| @cap-js/asyncapi | 1.0.2 |
| @cap-js/cds-types | 0.6.5 |
| @cap-js/db-service | 1.16.2 |
| @cap-js/hana | 1.5.2 |
| @cap-js/openapi | 1.0.6 |
| @cap-js/sqlite | 1.7.7 |
| @sap/cds | 8.6.0 |
| @sap/cds-compiler | 5.5.2 |
| @sap/cds-dk (global) | 8.3.0 |
| @sap/cds-fiori | 1.2.8 |
| @sap/cds-foss | 5.0.1 |
| @sap/cds-mtxs | 2.2.0 |
| @sap/eslint-plugin-cds | 3.1.0 |
| Node.js | v20.17.0 |

@dimrat dimrat added the bug Something isn't working label Jan 3, 2025
@BobdenOs BobdenOs linked a pull request Jan 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant