Skip to content

Conversation

helix
Copy link

@helix helix commented 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(',')}"

Choose a reason for hiding this comment

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

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.

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.

2 participants