IBM Worklight-在SQL适配器查询中使用变量时出错 [英] IBM Worklight - Error while using variable in a SQL Adapter query

查看:80
本文介绍了IBM Worklight-在SQL适配器查询中使用变量时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在worklight中使用SQL适配器,在这里我需要具有在查询中使用它的变量.

I am using SQL adapter in worklight where I need to have a variable that I need to use it in the query.

我在此处中阅读并遵循相同.但它显示以下错误.

I read here and followed the same. But it`s showing the below error.

在SQL适配器中使用变量时粘贴了完整的错误消息.

Pasted the complete error message on using a variable in the SQL adapter.

  [ERROR   ] FWLSE0099E: An error occurred while invoking procedure  [project Sample]Device/SqlStatementFWLSE0100E:  parameters: [project Sample]{
   "arr": [
      {
         "parameters": [
            null
         ],
         "preparedStatement": "UPDATE devices SET DeviceQuantity=$[count] WHERE DeviceNames = 'DellTestLap';"
      }
   ]
}
Parameter index out of range (1 > number of parameters, which is 0)..
Performed query:
UPDATE devices SET DeviceQuantity=$[count] WHERE DeviceNames = 'DellTestLap';
FWLSE0101E: Caused by:  [project Sample]java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). 
                                                                                                               com.worklight.common.log.filters.ErrorFilter

Project.js

Project.js

     function UpdateDeviceDetails(){


            var count = 2;
            var invocationData2 = {
            adapter : 'Device', // adapter name
            procedure : 'UpdateDeviceDetails', // procedure name
            parameters : [count] 

        };



        WL.Client.invokeProcedure(invocationData2,{
            onSuccess : QuerySuccess,
            onFailure : QueryFailure
        });
}

Adapter.js

Adapter.js

var DeviceDetails  = WL.Server.createSQLStatement("UPDATE devices SET DeviceQuantity=$[count] WHERE DeviceNames = 'DellTestLap';");

function UpdateDeviceDetails(count) {

    return WL.Server.invokeSQLStatement({
        preparedStatement :DeviceDetails,
        parameters : [count]
    });
}

推荐答案

我从未在SQL适配器中使用$ [variable_name]语法.我一直都用?"

I've never used the $[variable_name] syntax with SQL adapters. I've always used "?"

更新设备SET DeviceQuantity =?WHERE DeviceNames = 'DellTestLap';"

"UPDATE devices SET DeviceQuantity=? WHERE DeviceNames = 'DellTestLap';"

但是,假设此语法有效,那么您的代码如何引用名称"count"?变量"count"解析为数字2.SQL语句将无法仅通过变量名来知道引用名称计数.如果传递给参数的变量更像这样:

However, assuming that this syntax does work, how is your code referencing the name "count"? The variable "count" is resolved as the number 2. The SQL statement won't be able to know to reference the name count just by the variable name. It would make more sense if the variable passed to parameters was more like this:

return WL.Server.invokeSQLStatement({
        preparedStatement :DeviceDetails,
        parameters : [{ count: 2 }]
    });

话虽如此,我以前从未使用过这种语法,我只使用?"语法.

That being said, I've never used this syntax before, I just use the "?" syntax.

这篇关于IBM Worklight-在SQL适配器查询中使用变量时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆