使用sql适配器获取删除操作时出错

时间:2016-05-19 07:08:33

标签: javascript sql ibm-mobilefirst mobilefirst-adapters

我正在使用SQL适配器并尝试从MYSQL数据库中删除行但我收到错误为worklight.js:5355 Procedure invocation error. Runtime: No value specified for parameter 1. Performed query: delete from customer where id=?

image

// ******************* SQL Adapter ************************ *****

var procedurestat7 = WL.Server.createSQLStatement("delete from customer where id=?");
//preparedStatement.setLong(1, id);
function procedure7(id) {
    return WL.Server.invokeSQLStatement({
        preparedStatement : procedurestat7,
        parameters : [id]
    });
}

// ******************** Main.js ********************** *************

function wlCommonInit(){
    /*
     * Use of WL.Client.connect() API before any connectivity to a MobileFirst Server is required. 
     * This API should be called only once, before any other WL.Client methods that communicate with the MobileFirst Server.
     * Don't forget to specify and implement onSuccess and onFailure callback functions for WL.Client.connect(), e.g:
     *    
     *    WL.Client.connect({
     *          onSuccess: onConnectSuccess,
     *          onFailure: onConnectFailure
     *    });
     *     
     */

    // Common initialization code goes here

    $("#view").load("pages/login.html");

};

function register(){
    $("#view").load("pages/register.html");
}



function validateLogin(u,p){
    var u = $("#usr").val();
    var p = $("#pass").val();

    localStorage.setItem('username', u);
    var invocationData = {
            adapter : 'SQL', // adapter name
            procedure : 'procedure4',
            parameters : [u,p]
    };

    WL.Client.invokeProcedure(invocationData,{
        onSuccess : loadSQLQuerySuccess, //success callback
        onFailure : loadSQLQueryFailure // failure callback
    });

    function loadSQLQuerySuccess(result){
        var data = result.invocationResult;
        data = data.resultSet;
        console.log(data);
        if(data == "" || data == null || data == undefined || data == [] || u == "" || u == " " || u == null || u == undefined || p == "" || p == " " || p == null || p == undefined ){
            $("#lgError").show();
            console.log('error');
        }
        else{
            console.log(u+" :: "+p);
            $("#view").load("pages/data.html");
            var uname = localStorage.getItem('username');
            console.log(uname);
            $("#uname").append(uname);
        }
    };

    function loadSQLQueryFailure(result){
        var data = result.invocationResult;
        console.log("failed");

    };
};

function RegLogin(ru,rp){
    var ru = $("#rusr").val();
    var rp = $("#rpass").val();
    localStorage.setItem('username', ru);
    var invocationData = {
            adapter : 'SQL', // adapter name
            procedure : 'procedure5',
            parameters : [ru,rp]
    };

    WL.Client.invokeProcedure(invocationData,{
        onSuccess : rloadSQLQuerySuccess, //success callback
        onFailure : rloadSQLQueryFailure // failure callback
    });

    function rloadSQLQuerySuccess(result){
        var data = result.invocationResult;
        data = data.resultSet;
        if(data == "" || data == null || data == undefined || data == [] ){
            alert("User Registered successfully");
            $("#view").load("pages/login.html");

        }
        else{
            alert("Error");
        }
    };

    function rloadSQLQueryFailure(result){
        var data = result.invocationResult;
        $("#rgError").show();
    };
};

var invocationData = {
        adapter : 'SQL', // adapter name
        procedure : 'procedure3'
};

WL.Client.invokeProcedure(invocationData,{
    onSuccess : loadSQLQuerySuccess1, //success callback
    onFailure : loadSQLQueryFailure1 // failure callback
});

function loadSQLQuerySuccess1(result){
    var data = result.invocationResult;
    console.log("success");
};

function loadSQLQueryFailure1(result){
    var data = result.invocationResult;
    console.log("failed");
};

function custTable(){
    var custInvokeData = {
            adapter:'SQL',
            procedure:'procedure6'

    }

    WL.Client.invokeProcedure(custInvokeData,{
        onSuccess: custSuccess,
        onFailure: custfailure
    });
}

function custSuccess(result){
    var data = result.responseJSON;
    var isSuccess = data.isSuccessful;
    var resultSet = data.resultSet;
    console.log(resultSet.length);
    console.log('Success Customer Data: '+JSON.stringify(data));
    if(isSuccess == true){
        console.log('true');
        var out = "";
        for(var i = 0; i<resultSet.length; i++){
            out += "<tr><td>"+resultSet[i].name+"</td><td>"+resultSet[i].des+"</td><td><span class='custid' onclick='deleteData("+resultSet[i].id+")'>X</span></td></tr>";
        }
        document.getElementById('data').innerHTML = "<table><tr><th>Name</th><th>Desc</th><th>Del</th></tr>" +out+"</table>";
    }
    else
        {
        console.log('false');
        }
}

function custfailure(result){
    var data = result;
    console.log('Success Failure Data: '+JSON.stringify(data));
}

function deleteData(id){
    console.log('Delete function called');
    var id = "";
    var custDelData = {
            adapter:'SQL',
            procedure:'procedure7',
            parameter: [id]
    }

    WL.Client.invokeProcedure(custDelData,{
        onSuccess: DelSuccess,
        onFailure: Delfailure
    });
}

function DelSuccess(){
    console.log('deleted');
}
function Delfailure(){
    console.log('not deleted');
}

1 个答案:

答案 0 :(得分:1)

您应该传递ID值,但在 //VVVVVV $adv = '<a href="'.$rs['adv_url'].'" target="_blank"><img src="'.$adDir.$rs['adv'].'" style="width:250px; height:150px" >&nbsp; </a>'; 中,您将其设置为:procedure7,然后将其作为var id = ""传递...也许这就是您的问题

id