Talk:Running Rails with ActiveRecord-JDBC

From JRubyWiki

Jump to: navigation, search

Hi, I have followed instructions and am coming unstuck on step 12 - scaffold creation fails as follows:

START PASTE=================================================

E:\apps\jruby-0.9.1\railsapps\xxx>jruby script/generate scaffold widget

     exists  app/controllers/
     exists  app/helpers/
     exists  app/views/widgets
     exists  test/functional/
 dependency  model
     exists    app/models/
     exists    test/unit/
     exists    test/fixtures/
  identical    app/models/widget.rb
  identical    test/unit/widget_test.rb
  identical    test/fixtures/widgets.yml

The driver encounter an error: unable to choose type from: [["DOUBLE", {"num_prec_radix"=>10, "type_name"=>"DOUBLE", "case_sensitive"=>"false", "sql_data_type"=>0, "maximum_scale"=>308, "data_type"=>6, "literal_suffix"=>"", "searchable"=>3, "auto_increment"=>"true", "create_params"=>"[(M,D)] [ZEROFILL]", "minimum_scale"=>-308, "unsigned_attribute"=>"false", "fixed_prec_scale"=>"false", "local_type_name"=>"DOUBLE", "precision"=>17, "sql_datetime_sub"=>0, "nullable"=>1, "literal_prefix"=>""}], ["DOUBLE", {"num_prec_radix"=>10, "type_name"=>"DOUBLE", "case_sensitive"=>"false", "sql_data_type"=>0, "maximum_scale"=>308, "data_type"=>8, "literal_suffix"=>"", "searchable"=>3, "auto_increment"=>"true", "create_params"=>"[(M,D)] [ZEROFILL]", "minimum_scale"=>-308, "unsigned_attribute"=>"false", "fixed_prec_scale"=>"false", "local_type_name"=>"DOUBLE", "precision"=>17, "sql_datetime_sub"=>0, "nullable"=>1, "literal_prefix"=>""}]] for float

END PASTE=====================================

The widgets table looks like this:

START PASTE=================================================

CREATE TABLE `widgets` (

 `id` int(9) NOT NULL auto_increment,
 `name` varchar(16) NOT NULL,
 `descr` text,
 PRIMARY KEY  (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

END PASTE=================================================

Can anyone help me with this? I am on Windows XP SP2 Rainer

Contents

Rails problems...under what version?

Could you tell us what the versions of Rails and JRuby are? It would probably help if you posted this on the mailing lists; this isn't the quickest way to get a response.

Rails problems...under what version?

JRuby 0.9.1 with Rails 1.1.6 ... your question has prompted me to also check the MySQL.jar version i am using and it is 3.0.9 - this was the cause of my problem. Downloaded the latest (mysql-connector-java-3.1.14-bin.jar) and that fixed it. It's quite possibly an incompatibility between the earlier 3.0.9 connector and MySQL 5, rather than anything to do with JRuby. I will step back to MySQL 4.1, retry with connector 3.0.9 to test that and let you know. Sorry to post here - have only just begun exploring JRuby. Regards Rainer

Oracle 9i: The driver encounter an error: unable to choose type from:

I'm having the same problem with Oracle 9i

The driver encounter an error: unable to choose type from: ...

(ActiveRecord-JDBC 0.2.3) under JRuby 0.9.8

Oracle 9i:

Excatly the same problem with JRuby 0.9.8 and Oracle 9i. Worked like a charm with MySQL, but when I tried to connect with an Oracle instance (via the console for instance), I had that exception when Rails is loading.

Raph.

Oracle 10g:

I encountered something similar with Oracle 10g but it was saying:

START PASTE =======================================================

The driver encounter an error: unable to choose type from: [["INTERVALDS", {"nullable"=>#<BigDecimal:169aa0,'1',1(4)>, "num_prec_radix"=>#<BigDecimal:1b9ea,'10',2(4)>, "local_type_name"=>"INTERVALDS", "fixed_prec_scale"=>#<BigDecimal:54ef33,'0',1(4)>

END PASTE ========================================================

To resolve this I found a bug written 9107 about DECIMAL issue. Here was the fix posted there:

http://rubyforge.org/tracker/index.php?func=detail&aid=9107&group_id=2014&atid=7857

START PASTE =======================================================

Date: 2007-03-12 09:56 Sender: Julien Faissolle

Martin, I think you have the solution here. The connection can be established by replacing in AR_TO_JDBC_TYPES (jdbc_adapter.rb):

       :decimal     => [ lambda {|r| Jdbc::Types::DECIMAL == r['data_type']}, ....

by

       :decimal     => [ lambda {|r| [Jdbc::Types::DECIMAL, Jdbc::Types::NUMERIC].include?(r['data_type'])}, ....

END PASTE ========================================================

you can find the jdbc_adapter.rb under jruby/lib/ruby/gems/1.8/gems/ActiveRecord-JDBC-0.2.3/lib/active_record/connection_adapters/

Expansion on Step 11

a. Create database testapp_development

    1. mysql -uroot -p
    2. enter password
    3. create database testapp_development;
    4. quit

b. Create table widgets using migration

    1. jruby script/generate migration widgets
    2. under db/migrate find new file 001_widgets.rb and modify to look like:
 class Widgets < ActiveRecord::Migration
  def self.up
   create_table :widgets do |table|
     table.column :name, :string
     table.column :description, :string
   end
  end
  def self.down
   drop_table :widgets
  end
 end
   3. rake migrate
Personal tools