This project is archived and is in readonly mode.

#6012 open
Nic Benders

Incorrect SQL generation for DB2 in Rails 3.0.3

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

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.

Comments and changes to this ticket

  • Bruno Cardoso

    Bruno Cardoso November 22nd, 2010 @ 04:29 PM

    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.

  • rails

    rails February 23rd, 2011 @ 12:00 AM

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

  • rails

    rails February 23rd, 2011 @ 12:00 AM

    • State changed from “open” to “stale”
  • Anton Gerbracht

    Anton Gerbracht February 25th, 2011 @ 03:54 PM

    • State changed from “stale” to “open”

    Issue still exists in Rails 3.0.4

    [state:open]

  • Taylor Brockman

    Taylor Brockman February 28th, 2011 @ 05:36 PM

    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

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Pages