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.

paginate_by_sql fails when using Oracle and the jdbc driver.

#237

Why not remove the following block of code altogether?

unless ['oracle', 'oci'].include?(self.connection.adapter_name.downcase)
  count_query << ' AS count_table'
end

When using JDBC connection.adapter_name shows up as jdbc regardless of the database. So this will fail for Oracle when using JDBC and when the inner select statement returns no rows.

count_query = "SELECT COUNT(*) FROM (#{count_query})"

Reported by squirrelbone · July 8th, 2008 @ 09:05 PM

State: open
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Mislav
    Mislav
    • Tag changed from will_paginate to oracle, will_paginate

    Interesting. And how will removing those lines of code fix the problem with Oracle?

    August 4th, 2008 @ 05:32 PM

  2. squirrelbone
    squirrelbone

    Example of what happens with Oracle. Since

    count_query = "SELECT COUNT(*) FROM (#{count_query})"
    unless ['oracle', 'oci'].include?(self.connection.adapter_name.downcase)
    count_query << ' AS count_table'
    end
    

    count_query is a subquery, though in oracle when you try to name it using "AS count_table" it throws an error. So when using JDBC, despite connecting to an Oracle database (self.connection.adapter_name.downcase == "jdbc") it will runs that block of code which isn't necessary in the first place. Even though naming it count_table works on the other databases, it's used for nothing.

    So I'll show you in Oracle with a simple example

    SQL> create table pooper (id NUMBER);
    Table created.
    
    SQL> select count(*) from (select * from pooper);
      COUNT(*)
    ----------
             0
    
    SQL> select count(*) from (select * from pooper) AS count_table;
    select count(*) from (select * from pooper) AS count_table
                                                *
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    
    
    

    August 6th, 2008 @ 12:42 AM

  3. Mislav
    Mislav
    • State changed from new to open

    I see now. I'll try to take a different approach of just adding the "AS ..." alias explicitly to databases which need it.

    August 6th, 2008 @ 03:14 PM

  4. squirrelbone
    squirrelbone

    Why is that alias needed for any of the databases? I can't find anywhere that it's used. If I were you I'd just remove this block of code:

    @@@ruby unless ['oracle', 'oci'].include?(self.connection.adaptername.downcase) countquery << ' AS count_table' end

    
    
    Unless I'm missing something, which is certainly possible.
    

    August 7th, 2008 @ 04:05 PM

  5. dave smylie
    dave smylie

    Not sure if this has been fixed in git, but bug still exists in the current gem version (2.3.7)

    I'm using the oracleenhanced adaptor, which falls into this unless block and causes invalid sql.

    I've changed it to:

    unless ['oracle', 'oci', 'oracleenhanced'].include? self.connection.adapter_name.downcase)

    count_query << '  AS count_table'
    
    

    end

    which fixes it for me.

    February 24th, 2009 @ 10:26 PM

  6. Mislav
    Mislav

    Not fixed yet. Looking into it

    February 26th, 2009 @ 06:50 PM

  7. chobomuffin
    chobomuffin

    I am also experiencing this problem with the Oracle Enhanced Adapter. Adding 'oracleenhanced' to the following seemed to work; unless ['oracle', 'oci'].include?(self.connection.adapter_name.downcase)

    However do you even need the ' AS count_table' at all? Does MySQL or other database implementations require that syntax?

    March 31st, 2009 @ 02:52 AM

  8. Mislav
    Mislav

    They probably don't. I will throw this out the window soon, so you guys don't have any more problems

    March 31st, 2009 @ 11:27 PM

  9. nathanvda
    nathanvda

    We switched to the oracle-enhanced and also bumped into this error. Squirrelbone gave a good explanation. I would just adjust the code as mentioned above too:

    unless ['oracle', 'oci', 'oracle_enhanced'].include?(self.connection.adapter_name.downcase)

    This works for me, and does not impact the other databases, where the extra alias might be needed.

    April 23rd, 2009 @ 05:47 PM

  10. Mislav
    Mislav
    • Tag changed from oracle, will_paginate to jdbc, oracle, will_paginate

    I improved oracle detection a bit. Still doesn't solve the JDBC issue, though.

    May 21st, 2009 @ 11:36 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.