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

fix(typeorm): correct quotes for column identifiers when driver is ‘mariadb‘ #546

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

Conversation

constb
Copy link

@constb constb commented Jun 16, 2020

#531 #545

TypeOrmCrudService.getFieldWithAlias escapes identifiers using backticks or double quotes.

it only uses backticks when this.dbName === 'mysql' but TypeORM also uses 'mariadb' to address a few subtle implementation differences.

this causes service to use double quotes in SQL and that fails with You have an error in your SQL syntax…

Copy link

@jafio jafio left a comment

Choose a reason for hiding this comment

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

I tested the fix in a project that had the bug and it fixed it. I think it can be merged!

Copy link

@adrianobnu adrianobnu left a comment

Choose a reason for hiding this comment

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

I think this is better:

const i = ['mysql','mariadb'].includes(this.dbName) ? '`' : '"';

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes

@constb
Copy link
Author

constb commented Mar 4, 2021

@adrianobnu personally I feel with only two comparisons the explicit code is better and more readable. but honestly whatever as long as a bug gets fixed, I'm fine with it… :)

@adrianobnu
Copy link

@adrianobnu personally I feel with only two comparisons the explicit code is better and more readable. but honestly whatever as long as a bug gets fixed, I'm fine with it… :)

Yes, it works anyway, but this alternative only makes 1 comparison (instead of 2 or more if you have other databases in the same situation), and I see no difficulties in those who see the code understand what it does.

@adrianobnu
Copy link

@zMotivat0r Can you do the review and approve the merge of this small fix?

@constb
Copy link
Author

constb commented Mar 6, 2021

Yes, it works anyway, but this alternative only makes 1 comparison (instead of 2 or more if you have other databases in the same situation), and I see no difficulties in those who see the code understand what it does.

@adrianobnu actually, Array.prototype.includes() must make 2 comparisons to make sure the item isn't in array, and an additional function call. :)

if you're thinking about doing micro-optimisations, I think regexp would be a couple nanoseconds faster here…

@jeremyhalin
Copy link

Having same error.
This issue has been opened for 10 months now, it's a small fix, and it works fine for all MariaDB's users.
Can we merge it? How can we help?

[Nest] 11360   - 2021-04-09 23:09:08   [ExceptionsHandler] You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB server version for the right syntax to use near '."id" = 1)' at line 1 +30543ms

@jspizziri
Copy link

Would love to see this merged.

@sgClaudia98
Copy link

any update on this??

@sgClaudia98
Copy link

This worked for me why is not merged?

@rewiko
Copy link
Collaborator

rewiko commented Nov 28, 2021

I am trying to help and have forked this repo (can't reach the owner of this repo and do not have the credential for the npm repo).

See #710 (comment)

We can hopefully merge it via rewiko#5

@rewiko rewiko mentioned this pull request Nov 28, 2021
19 tasks
@rewiko
Copy link
Collaborator

rewiko commented Nov 28, 2021

Merged via rewiko#5

Copy link

@sgClaudia98 sgClaudia98 left a comment

Choose a reason for hiding this comment

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

This change works!! Merge immediately

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.

7 participants