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

Query.all on Oracle report ORA-00904: invalid identifier error #73

Open
zorrofox opened this issue May 24, 2013 · 5 comments
Open

Query.all on Oracle report ORA-00904: invalid identifier error #73

zorrofox opened this issue May 24, 2013 · 5 comments

Comments

@zorrofox
Copy link
Contributor

I have use the quick start code

var persist = require("persist");
var type = persist.type;

// define some model objects

test = persist.define('test', {
    'col_str' : type.STRING
});

persist.connect({
    "driver" : "oracle",
    "hostname" : "localhost",
    "user" : "hr",
    "password" : "welcome1",
    trace : true
}, function(err, connection) {
    test.using(connection).all(function(err, rows){
        if (err)
          console.log(err);
    })
});

And I will get ORA-00904: "T0"."id": invalid identifier error.

I have some review on the source code find in the ./lib/drivers/oracle.js file line 186 when the oracle driver implemented escapeColumnName function:

...
escapeColumnName: function (columnName) {
    return '"' + columnName + '"';
  }
...

But the oracle will recognize the double quotation marks as usual char and not match the orignal table column name.

@joeferner
Copy link
Owner

Unfortunately I don't have access to an Oracle environment anymore. Looking at this Stack Overflow question http://stackoverflow.com/questions/13798035/oracle-table-column-name-with-space quotes should work.

It looks like you have tracing on. Can you copy and paste the SQL info SQLPlus and get it to work?

@zorrofox
Copy link
Contributor Author

The output SQL like this:

select t0."col_str" AS c0, t0."id" AS c1 FROM tests t0

The SQL or SQLPLUS also will report the ORA-00904 issue.
And I think you mentioned solution only work in create table on oracle.

@zorrofox
Copy link
Contributor Author

I just try some case, and the if the oracle table column name DOES have some spaces you must use the double quotation marks but if you don't have any spaces you MUST NOT use the them. So I suggest the code bellow:

escapeColumnName: function (columnName) {
    return columnName.indexOf(String.fromCharCode(32)) > 0 ? '"' + columnName + '"' : columnName;
  }

@RobertZito
Copy link

Question, I have a single word table and I am getting the same error, I know the the table is there because I run runSqlEach and it runs fine. Does case sensitivity matter? Everything in the dB is uppercase?

@RobertZito
Copy link

Also note that the "s" in the code that takes the table name to say select from (tablename)s, the s is valid meaning if the table does not end in an s you will get table node found here is what I am finding.The name of my table is USERPROPS and if I use USERPROP I get error [Error: ORA-00904: "T0"."ID": invalid identifier]. The oracle.js is actually adding the s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants