Query.all on Oracle report ORA-00904: invalid identifier error
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.
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?
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.
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;
}
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?
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