RegExp exec问题

时间:2017-04-16 23:48:07

标签: javascript sql node.js rest

下面的代码验证请求的REST端点是否为 '/ employees /< [A-Za-z0-9 _] +>“以下端点有效”/ employees / 100“。如果端点有效,则排除请求的URL并将员工编号传递给emp.get过程。代码没有执行正确的ReqExp.exec命令,并且在它应该只传递100时传递/ employees / 100.我已经包含了empno和req.url的日志消息。

我不确定问题是执行的sql查询还是将员工编号传递给sql查询。 sql查询应该在employee_number列上执行where语句。

非常感谢任何帮助。

        var empnoPatt = "[A-Za-z0-9_]+";
        var patt = new RegExp("/employees/" + empnoPatt);
        if (patt.test(req.url)) {
            patt = new RegExp(empnoPatt);
            console.log(req.url);
            var empno = patt.exec(req.url);
            console.log(empno);
            emp.get(req, resp, empno);
        }

console.log(req.url);
/employees/100

console.log(empno);
[ 'employees', index: 1, input: '/employees/100' ]

this is the error that I am receiving when I try to search for employee 100
{ RequestError: Invalid column name 'employees'.  This is confusion to me and I am not sure why the sql query thinks employees is a column in the table.

这个执行的函数应返回员工记录,其中employee_number = 100

exports.get = function (req, resp, empno) {
    db.executeSql("SELECT * FROM EMPLOYEE WHERE EMPLOYEE_NUMBER =" + empno, function (data, err) {
        if (err) {
            httpMsgs.show500(req, resp, err);
        }
        else {
            httpMsgs.showJSON(req, resp, data);
        }
    });

这是正确传递员工编号后返回的记录集

{
  "recordsets": [
    [
      {
        "RECORD_KEY": "951112558721130050",
        "EMPLOYEE_NUMBER": "100",
        "EMPLOYEE_FOH_LOGIN": "11",
        "EMPLOYEE_BOH_LOGIN": null,
        "EMPLOYEE_BOH_PASSWORD": "",
        "CLOCK_NUMBER": null,
        "FIRST_NAME": "SAMPLE CLERK",
        "LAST_NAME": null,
        "TRAINING_MODE": false,
        "KEY_CARD": null,
        "VERIFONE_SERVER_ID": null,
        "PAY_TYPE": 1,
        "DEFAULT_ROLE_RECORD_KEY": null,
        "CAN_EDIT_FIELD_PERMISSIONS": false,
        "PRIVILEGE_REQUIRED": null,
        "ACTIVE": true
      }
    ]
  ],
  "recordset": [
    {
      "RECORD_KEY": "951112558721130050",
      "EMPLOYEE_NUMBER": "100",
      "EMPLOYEE_FOH_LOGIN": "11",
      "EMPLOYEE_BOH_LOGIN": null,
      "EMPLOYEE_BOH_PASSWORD": "",
      "CLOCK_NUMBER": null,
      "FIRST_NAME": "SAMPLE CLERK",
      "LAST_NAME": null,
      "TRAINING_MODE": false,
      "KEY_CARD": null,
      "VERIFONE_SERVER_ID": null,
      "PAY_TYPE": 1,
      "DEFAULT_ROLE_RECORD_KEY": null,
      "CAN_EDIT_FIELD_PERMISSIONS": false,
      "PRIVILEGE_REQUIRED": null,
      "ACTIVE": true
    }
  ],
  "output": {},
  "rowsAffected": [
    1
  ]
}

0 个答案:

没有答案