Skip to content Skip to sidebar Skip to footer

Node.js - The Multi Part Could Not Be Bound

I have an error (node:1152) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): RequestError: The multi-part identifier 'SC1.refb' could not be bound.

Solution 1:

It seems that you have some whitespace messed up in the SQL but that is the least of your problems here.

First of all, always attach a rejection handler to every promise or otherwise your app will crash on errors. Example:

Bad:

f().then(function (articles) { ... });

Good:

f().then(function (articles) { ... }, function (error) { ... });

Also good:

f().then(function (articles) { ... }).catch(function (error) { ... });

See this answer to know why it's important:

Second of all, never concatenate strings with SQL or otherwise you will get SQL injection vulnerabilities. Example:

Bad, unsafe, error prone and hard to maintain:

connection.query(
  "SELECT * FROM player WHERE nick = '" + data.login + "' AND pass = '" + data.pass + "'",
  function (err, rows) {
    //...
  }
);

Good, safe, robust and easy to maintain:

connection.query(
  "SELECT * FROM player WHERE nick = ? AND pass = ?",
  [data.login, data.pass],
  function (err, rows) {
    // ...
  }
);

See those answers for more details:

Obligatory comic strip that demonstrates the problem:

enter image description here

Post a Comment for "Node.js - The Multi Part Could Not Be Bound"