2017-08-17 87 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

相關問題