Oracle Formatter and ORA-00904
See original GitHub issueSince Oracle interprets quoted and non-quoted identifiers differently, the database throws ORA-00904 (“invalid identifier”) when Knex’s formatter wraps my identifiers in quotes.
For example:
var tableName = 'employees';
var predicate = {name: 'Johnson'};
knex.select('*').from(tableName).where(predicate); // throws ORA-00904
var newTableName = tableName.toUpperCase();
var newPredicate = {};
for (property in predicate) {
if (predicate.hasOwnProperty(property)) {
newPredicate[property.toUpperCase()] = predicate[property];
}
}
knex.select('*').from(newTableName).where(newPredicate); // works fine
In order to avoid this error, I either find myself .toUpperCase()
-ing all my variables containing identifiers before passing them to Knex or rewriting Formatter_Oracle.prototype.wrapValue
in lib/dialects/oracle/formatter.js to do it for me:
// Wraps a value (column, tableName) with the correct ticks.
Formatter_Oracle.prototype.wrapValue = function(value) {
// jthomm adding `.toUpperCase()`
return (value !== '*' ? '"' + value.toUpperCase() + '"' : '*');
};
I’m not suggesting you guys implement it this way but I was wondering if there is an idiomatic way for me override Formatter_Oracle.prototype.wrapValue
with my own function when I instantiate the client or something. Right now I’m literally changing the code in my local Knex installation every time I want to connect to an Oracle database.
Issue Analytics
- State:
- Created 9 years ago
- Comments:15 (5 by maintainers)
Top GitHub Comments
For anyone finding this issue on google. Here’s the solution using wrapIdentifier with the latest release (0.14.4):
In knex 0.14 one will be able to override formatters for identifiers https://github.com/tgriesser/knex/pull/2217