Skip to content

Support number as field name #5

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

Closed
wants to merge 3 commits into from

Conversation

XadillaX
Copy link
Contributor

E.g.

CREATE TABLE `test` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `1` int(11) NOT NULL,
  `2` int(11) NOT NULL,
  `3` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

And my code would be like:

let id = 5;
let idx = 1;
let sql = "UPDATE `test` SET ?? = ?? + (?) WHERE `id` = ?";
let params = [ idx, idx, 1, id ];

@XadillaX
Copy link
Contributor Author

Anyone who to handle this PR?

@XadillaX
Copy link
Contributor Author

@dougwilson @fengmk2

@@ -23,6 +23,10 @@ SqlString.escapeId = function escapeId(val, forbidQualified) {
return sql;
}

if(typeof val === 'number') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style

@fengmk2
Copy link
Member

fengmk2 commented Jul 28, 2016

Is there any document talk about filed name can be a number?

@XadillaX
Copy link
Contributor Author

XadillaX commented Jul 28, 2016

@fengmk2 cnpm's model layer https://github.com/cnpm/cnpmjs.org/blob/master/models/download_total.js uses 'd1', 'd2'...

And I tried to use 1, 2...

It created successfully.

@dougwilson
Copy link
Member

Sorry, apparently I never actually subscribed to this repository :) I don't see anything wrong with the concept, but I have a few comments on the change itself:

  1. What if instead of stringifying only numbers, we just stringified anything that was not an array? Then it would let anything work.
  2. The reassigning of an argument variable causes the function to deoptimize in v8. Please assign to a non-argument variable.

@XadillaX
Copy link
Contributor Author

XadillaX commented Jul 29, 2016

@dougwilson

For the first point, I don't think someone will expect escapeId(true) to be "true". But if you think it's necessary, I'm glad to stringify anything was not an array.

For the second one, I will commit later to declare a new variable.

@dougwilson
Copy link
Member

For the first point, I don't think someone will expect escapeId(true) to be "true". But if you think it's necessary, I'm glad to stringify anything was not an array.

Sure, I tend to agree, but i.m.o that same argument would just be instead of even making this PR, just pass the number as a string in the first place... :)

@XadillaX
Copy link
Contributor Author

XadillaX commented Jul 29, 2016

@dougwilson e.g.

for (let i = 0; i < 10; i++) {
  escapeId(i);
}

Code above will crashed without this PR. But it's more convenient. Or the code should be like:

for (let i = 0; i < 10; i++) {
  escapeId(i.toString());
}

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

Successfully merging this pull request may close these issues.

3 participants