Fix: escape MySQL identifiers using reserved words#42
Open
helix wants to merge 1 commit intotagomoris:masterfrom
Open
Fix: escape MySQL identifiers using reserved words#42helix wants to merge 1 commit intotagomoris:masterfrom
helix wants to merge 1 commit intotagomoris:masterfrom
Conversation
dmurvihill
reviewed
Apr 13, 2017
| values << Mysql2::Client.pseudo_bind(values_template, data) | ||
| end | ||
| sql = "INSERT INTO #{table} (#{@column_names.join(',')}) VALUES #{values.join(',')}" | ||
| sql = "INSERT INTO `#{table}` (#{@column_names.map { |colname| "`#{colname}`" }.join(',')}) VALUES #{values.join(',')}" |
There was a problem hiding this comment.
Column names may legally include a backtick character themselves.
Identifier quote characters can be included within an identifier if you quote the identifier. If the character to be included within the identifier is the same as that used to quote the identifier itself, then you need to double the character. The following statement creates a table named a`b that contains a column named c"d:
CREATE TABLE `a``b` (`c"d` INT);So in addition to wrapping names in backticks, you will also have to replace backticks inside the names with double backticks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference: