JRuby

activerecord jdbc derby adapter should quote columns called "year"

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    JRuby 1.1.4, activerecord.jdbc-0.8.2, sun java 1.6.0_06, derby 10.4
  • Number of attachments :
    1

Description

When creating a table with a column called "year" in a migration script and running it against derby using the activerecord-jdbc-derby adapter, the migration step fails with the error:

/usr/local/jruby-1.1.4/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:147:in `log': ActiveRecord::ActiveRecordError: Syntax error: Encountered "year" at line 1, column 153.: CREATE TABLE attendances (id int generated by default as identity NOT NULL PRIMARY KEY, member_id integer NOT NULL, group_schedule_id integer NOT NULL, year integer NOT NULL, week integer NOT NULL, created_at timestamp, updated_at timestamp) (ActiveRecord::StatementInvalid)

The "year" column should be quoted since it is a reserved word in derby.

If there is a workaround for this, please let me know.

Activity

Hide
Charles Oliver Nutter added a comment -

Add logic to quote it? To be honest, I'd really like to have more people familiar with the internals of AR-JDBC, and it's really not that bad of code (don't think it's as crazy as AR itself). I'm sure we'll try to look into it, but anything you can to to educate yourself and the wiki would be greatly appreciated

Show
Charles Oliver Nutter added a comment - Add logic to quote it? To be honest, I'd really like to have more people familiar with the internals of AR-JDBC, and it's really not that bad of code (don't think it's as crazy as AR itself). I'm sure we'll try to look into it, but anything you can to to educate yourself and the wiki would be greatly appreciated
Hide
Uwe Kubosch added a comment -

I'll do it!

Temporary work-around is to quote the column yourself:

  create_table "attendances", :force => true do |t|
    t.integer  "member_id",         :null => false
    t.integer  "group_schedule_id", :null => false
    t.integer  '"year"',              :null => false
    t.integer  "week",              :null => false
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "attendances", ["group_schedule_id", "member_id", "week", '"year"'], :name => "index_attendances_on_member_id_and_group_schedule_id_and_year_a", :unique => true

Note the single AND double quotes around the '"year"' column.

Show
Uwe Kubosch added a comment - I'll do it! Temporary work-around is to quote the column yourself:
  create_table "attendances", :force => true do |t|
    t.integer  "member_id",         :null => false
    t.integer  "group_schedule_id", :null => false
    t.integer  '"year"',              :null => false
    t.integer  "week",              :null => false
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "attendances", ["group_schedule_id", "member_id", "week", '"year"'], :name => "index_attendances_on_member_id_and_group_schedule_id_and_year_a", :unique => true
Note the single AND double quotes around the '"year"' column.
Hide
Uwe Kubosch added a comment -

Attached patch with test and fix for this issue.

Started a list of keyword to be quoted, but only added "YEAR" since that is the only one I know about

Please apply. When is the next release for AR-JDBC scheduled? Together with JRuby 1.1.5?

Uwe

Show
Uwe Kubosch added a comment - Attached patch with test and fix for this issue. Started a list of keyword to be quoted, but only added "YEAR" since that is the only one I know about Please apply. When is the next release for AR-JDBC scheduled? Together with JRuby 1.1.5? Uwe
Hide
Thomas E Enebo added a comment -

Fixed in commit 0596cf4. I already have added many other reserved names, but I am sure I am still missing several.

Show
Thomas E Enebo added a comment - Fixed in commit 0596cf4. I already have added many other reserved names, but I am sure I am still missing several.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: