本文介绍了在sql adapter过程中使用WL.Server.invokeSQLStatement返回的结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use the resultSet returned by invoking a SQL statement through WL.Server.invokeSQLStatement statement in a SQL adapter procedure within the procedure itself.

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

I have tried the way we generally do by using result.invocationResult.resultSet[variable].Property inside the SQL adapter procedure, but it doesn't works.

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

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

Adapter 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上我收到以下错误

On Chrome i am getting the following error


推荐答案

尝试更改适配器JavaScript实现而不是以下。

Try changing your adapter JavaScript implementation to the following instead.

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

I tried a version of this with different table and variables and it worked for me (at least, the adapter invocation from Worklight Studio).

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

Note how I am using locId.resultSet and not locId.invocationResult.resultSet. The latter is used on the client-side whereas the former is used on the server-side.

请注意分离为两个函数。

Also note the separation to two functions.

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;
}

注意如果声明...确保在那里添加一些错误处理......

Note the if statement... make sure to add some error handling there as well...

这篇关于在sql adapter过程中使用WL.Server.invokeSQLStatement返回的结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:11