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.

SAP Hana Driver does not drop prepared statement

See original GitHub issue

Issue Description

After certain amount of db queries, an error occurs due to exceeded maximum number of prepared statements

Expected Behavior

Single connection should be able to execute infinite number of queries and prepared statements should be closed/dropped when db lib does do it automatically.

Actual Behavior

Error message obtained

Error: exceed maximum number of prepared statements: the number of prepared statements per connection cannot exceed the max statements

Steps to Reproduce

Setup a nestjs with typeorm simple app on SAP hana db, define one entity, and in a loop run inserts for that entity. This brakes after ~34k of inserts

import { InjectRepository } from '@nestjs/typeorm';

  constructor(
    @InjectRepository(Schedule)
    private readonly repo: Repository<Schedule>,
  ) {
  }

for (let i=0; i<=200000; i++) {
      const ent = new Entity({...});
      await this.repo.insert(ent);
}

My Environment

Dependency Version
Operating System MacOS BigSur
Node.js version v12.20.1
Typescript version v3.8.3
TypeORM version v0.2.24
@sap/hana-client version 2.6.58
hdb-pool version 0.1.4
@nestjs/typeorm version 7.0.0

Additional Context

SapQueryRunner.query() is doing databaseConnection.prepare() but not doing stmt.drop() in the callback. In my test, after modifying local copy of the file with

// first thing in the prepare callback
statement.drop((err) => {
  if (err) {
    _this.driver.connection.logger.logQueryError(err, query, parameters, _this);
    resolveChain();
    return fail(new index_1.QueryFailedError(query, parameters, err));
  }
})

Note that patch is done on the compiled js in my local node_modules… Typescript would look different ofc.

I am able to go pass the 34k of inserts w/out the error state above. Let it running all the way up to 200k

Please verify error handling stated above is ok - if I’m gonna do the PR

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

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, although I believe I could do it if I had the time…
  • No, I don’t have the time and I wouldn’t even know how to start.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tmiloscommented, Apr 6, 2021

No updates I can see. I could do a PR to fix it, just wanna get some heads up first, not to waist time producing a rejected PR

1reaction
1i2hscommented, Apr 6, 2021

Any updates on this issue? This gives quite a big performance impact on applications using SAP HANA…🥲

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prepared statement with named parameter - SAP Community
The SAP HANA JDBC driver doesn't support named parameters, so you're still stuck with parameter indexes, but with the dollar-notation it's ...
Read more >
HANA support for JDBC - prepareStatement(String sql, int ...
It seems HANA JDBC driver does not support prepareStatement(String sql, int autoGeneratedKeys). Can someone confirm? If so, is there a plan to ...
Read more >
SAP JDBC driver - in_predicate - where-in clause not working
I am trying to run a query on HANA database using SAP JDBC driver for the query which looks like -> Select *...
Read more >
Prepared Statement Caching - SAP Help Portal
The SAP HANA client caches statements with SQL strings that have been prepared at least twice on the same connection. Once the cache...
Read more >
What could cause JDBC prepared statements to be slow while ...
There must be some configuration issue between them. I suspect it is a networking issue, but the Hana JDBC driver is closed-source as...
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