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.

Oracle Formatter and ORA-00904

See original GitHub issue

Since 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:closed
  • Created 9 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
mhofer117commented, Mar 29, 2018

For anyone finding this issue on google. Here’s the solution using wrapIdentifier with the latest release (0.14.4):

var knex = require("knex")({
  "client"     : "oracledb",
  "connection" : { your connection string },
  // convert all identifiers to uppercase (Oracle standard)
  "wrapIdentifier": (value, origImpl, queryContext) => origImpl(value.toUpperCase())
});
2reactions
elhigucommented, Sep 28, 2017

In knex 0.14 one will be able to override formatters for identifiers https://github.com/tgriesser/knex/pull/2217

Read more comments on GitHub >

github_iconTop Results From Across the Web

What could be causing this error......ORA-00904: : invalid ...
Hi, My Webapp is returning this action error when a user click on a link: Error occurred using: SELECT ucp.*, clp.forename, clp.surname, ...
Read more >
ORA-00904: "T1"."TOT_COSTS_UPLIFTED_FUEL_QTY"
Cause: The column name entered is either missing or invalid. Action: Enter a valid column name. ... column name is correct! ... If...
Read more >
ORA-00904 invalid IDENTIFIER IS COMING WHEN ...
Now I can see that the middle subquery seems to count the same again - just added f.txn_status = 'C'. Perhaps you can...
Read more >
Dynamic SQL Error -ORA-00904: invalid identifier — oracle-tech
I have to write a package to write a text file. The formatting information for the file is held in a table, which...
Read more >
DB Link ORA-00904 with ROWNUM - Oracle Communities
Alternatively, if the to_char and formatting is removed, the query works ... 2001 9 / ORDER BY 1 ASC) * ERROR at line...
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