JRuby

AR models backed by views fail to work

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1RC1
  • Fix Version/s: JRuby 1.1RC2
  • Component/s: None
  • Labels:
    None
  • Environment:
    MySQL
  • Number of attachments :
    0

Description

To verify this,

Just try SomeModelBackedByTable.columns in script/console, this should return all columns in the table.

Try the same with SomeModelBackedByView.columns and this should result in

"Table ViewName doesn't exist".

Activity

Hide
K Venkatasubramaniyan added a comment -

Upon investigation, this problem occurs in class JdbcAdapterInternalService.java inside method

public static IRubyObject columns_internal(final IRubyObject recv, final IRubyObject[] args)

There is check here to verify that the table indeed physically exists before proceeding to get metadata. Obviously this check fails for views. Just commenting out the check fixes the problem.

One way to fix is just not have to have this check. There may be better ideas to fix this.

Show
K Venkatasubramaniyan added a comment - Upon investigation, this problem occurs in class JdbcAdapterInternalService.java inside method public static IRubyObject columns_internal(final IRubyObject recv, final IRubyObject[] args) There is check here to verify that the table indeed physically exists before proceeding to get metadata. Obviously this check fails for views. Just commenting out the check fixes the problem. One way to fix is just not have to have this check. There may be better ideas to fix this.
Hide
K Venkatasubramaniyan added a comment -

BTW, this problem may also exist for other RDBMS like Oracle and DB2 and I just haven't tested to find out whether they are indeed problems.

Show
K Venkatasubramaniyan added a comment - BTW, this problem may also exist for other RDBMS like Oracle and DB2 and I just haven't tested to find out whether they are indeed problems.
Hide
K Venkatasubramaniyan added a comment -

I forgot to add that I am using ActiveRecord JDBC version 0.7.1 I should have mentioned this in the affected versions. but not able to change the description.

Show
K Venkatasubramaniyan added a comment - I forgot to add that I am using ActiveRecord JDBC version 0.7.1 I should have mentioned this in the affected versions. but not able to change the description.
Hide
Charles Oliver Nutter added a comment -

We should try to pin this down for RC2, or 1.1 at the latest.

Show
Charles Oliver Nutter added a comment - We should try to pin this down for RC2, or 1.1 at the latest.
Hide
Ola Bini added a comment -

Fixed on AR-JDBC trunk. There was no real need to actually check for the existence of table at that point.

Show
Ola Bini added a comment - Fixed on AR-JDBC trunk. There was no real need to actually check for the existence of table at that point.
Hide
Nick Sieger added a comment -

Well, there was, because in JDBC, getColumns only returns an empty result set if the table doesn't exist, rather than raising an exception. Should an empty result set always signify a missing table?

Rails expects #columns to raise if the table doesn't exist, otherwise bad things happen (can't remember exactly what right now, but I put the test there for a reason...).

Show
Nick Sieger added a comment - Well, there was, because in JDBC, getColumns only returns an empty result set if the table doesn't exist, rather than raising an exception. Should an empty result set always signify a missing table? Rails expects #columns to raise if the table doesn't exist, otherwise bad things happen (can't remember exactly what right now, but I put the test there for a reason...).
Hide
Nick Sieger added a comment -

Reopening until we find a compromise for this...

Show
Nick Sieger added a comment - Reopening until we find a compromise for this...
Hide
Ola Bini added a comment -

Fixed on trunk of AR-JDBC, by adding back the former check, and now also searching for both tables and views in the DatabaseMetaData.getTables call.

Show
Ola Bini added a comment - Fixed on trunk of AR-JDBC, by adding back the former check, and now also searching for both tables and views in the DatabaseMetaData.getTables call.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: