CodeFoodPixels / node-promise-mysql

A wrapper for mysqljs/mysql that wraps function calls with Bluebird promises.
MIT License
338 stars 64 forks source link

Callback function error #32

Closed buphmin closed 7 years ago

buphmin commented 7 years ago

First the error i get is: TypeError: this._callback.apply is not a function

From my this stems from the node mysql library that this library wraps around when you get an error and do not supply a callback function. Now since this uses promises this should not be happening correct? At the very least if you provide a .catch

Here is what i am doing here.

var params = {} //connection params (not empty in real)

  mysql.createConnection(params)
.then(connection => {
//This query had mismatched ? to params
  return connection.query("insert into mydb.mytable (myfield1, myfield2, myfield3...myfield19) values (?,?,?, ...?)",
  [1, null, 'abc', ...'19th field']);
})
.then(response => {
  console.log(response);
})
.catch(error => {
  console.log(error);
});

Now the myfield is not nullable and should throw a mysql error, which is fine and expected, but it should not have the no callback error.

Let me know if maybe there is something i missed or this is an actual bug.

Thanks.

buphmin commented 7 years ago

Ok so after digging and digging I have found an error in my sql syntax and/or number of parameters to '?'.

It was a fairly sizable statement so i didnt mark it all there, ill edit my original satement to more accurately reflect the params. But alas after fixing the sql statement that error no longer occurs.

Granted I'm not sure that changes this bug though as the error should be catchable.

CodeFoodPixels commented 7 years ago

Thanks for the report! I'll see if I have time over the weekend to investigate this.

CodeFoodPixels commented 7 years ago

@buphmin trying to replicate this and I'm just getting mysql errors.

To clarify, your bug was caused by something like this, right?

connection.query('insert into posts (user, message, post_date, post_time) values (?, ?, ?, ?)', [data.user, data.message, data.post_date]);

4 question marks, 3 items passed into the query.

buphmin commented 7 years ago

Hi thanks for taking the time to look into this. The error was caused by more question marks then parameters as you said. I can no longer replicate it myself actually, though I believe the base mysql library updated since I mentioned the problem. So perhaps something in how the pieces aligned caused problems. Since I can no longer reproduce the bug I will go ahead and close this. Thanks for taking the time to bring bluebird to mysql.