2015-01-09 98 views
1

我想打電話給使用節點Oracle驅動程序Oracle存儲過程 - https://github.com/joeferner/node-oracle如何在節點js中處理oracle.sql.ARRAY?

我能夠調用使用下面的代碼的程序,但我有第二個參數(parameterArray)的問題。它需要傳遞一系列的項目,在java中我們使用oracle.sql.ARRAY,但是如何處理這個節點js?我當前的代碼如下...

var oracle = require('oracle'); 

var connectData = { 
    hostname: "example_editted.com", 
    port: 1521, 
    database: "dev", // System ID (SID) 
    user: "user", 
    password: "password" 
} 

oracle.connect(connectData, function(err, connection) { 

var starting_time = req.body.startDate + " 00:00:00" 
var ending_time = req.body.endDate +" 00:00:00" 
var parameterArray = {owner_id: req.body.accountId, time_min: null, time_max: null, duration_min: null, duration_max: null, date_format: "'MM/DD/YYYY HH24:MI:SS'", start_date: starting_time, end_date: ending_time} 
connection.execute("call reporting.execute_report(:1, :2, :3)", ["ProcedureName", parameterArray,new oracle.OutParam()], function(err, results) { 

的當前錯誤,我得到的是

Assertion failed: (handle->InternalFieldCount() > 0), function Unwrap, file /Users/johnson/.node-gyp/0.10.35/src/node_object_wrap.h, line 61. 
Abort trap: 6 
+0

通過我所看到的** ** **(沒有任何node.js經驗),您正試圖傳遞字符串索引關聯數組,Oracle調用接口不允許。無論你在哪裏谷歌的「綁定關聯數組索引varchar2」,你只會發現失敗提到這樣做。通過OCI傳遞數組/集合只允許用於整數索引的afaik。 – nop77svk 2015-01-12 07:56:27

回答

1

基於一個純粹猜測,問題可能在於OCI無力結合與字符串的索引集合,您的解決方案可能是在調用存儲過程並在調用存儲過程之前將您的關聯集合重新組合到PLSQL代碼之前,將您的JS對象分解爲一對常規數組,即...

. 
. 
.  
//var parameterArray = {owner_id: req.body.accountId, time_min: null, time_max: null, duration_min: null, duration_max: null, date_format: "'MM/DD/YYYY HH24:MI:SS'", start_date: starting_time, end_date: ending_time} 
var parameterArrayIndices = ["owner_id", "time_min", "time_max", "duration_min", "duration_max", "date_format", "start_date", "end_date"]; 
var parameterArrayValues = [req.body.accountId, null, null, null, null, "'MM/DD/YYYY HH24:MI:SS'", starting_time, ending_time]; 

connection.execute(" 
    declare 
     i_indices  dbms_sql.varchar2a; 
     i_values  dbms_sql.varchar2a; 
     l_params  <the_collection_type_of_the_procedure's_second_parameter>; 
    begin 
     i_indices := :1; 
     i_values := :2; 

     for i in nvl(i_indices.first,1)..nvl(i_indices.last,0) loop 
      l_params(i_indices(i)) := i_values(i); 
     end loop; 

     reporting.execute_report(:3, l_params, :4); 
    end; 
", [parameterArrayIndices, parameterArrayValues, "ProcedureName", new oracle.OutParam()], function(err, results) {