-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue description
Parameter binding fails for Oracle query when parameter name is reused
Expected Behavior
Queries with duplicate parameter names should bind successfully.
Actual Behavior
An error is thrown:
QueryFailedError: NJS-098: 2 positional bind values are required but 1 were provided
Steps to reproduce
Try to execute a query that contains duplicate parameter names. For example:
const repo = module.get<Repository<SomeEntity>>(getRepositoryToken(SomeEntity));
const qb = repo.createQueryBuilder();
qb.where('id = :id', { id: 'foo' }).orWhere('id = :id', { id: 'foo' });
const result = await qb.getManyAndCount();
This is obviously a contrived example, but the point is that it has two parameters with the same name. I experienced the failure on a much more complex query, but I wanted to distill it down as simply as I could for reproduction.
My Environment
| Dependency | Version |
|---|---|
| Operating System | macOS |
| Node.js version | 16.19.0 |
| Typescript version | 4.8.4 |
| TypeORM version | 0.3.20 |
| oracledb version | 6.4.0 |
Additional Context
This was caused by a fix by @iifawzi that went in for version 0.3.18. It's a good fix, and it works fine against the Oracle thick driver, but it fails against the thin driver, which is now standard (v6+ of oracledb).
The problem arises when this code runs in the driver: https://github.com/oracle/node-oracledb/blob/v6.4.0/lib/thin/connection.js#L169-L173. Because of the optimization put in place by the previous fix, the binds list no longer contains the duplicate parameter. Unfortunately, the statement.bindInfoList does, which leads to a mismatch and a ERR_WRONG_NUMBER_OF_POSITIONAL_BINDS error.
@iifawzi, I didn't tag you to call you out. On the contrary, you clearly know this code based on your previous fix and I'm hopeful that you may know a way around this new issue!
Relevant Database Driver(s)
- aurora-mysql
- aurora-postgres
- better-sqlite3
- cockroachdb
- cordova
- expo
- mongodb
- mysql
- nativescript
- oracle
- postgres
- react-native
- sap
- spanner
- sqlite
- sqlite-abstract
- sqljs
- sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
No, I don’t have the time, but I can support (using donations) development.