2017-08-17 88 views
0

我有以下代码。为什么xsjs不允许小写的表名?

var table "ZNAme"; 

var connection = $.db.getConnection(); 
var query; 

try{ 
    query = 'DROP TABLE MYSCHEMA.' + table; 
    var drop = connection.prepareStatement(query); 
    drop.execute(); 

    }catch(e){ 
     $.response.setBody(e.message); 
} 

The problem is that when I run it it gives me an error saying it can't find the table "ZNAME". For some reason it changes all the chars to upper case. However I'm creating this table also using xsjs and it works fine. I'm able to create the table, add data to it and read the data from it. The only thing I can't do is remove it. It only works if all chars are upper case. Can someone explain to me why this is going on? 

var table "ZNAme"; 

var connection = $.db.getConnection(); 
var query; 

try{ 
    query = 'DROP TABLE MYSCHEMA.' + table; 
    var drop = connection.prepareStatement(query); 
    drop.execute(); 

    }catch(e){ 
     $.response.setBody(e.message); 
} 

问题是,当我运行它时,它给了我一个错误,说它无法找到表“ZNAME”。出于某种原因,它将所有的字符都改为大写。不过,我创建这个表也使用xsjs,它可以找到。我能够创建表格,添加数据并从中读取数据。我唯一不能做的就是删除它。有人可以向我解释为什么这会发生吗?

回答

1

通过将对象名称放在双引号("<object name here>")中,可以使用带小写字母的对象名称。

所以,你的代码是可以改变这样

query = 'DROP TABLE MYSCHEMA."' + table + '"'; 

工作。

您可以在整个开发人员指南的HANA文档和许多代码示例中找到该解释。

另请确保您的代码不受SQL注入威胁的影响。您绝对需要确保您的table字符串只包含表名,而不包含其他某个SQL命令。 more on that here

相关问题