Error 'uninitialized constant Arel::Visitors::SQLite' with rails

The problems started when I updated a working Rails project to Netbeans
7.4. I have installed all the gems I thought I needed, and the result is
this error when trying to create a database.

uninitialized constant Arel::Visitors::SQLite

The error is here:
…/activerecord-jdbc-adapter-1.3.10/lib/arjdbc/sqlite3/adapter.rb:104:in
`SQLite3’

Relevant versions are:

JRuby 1.7.0
Rails 2.3.8
activerecord-jdbcsqlite3-adaptor 1.3.10.

A bit of searching told me that “Arel::Visitors::VISITORS is deprecated
and will be removed”, and this is likely to be somewhere around this
version of Rails. It didn’t tell me what to do about it.

I suspect a dependency/version problem, but I have no idea what.

So you’re mixing rails 2.3.8 (more than 4 years old) with the latest
release of a jdbcsqlite3 adaptor (few days old only) and you hope to
succeed? On top of this, you’re using an almost 2 years old version of
jruby…

If you wish to succeed, and I guess some legacy is involved here (old
rails), please use at least a version of the jdbcsqlite3 adaptor that
may
have been tested back then on jruby in 2010.

I would suggest using
https://rubygems.org/gems/activerecord-jdbcsqlite3-adapter/versions/1.0.3-java
and maybe also downgrade to jruby 1.6.8.

Good luck!

If you like to put it that way. I all actually did was upgrade Netbeans
to 7.4 a while back and then more recently tried to get this old project
working. The JRuby is what came with Netbeans. The jdbc was just the
default gem.

Unless there is a compelling reason, I would prefer to move forward than
backward. Is it likely that (say) Rails 3.x would work? I’d rather fix
problems moving the project forwards than this kind of wrestling with
outdated incompatible versions.

I cannot foretell if rails 3 will work or not. Your code will need a lot
of
rework. Maybe the application is small and you can cope with the
upgrade.

But it is usually a good idea to freeze your gems to a specific version
in
time to ensure stability.

I stopped using rails 2 years ago. It was not a good match for my apps
and
i preferred sequel to activerecord, and sinatra to rails.

Maybe the breakage is in the database adaptor rather than in the rails
version. Rails 2 did not know about bundler so your project does not
have a
Gemfile, right?

What does happen if you replace sqlite by h2? H2 is a java database,
usable
in embedded or network mode. Please google for an adaptor.

I’ll try to build a small test case later today to debug this as well.

Good luck.

Hi,

experiment over: I insist that my 1st answer was the best possible way
forward without changing all your architecture or your software stack…

Demonstration:

1/ install jruby-1.7.0 & install the gems in mode 1.9 (a requirement
from
latest activerecord-jdbcsqlite3-adapter)

  • jruby -S jgem ins rails -v 2.3.8
  • jruby -S jgem ins activerecord-jdbcsqlite3-adapter -v 1.3.10
    => note this will install the following 3 gems, actually from rails
    4.x
    (please note Arel…)
    Fetching: activesupport-4.1.5.gem (100%)
    Fetching: activemodel-4.1.5.gem (100%)
    Fetching: arel-5.0.1.20140414130214.gem (100%)

2/ create a rails 2.3.x app with 1 model and run the db migration

  • jruby -S rails todoapp
  • cd todoapp (change sqlite3 adapter to jdbcsqlite3 in
    config/database.yml)
  • jruby script/generate model Task title:string note:text
    completed:date
  • jruby -S rake db:migrate
    => uninitialized constant Arel::Visitors::SQLite

Suggested fix: install an older version of
activerecord-jdbcsqlite3-adapter
(I suggested 1.0.3)

1/ install jruby-1.7.0 & install the gems in mode 1.9 (not a requirement
anymore but to ensure consistency)

  • jruby -S jgem ins rails -v 2.3.8
  • jruby -S jgem ins activerecord-jdbcsqlite3-adapter -v 1.0.3

2/ create a rails 2.3.x app with 1 model and run the db migration

  • jruby -S rails todoapp
  • cd todoapp (change sqlite3 adapter to jdbcsqlite3 in
    config/database.yml)
  • jruby script/generate model Task title:string note:text
    completed:date
  • jruby -S rake db:migrate
    == CreateTasks: migrating
    ====================================================
    – create_table(:tasks)
    -> 0.0220s
    -> 0 rows
    == CreateTasks: migrated (0.0240s)
    ===========================================

So there you’ve a fix: good luck again with your project

:wink:

On Mon, Sep 8, 2014 at 6:53 AM, Christian MICHON
<[email protected]

Thought I pop in … Christian has given some great advise but there’s a
few “misleading” ones as well - let me explain :

Latest activerecord-jdbcxxx gems 1.3.x (although new) work with Rails
2.3
… I would actually highly recommend using 1.3, if there are issues
downgrade to 1.2.
That being said, you should not expect them to work with every Rails
2.3.x
version that was out there … but somehow the “latest” one(s).

Without Bundler you will need to “cleanup” your gems - esp. make sure
there’s no Rails gems of any other versions than the desired 2.3.x
(activesupport, activerecord etc.)

Than install the AR-JDBC gems with --ignore-dependendies (it depends on
activerecord >= 2.2 but that simply causes rubygems to fetch the latest
activerecord gem) :

gem ins activerecord-jdbc-adapter activerecord-jdbcsqlite3-adapter

–ignore-dependencies

One more thing is JRuby … there’s been some AR-JDBC related issues
along
the 1.7.x line - so again do not expect all to work with 1.7.0 but it
sure
will just fine with latest.
Do not forget to force JRuby 1.7 it into --1.8 mode if needed (since it
defaults to --1.9 since 1.7) … on the other hand I also expect JRuby
1.6.8 to work as well just fine.

One thing that limits you very much is that you seem to be “stucked” on
what NetBeans provides … unfortunately the RoR plugins have not been
catching up.
It’s usable (I’m actually using it but only the editor - no related Ruby
tooling) but it will certainly be tricky to find out the correct
versions
on JRuby/Rails that work.

Hope some of that is useful, CHEERS!

On Mon, Sep 8, 2014 at 8:43 AM, Christian MICHON
<[email protected]

Thanks for the helpful hints. I haven’t been able to get 1.3.x working.
I really don’t have much control over gems versions, working with
Netbeans. What do people use these days, if it’s not Netbeans?

I tried H2 and that installed fine and seemed to work, but it created
the database file and then came up with an entirely different error:
‘database file already exists’.

I’m starting to suspect there is more than one problem here. In
particular, I’m reasonably sure I started this project at rails 2.1.2 or
thereabouts, and that is long gone, perhaps the problem is my code.

So I’m going to try to get a ‘pure’ new rails project working and import
my code into it, rather than the other way around.

Anyway, thanks for the help.

After preliminary experimentation, rails 3 is off the table. I wrote
this code about 5 years ago when Rails 2.3 was the latest and greatest,
and the main reason to run it now is to move it somewhere else. I’m not
a big rails fan, but I do like ruby as a language.

I would really prefer to keep Netbeans 7.4 and the Jruby that came with
it. I’m using them for other (non-rails) projects.

After your previous helpful message I came to the conclusion that the
jdbc adapter was the place to focus.

To be honest, I don’t care what database. It was originally MySql but
that’s really too heavyweight. I use sqlite for other things so it’s
familiar, but H2 is OK too. Or Mssql. Whatever.

I tried to set a version for the jdbc gem. No, I don’t have bundler and
I don’t have a gemfile. What I have is

Rails::Initializer.run do |config|

So I loaded the gem and tried

config.gem “activerecord-jdbcsqlite3-adapter”, :version => ‘1.0.3’

Which produced the error:

NoMethodError: undefined method name' for "actionmailer":String C:/Users/david/AppData/Roaming/NetBeans/7.4/jruby/lib/ruby/gems/shared/gems/rails-2.3.8/lib/rails/gem_dependency.rb:275:in==’

Not obvious how the two are connected, but I guess that’s what the
debugger is for.

Your experiment (a) reproduce the problem and (b) suggested this is the
right fix. I have a few things to try now at least. Thanks for the help.

On Tue, Sep 9, 2014 at 2:58 AM, David B. [email protected]
wrote:

I really don’t have much control over gems versions, working with
Netbeans.

Mmm. Don’t know about the Netbeans part, but if you have this app
actually running somewhere you should be able to determine the
exact versions of all the relevant gems and build a Gemfile with that
information.

That would at least enable you to make sure your tests run (or add
tests) prior to upgrading to a supported version.

So I’m going to try to get a ‘pure’ new rails project working and import
my code into it, rather than the other way around.

If you’re going from 2.3.x to 3.2.x or 4.x then yes, that’s going to be
a much better approach. Not necessarily pain-free, but still easier
in my experience.

Good luck.

Hassan S. ------------------------ [email protected]

twitter: @hassan

Well, I for one never used Netbeans…

Moving away from SQlite towards H2, especially in jruby, is a smart
move.
See how booleans are actually handled in SQlite internals, you’ll be
scared…

Yet it takes time to wrap one’s head around the embedded/network
settings
of H2. If you need more help, you can contact me outside of the mailing
list.