Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3631 (closed defect: duplicate)

Opened 3 years ago

Last modified 2 years ago

table names should be quoted

Reported by: anonymous Assigned to: David
Priority: low Milestone: 1.2.4
Component: ActiveRecord Version: 1.2.3
Severity: normal Keywords: crash, quote table names, reserved words
Cc: eallik, eadz, mislav, bitsweat

Description

Not sure about other db's but with mysql table names probably should be quoted. For example, if I create a table named lines, because I want a model named Line, mysql craps out because to it lines is a reserved word.

Change History

01/27/06 15:41:40 changed by anonymous

  • severity changed from major to normal.

did a little more asking around about databases, and in general it's bad to use reserved words. For starts, not all db's support quoting table names. In my case i was using the lines reserved word because i'm plotting lines :-) I have gone through the activerecord code and quoted all table names and it's working for me... not sure how this would effect other db's but i suspect it would not be a good thing for them... hopefully someone more in the know then i will be able to comment on this.

02/09/06 08:09:00 changed by BobSilva

  • keywords changed from crash to crash, quote table names, reserved words.
  • priority changed from normal to low.

Most databases will support quoted table names, it can create some pretty ugly sql though.

02/09/06 21:13:11 changed by anonymous

  • type changed from defect to enhancement.

06/12/06 17:33:45 changed by cheryl@icci.com

This problem also occurs with column names. For example, it occurs you try to remove a column that is named with a reserved word. The column name needs to have back ticks around it, so a temporary work around is:

remove_column :table_name, '`reserved_word`'

05/23/07 19:39:18 changed by josh

  • status changed from new to closed.
  • resolution set to wontfix.

Don't use reserved words.

09/17/07 14:16:10 changed by elia

  • status changed from closed to reopened.
  • type changed from enhancement to defect.
  • version changed from 1.0.0 to 1.2.3.
  • resolution deleted.
  • milestone set to 1.2.4.

Quoting isn't a bad thing. And if have to deal with a legacy database you can't choose the table names.

09/17/07 16:04:39 changed by elia

  • status changed from reopened to closed.
  • resolution set to duplicate.

09/17/07 16:06:42 changed by elia

  • cc set to eallik, eadz, mislav, bitsweat.