Ibm mobilefirst 无法使用worklight从SQL适配器获取主密钥冲突响应?
我有一个MySql表,其中包含userID、Mobile、Password、Re Password列,其中Mobile列是我的主键,我正在从我的SQL适配器向其中插入数据 SQLAdapter impl.jsIbm mobilefirst 无法使用worklight从SQL适配器获取主密钥冲突响应?,ibm-mobilefirst,worklight-adapters,Ibm Mobilefirst,Worklight Adapters,我有一个MySql表,其中包含userID、Mobile、Password、Re Password列,其中Mobile列是我的主键,我正在从我的SQL适配器向其中插入数据 SQLAdapter impl.js function registration(mob_no,user_name,pass,re_pass){ return WL.Server.invokeSQLStoredProcedure({ procedure : "registration",
function registration(mob_no,user_name,pass,re_pass){
return WL.Server.invokeSQLStoredProcedure({
procedure : "registration",
parameters : [mob_no,user_name,pass,re_pass]
});
}
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);
}
SQLAdapter.xml
<procedure name="registration" />
我的问题是,当我插入新数据时,一切都很顺利,我得到了正确的响应,一切都是“幸福结局”,但当我尝试插入相同的手机号码和不同的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没有任何问题,我认为您应该使用回调,它从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 ;
已引用IBM Worklight-是否可以使用Out参数调用存储过程?但我会尝试你问我的建议。Worklight适配器不支持Out参数。Idan是对的,它不工作。另外,我很快会更新这个问题。@PawanAryan:选中projectname.tablename中的select count(*),其中projectname.tablename.mob\u no=data.mob\u no。。。如果它与returnvalue匹配,则用户输出的returnvalue变为“1”,因为mob_no是主键,否则将执行insert并仅返回returnvalue。。现在returnValue将为“0”,因为它位于else部分。请让项目DBA检查存储过程。这对我来说很好…当然我也给他发过同样的邮件。我也会试试这个