Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More verbose undefined parameter error messages #1707

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

theirongiant
Copy link

@theirongiant theirongiant commented Nov 22, 2022

Adds list of undefined named parameters/indexes to error message.

For named parameters the error message will be
Bind parameters must not contain undefined (parameters :id, :email). To pass SQL NULL specify JS null
and for array parameters it will be
Bind parameters must not contain undefined (indexes 0, 1). To pass SQL NULL specify JS null

Adds list of undefined named parameters/indexes to error message
@sidorares
Copy link
Owner

ref #1706

@sidorares
Copy link
Owner

I can't remember if .execute() support non-array single parameter, with .query() you allowed to do this:

var post  = {id: 1, title: 'Hello MySQL'};
// you can do post as well as [post]
var query = connection.query('INSERT INTO posts SET ?', post, function (error, results, fields) {
  if (error) throw error;
  // Neat!
});

was only using for my convenience, probably better to just remove
@theirongiant
Copy link
Author

I wasn't aware of that, I'll try out some tests and see how I can handle it.

@theirongiant
Copy link
Author

theirongiant commented Nov 22, 2022

Doesn't look like execute allows that, I get this error when I attempt it: Bind parameters must be array if namedPlaceholders parameter is not enabled.

Interestingly if I do
const connect = createConnection({namedPlaceholders: true}); try { connect.execute({sql: 'insert into tig_test_table set :user'}, {user: {id:1, name:'test', email:'test@test.com'}}, (err, results, fields) => { console.log(err, results, fields); }); } catch (e) { console.log(e); }
There's no error and nothing is inserted into the db but that's probably beyond the scope of what I'm doing here.

@sidorares
Copy link
Owner

one of the unit tests never finishes with your changes, could you try running tests locally?

@theirongiant
Copy link
Author

Apologies for that, I've put a fix in for that issue and it no longer hangs on test-execute-bind-functions. I'm not able to get a clean run on a full test run but I think that's down to me running a real old version of mysql (5.6.45). I'll see if I can get a more up to date version if there are any further issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants