无法使用工作灯从SQL适配器获取PRIMARY_KEY冲突响应



我有MySql表userID,Mobile,Password,Re-Password列,其中Mobile列是我的PRIMARY_KEY,我从我的SQL适配器插入数据。

SQLAdapter-impl.js

function registration(mob_no,user_name,pass,re_pass){
    return WL.Server.invokeSQLStoredProcedure({
        procedure : "registration",
        parameters : [mob_no,user_name,pass,re_pass]
    });
}

SQLAdapter.xml

<procedure name="registration" />

Registration.js

function registration(mob_no,user_name,pass,re_pass){
    var invocationData = {
            adapter : "SQLAdapter",
            procedure: "registration",
            parameters: [mob_no,user_name,pass,re_pass]
    };
    WL.Client.invokeProcedure(invocationData, {
        onSuccess: getSecretDataOKReg, 
        onFailure: getSecretDataFAILReg
    });
}
function getSecretDataOKReg(response)
{   
    var bool=response.invocationResult.isSuccessful;
    console.log("Registration Operation Successfull :" +bool);
    if(bool)
    {
        saveRegistrationDetails();
        $("#pagePort").load(path + "pages/Login.html", function(){
            $.getScript(path + "js/Login.js", function() {
                if (currentPage.init) {
                    currentPage.init();
                }
            });
        });
    }
}
function getSecretDataFAILReg(response)
{
    alert("Unsuccess "+response);
}

我的问题是当我插入新数据时,一切都很好,我得到适当的响应,一切都是"快乐的结局故事",但当我试图插入相同的手机号码以及不同的permo-combo数据时,我得到错误

Procedure invocation error. Runtime: Failed to retrieve data with procedure : registration worklight.js:4673
WL.Logger.__log worklight.js:4673
PUBLIC_API.(anonymous function) worklight.js:4858
onInvokeProcedureSuccess worklight.js:7355
window.WLJSX.Ajax.WLRequest.WLJSX.Class.create.onSuccess worklight.js:3238
window.WLJSX.Ajax.WLRequest.WLJSX.Class.create.onWlSuccess worklight.js:3210
(anonymous function) worklight.js:947
window.WLJSX.Ajax.Request.WLJSX.Class.create.respondToReadyState worklight.js:1156
window.WLJSX.Ajax.Request.WLJSX.Class.create.onStateChange worklight.js:1094
(anonymous function)

我理解这可能已经到达,因为我曾试图在MYSql中插入相同的主键数据,但我怎么能积极地处理它,并显示警告或用户说你已经注册了?在我的js文件中是否有任何问题来识别SQL错误代码,这是在错误响应中看不到的。

此错误与Worklight在这里没有任何问题,我认为你应该使用Callback从MySQL返回值。

function registration(mob_no,user_name,pass,re_pass,returnValue){
    var invocationData = {
            adapter : "SQLAdapter",
            procedure: "registration",
            parameters: [mob_no,user_name,pass,re_pass,returnValue]
    };
    WL.Client.invokeProcedure(invocationData, {
        onSuccess: getSecretDataOKReg, 
        onFailure: getSecretDataFAILReg
    });
}
function getSecretDataOKReg(response)
{   
    var bool=response.invocationResult.isSuccessful;
    console.log("Registration Operation Successfull :" +bool);
    if(bool)
    {
        saveRegistrationDetails();
        $("#pagePort").load(path + "pages/Login.html", function(){
            $.getScript(path + "js/Login.js", function() {
                if (currentPage.init) {
                    currentPage.init();
                }
            });
        });
    }
}
function getSecretDataFAILReg(response)
{   
    console.log("Check this here "+ response.invocationResult.resultSet[0].returnValue);
    alert("Unsuccess "+JSON.stringify(response));
}

并在存储过程中使用returnValue作为OUT参数,并使用if和else条件。

请查找相同的SQL存储过程

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `loginAuthentication`(IN mob_no VARCHAR(45),IN user_name VARCHAR(45),pass VARCHAR(45),re_pass VARCHAR(45),OUT returnvalue INT)
BEGIN
       DECLARE no_of_records INT;
       SELECT COUNT(*) INTO no_of_records
       FROM tablename.registration 
       WHERE tablename.registration.mob_no=mob_no ;
       IF no_of_records = 1 THEN 
       SET returnvalue = 0; //Already exists one record with mob_no
       ELSE
       // Your INSERT QUERY
       SET returnvalue = 1;
       END IF;
END $$
DELIMITER ;

最新更新