使用 WL 返回的结果集.Server.invokeSQLStatement in sql adapter proced

use resultset returned by WL.Server.invokeSQLStatement within sql adapter procedure

本文关键字:in invokeSQLStatement sql adapter proced Server WL 返回 结果 使用      更新时间:2023-09-26

我想使用通过过程本身内的 SQL 适配器过程中的 WL.Server.invokeSQLStatement 语句调用 SQL 语句返回的resultSet

我已经尝试了我们通常在SQL适配器过程中使用result.invocationResult.resultSet[variable].Property的方式,但它不起作用。

.HTML

    <div data-role="page" id="mainPage">
        <div data-role="header">search medicine</div>
            <br>
            <hr>
            <div data-role="content">       
                <input type="text" value="MEDICINE" id="medicine"><hr>
                <input type="text" value="LOCATION" id="location"><hr>
                <input type="submit" id="search" value="SEARCH">
            </div>
        </div>
        <div id="itemsList" data-role="page">
            <table id="myTable" border="1">
                <tr>
                    <th>Registration No</th>
                </tr>
            </table>    
            <div data-role="header">gg</div>
            <div data-role="content"></div>
        </div>

JavaScript

window.$ = window.jQuery = WLJQ;
function wlCommonInit() {
}
$(document).ready(function(){
    $("#search").click(function(){
        GetEmployeeData();  
    });
});
function GetEmployeeData() {        
    var medicine= $("#medicine").val();
    var location=$("#location").val();
    alert(medicine);
    var invocationData = {
        adapter : 'ATM',
        procedure : 'getStudentInfos',
        parameters: [medicine,location]
    };
    WL.Client.invokeProcedure(invocationData,{
        onSuccess : loadFeedsSuccess,
        onFailure : loadFeedsFailure
    });
}
function loadFeedsSuccess(result){      
    alert("Hii");
    WL.Logger.debug("Feed retrieve success");
    if (result.invocationResult.resultSet.length>0) 
        displayFeeds(result.invocationResult.resultSet);
    else 
        loadFeedsFailure();     
}
function loadFeedsFailure(result){      
    alert("H");
}
function displayFeeds(items){
    alert("ii");
    var table = document.getElementById("myTable");
    for(var i=0;i<items.length;i++)
        {
            // Create an empty <tr> element and add it to the 1st position of the table:
            var row = table.insertRow(i+1); 
            var cell1 = row.insertCell(0);
            // Add some text to the new cells:
            cell1.innerHTML = items[i].RegNo;
        }
}
function LoadResultPage() {
    $("AppDiv").hide();
    $("#itemsList").show();
};

适配器 JavaScript

 var selectStatement2 = WL.Server.createSQLStatement("select LocId from location WHERE LocName= ? ");
    var selectStatement3 = WL.Server.createSQLStatement("select RegNo from storeloc WHERE LocId= ? ");
    function getStudentInfos(Name,Location) {    
        var result=WL.Server.invokeSQLStatement({
            preparedStatement : selectStatement2,
            parameters : [Location]
        });
       var a = result.invocationResult.resultSet;
       if(a.length>0)
       var LocId=a[0].LocId;
       return WL.Server.invokeSQLStatement({
        preparedStatement : selectStatement3,
            parameters : [LocId]
        });     
    }

在 Chrome 上,我收到以下错误

过程调用错误。Ecma 错误: 类型错误: 无法读取 属性"结果集"来自未定义 (E%3A%5CPRACTICE%5CATM%5Cadapters%5CATM/ATM-impl.js#25).我的25号线 is var a= result.invocationResult.resultSet;

尝试将适配器 JavaScript 实现更改为以下内容。

尝试了具有不同表和变量的版本,它对我有用(至少,来自Worklight Studio的适配器调用)。

请注意我如何使用locId.resultSet而不是locId.invocationResult.resultSet.后者用于客户端,而前者用于服务器端

另请注意分隔为两个函数。

function getStudentInfos(Name,Location) {
    var locId, a, b;
    locId = getlocId(Location);
    a = locId.resultSet;
    if (a && a.length>0) {
        b = a[0].LocId;
    }
    return WL.Server.invokeSQLStatement({
        preparedStatement : selectStatement3,
        parameters : [b]
    });
}
function getlocId (Location) {
    var result = WL.Server.invokeSQLStatement({
        preparedStatement : selectStatement2,
        parameters : [Location]
    });
    return result;
}

请注意if语句...确保在那里也添加一些错误处理...