Someone provided a patch for a two-year old bug that apparently still
affects AR-JDBC 0.9.3...


---------- Forwarded message ----------
From:  <nore...@rubyforge.org>
Date: Sun, Mar 7, 2010 at 4:29 AM
Subject: [Jruby-extras-devel] [ jruby-extras-Bugs-18604 ]
activerecord-jdbc does not handle schemaname.tablename naming
construct with mysql
To: nore...@rubyforge.org


Bugs item #18604, was opened at 2008-03-05 07:05
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=7857&aid=18604&group_id=2014

Category: AR-JDBC
Group: 0.2.3
Status: Open
Resolution: None
Priority: 3
Submitted By: Greg Orlowski (gregorlowski)
Assigned to: Nobody (None)
Summary: activerecord-jdbc does not handle schemaname.tablename naming
construct with mysql

Initial Comment:
In rails with MRI + MySQL, we are able to use the following construct
for setting table names in our model classes:

set_table_name "#{databasename}.tablename"

where databasename represents a MySQL database (schema). We need to do
this because our app spans multiple databases (legacy db), and
different model classes reference different schemas (effectively
databases in MySQL).

In JRuby with activerecord-jdbcmysql-adapter-0.7.2, (warbler deployed
on tomcat), we get the error (as a rails error page):

Table databasename. does not exist

(where databasename is the name of our dbschema).

I confirmed that if I remove the schema name, I can run a subset of
our app with the model classes that use the schema named as the
default schema in database.yml (in the database: section).

Rails version: 1.2.6

Gems Versions:
activerecord-jdbc-adapter-0.7.2
activerecord-jdbcmysql-adapter-0.7.2

Jars:
mysql-connector-java-5.0.4-bin.jar
jruby-complete-1.1RC2.jar
goldspike-1.5.jar

database.yml

development:
 adapter: jdbcmysql
 database: ourdbname
 username: ouruser
 password: ourpass
 host: 127.0.0.1


I do have this in my environment.rb:

if RUBY_PLATFORM =~ /java/
  require 'rubygems'
  RAILS_CONNECTION_ADAPTERS = %w(jdbcmysql)
  require 'active_record'
  gem 'activerecord-jdbcmysql-adapter'
  require 'active_record/connection_adapters/jdbcmysql_adapter'
end

----------------------------------------------------------------------

Comment By: Dilshod Mukhtarov (dilshodm)
Date: 2010-03-07 13:29

Message:
I faced same problem with activerecord-jdbc-adapter-0.9.3
The following is a patch that solves problem.

diff -Nru 
activerecord-jdbc-adapter-0.9.3/src/java/jdbc_adapter/RubyJdbcConnection.java
activerecord-jdbc-adapter-0.9.3.new/src/java/jdbc_adapter/RubyJdbcConnection.java
--- 
activerecord-jdbc-adapter-0.9.3/src/java/jdbc_adapter/RubyJdbcConnection.java
      2009-10-26 23:25:01.000000000 +0300
+++ 
activerecord-jdbc-adapter-0.9.3.new/src/java/jdbc_adapter/RubyJdbcConnection.java
  2010-03-07 10:35:12.000000000 +0300
@@ -135,14 +135,17 @@
                    if (schemaName != null) schemaName =
caseConvertIdentifierForJdbc(metadata, schemaName);
                    table_name =
caseConvertIdentifierForJdbc(metadata, table_name);

+                    String catalog = c.getCatalog();
+                    if (schemaName != null) { catalog = schemaName; }
+
                    String[] tableTypes = new
String[]{"TABLE","VIEW","SYNONYM"};
                    RubyArray matchingTables = (RubyArray)
tableLookupBlock(context.getRuntime(),
-                            c.getCatalog(), schemaName, table_name,
tableTypes, false).call(c);
+                            catalog, schemaName, table_name,
tableTypes, false).call(c);
                    if (matchingTables.isEmpty()) {
                        throw new SQLException("Table " + table_name +
" does not exist");
                    }

-                    results =
metadata.getColumns(c.getCatalog(),schemaName,table_name,null);
+                    results =
metadata.getColumns(catalog,schemaName,table_name,null);
                    return unmarshal_columns(context, metadata, results);
                } finally {
                    close(results);

----------------------------------------------------------------------

You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=7857&aid=18604&group_id=2014
_______________________________________________
Jruby-extras-devel mailing list
jruby-extras-de...@rubyforge.org
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to