Fixed in edge rails: table name quoting

database | edge | rails | sql October 16 2007

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`;
posted by brandon | updated October 16th 10:05 AM
comments feed

2 comments

  1. 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.

    Zach Moazeni Zach Moazeni
    October 16, 2007 at 10:31 AM
  2. 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.

    Gabe da Silveira Gabe da Silveira
    October 16, 2007 at 12:22 PM

Speak your mind:

(Required)

(Required)


(You may use textile in your comments.)

About

I'm Brandon Keepers, a web application developer that likes beautiful code, valid markup and adherence to standards. As a part of Collective Idea in Holland, Michigan, I practice Agile software development primarily using Ruby on Rails.

-86.103171 42.785037

Contact:

more ยป

Syndicate