Fixed in edge rails: table name quoting
One of more annoying ActiveRecord bugs has finally been fixed in edge rails after 2 years. Table names in SQL queries are now properly escaped.
On nearly every project it seems I end up having a table name that doesn’t work in either MySQL or sqlite. While they usually are SQL reserved words, most databases allow you to use reserved words if they’re properly quoted.
The following, which doesn’t work in MySQL:
DELETE FROM values;
will now be:
DELETE FROM `values`;
2 Comments
Son of a gun. I ran into this issue with MySQL 5 vs MySQL 4 on a table called “fields”. I didn’t know it was as easy as quoting.
Good to know.
I don’t have time to go check this out to see if it was also fixed, but be aware of possible tangential issues such as a table-detecting regexp code in the Associations module that is not adapter specific and thus will fail to detect quoted tables.
Anyway, I’m glad this is in. ActiveRecord really needed it.