【问题标题】:Exception passing parameters to Db2 query in IBM Cloud Functions using Node.js使用 Node.js 在 IBM Cloud Functions 中将参数传递给 Db2 查询的异常
【发布时间】:2018-07-03 12:34:55
【问题描述】:

我在 IBM Cloud Functions / OpenWhisk 中编写了一个基于 Node.js 的操作。该操作从 Db2 检索数据。当我没有参数标记时,查询有效。当我使用如下所示的参数并传入{"confname" : "IDUGEMEA2018" } 时会遇到错误并引发异常。

为什么?需要改变什么?

var ibmdb = require('ibm_db');

function queryConferences(dsn, confname) { 
 try {    
    var conn=ibmdb.openSync(dsn);
    var data=conn.querySync("select shortname, location, begindate, enddate, uri from conference where shortname=?", confname);
    conn.closeSync();
    return {result : data};
 } catch (e) {
     return { dberror : e }
 }
}

function main({confname, __bx_creds: {dashDB:{dsn}}}) {
    return queryConferences(dsn,confname);
}

【问题讨论】:

    标签: node.js db2 openwhisk ibm-cloud-functions


    【解决方案1】:

    失败是因为 bindingParameters 需要一个数组。我让它通过以下方式工作:

    {"confname" : ["IDUGEMEA2018"] }
    

    在 CLI 中,我使用以下内容对其进行了测试:

    bx wsk action invoke myAction -p confname "[\"IDUGEMEA2018\"]" -r
    

    【讨论】:

      猜你喜欢
      • 2021-10-03
      • 1970-01-01
      • 2020-07-29
      • 2021-10-18
      • 2012-10-17
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      相关资源
      最近更新 更多