0

我在 worklight 中使用 SQL 适配器,我需要有一个变量,我需要在查询中使用它。

在这里阅读并遵循相同的内容。但它显示以下错误。

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

  [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

项目.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
        });
}

适配器.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]
    });
}
4

2 回答 2

2

我从未在 SQL 适配器中使用过 $[variable_name] 语法。我一直用“?”

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

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.

于 2013-09-18T14:50:20.257 回答
1

You can also use the syntax of ?

var DeviceDetails  = WL.Server.createSQLStatement("UPDATE devices SET DeviceQuantity=? WHERE DeviceNames ='DellTestLap';");

this will work surely try it !!!!!!!!!!!!!

于 2013-12-19T05:09:51.763 回答