Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Incorrect SQL generation for DB2 in Rails 3.0.3

#6012

In Rails 3.0.1 (ARel 1.0.1) calling "Account.first" generates this SQL:

SELECT account.* FROM account FETCH FIRST 1 ROWS ONLY

After upgrading to Rails 3.0.3 (ARel 2.0.4) it generates this:

SELECT account.* FROM account LIMIT

Which is illegal for DB2, and throws an error:

ActiveRecord::StatementInvalid: RuntimeError: Failed to execute statement: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token "LIMIT" was found following "". Expected tokens may include: "FETCH FIRST ROWS ONLY". SQLSTATE=42601 SQLCODE=-104: SELECT account.* FROM account LIMIT 1

In both cases the ibm_db gem version 2.5.5 was used. I can provide detailed database.yml, model files, and the Gemfile if it would be helpful.

Reported by Nic Benders · November 19th, 2010 @ 07:18 AM

State: open
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Bruno Cardoso
    Bruno Cardoso

    I have the same problem with Oracle. It generates a query with "LIMIT X" when I try to use a belongs_to association.

    This is definitely a problem with rails 3.0.3. ActiveRecord is assuming we are using a BD with "LIMIT" command.

    November 22nd, 2010 @ 04:29 PM

  2. rails
    rails
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 23rd, 2011 @ 12:00 AM

  3. rails
    rails
    • State changed from open to stale

    February 23rd, 2011 @ 12:00 AM

  4. Anton Gerbracht
    Anton Gerbracht
    • State changed from stale to open

    Issue still exists in Rails 3.0.4

    [state:open]

    February 25th, 2011 @ 03:54 PM

  5. Taylor Brockman
    Taylor Brockman

    Confirmed that activerecord 3.0.2 - 3.0.4 break with the same problem above.

    Worked around the issue by downgrading activerecord to 3.0.1.

    sudo gem install activerecord --version=3.0.1

    gem 'activerecord', '= 3.0.1'

    2011-Feb-28 ibm_db limit workaround, broken w/ ibm_db = 2.5.6 and active_record >= 3.0.2

    February 28th, 2011 @ 05:36 PM