rails / arel

A Relational Algebra
2.06k stars 390 forks source link

InsertManager not wrapping escaped values in correct double-quotes #479

Closed henrytseng closed 6 years ago

henrytseng commented 7 years ago

It looks like InsertManager isn't wrapping characters that are escaped with double-quotes correctly for MySQL to read.

It's rendering the following: INSERT INTOtest(name) VALUES ('Bob\'s Org Group');

From: insert_manager = Arel::InsertManager.new().into(posts); insert_manager.insert([[posts[:name], "Bob\'s Org Group"]]); insert_manager.to_sql

henrytseng commented 7 years ago

Looks like this is method is delegated to connection.quote() but the ActiveRecord::ConnectionAdapters::Mysql2Adapter is not quoting correctly for MySQL. It seems the rails implementation of the adapter adjusts the quotes before sending the statement. It's probably better to solve this at the connection adapter.

https://github.com/rails/rails/issues/28562

It should render the following: INSERT INTO test(name) VALUES ("Bob\'s Org Group");

Will open an issue with rails as well.

matthewd commented 6 years ago

Per #523, Arel development is moving to rails/rails.

If this issue is still relevant, please consider reopening it over there. (Note that the Rails repository does not accept feature request issues, and requires reproduction steps that rely on Active Record's documented API.)