Activerecord-jdbcmssql-adapter seems to be broken

Either the activerecord-jdbc driver for MS SQL Server is broken, or I’m
not using it correctly. When trying to use it, it appears that a MySQL
dialect is being used, resulting in errors. For example the find(id)
method for models is generating a query with “LIMIT 1” in it, which is
not valid for MS SQL.

I’m using:

jruby-1.5.5
rails-3.0.2
activerecord-jdbc-adapter-1.0.2

Here’s an example of the error:

Current database.yml

development:
adapter: mssql
database: rails_dev
host: development_server
username: dbuser
password: dbpassword

Current Gemfile

source ‘http://rubygems.org

gem ‘rails’, ‘3.0.2’
gem ‘activerecord-jdbcmssql-adapter’

Sample test run

$ rails console
Loading development environment (Rails 3.0.2)

jruby-1.5.5 > user = User.new
=> #<User id: nil, name: nil, created_at: nil, updated_at: nil>

jruby-1.5.5 > user.name = “Some Guy”
=> “Some Guy”

jruby-1.5.5 > user.save
=> true

jruby-1.5.5 > users = User.all
=> [#<User id: 2, name: “Some Guy”, created_at: “2010-11-15 23:56:16”,
updated_at: “2010-11-15 23:56:16”>]

jruby-1.5.5 > some_guy = User.find(2)
ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: Incorrect
syntax near ‘LIMIT’.: SELECT users.* FROM users WHERE (users.[id] = 2)
LIMIT 1
from
gems/activerecord-3.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:202:in
log' from gems/activerecord-jdbc-adapter-1.0.2-java/lib/arjdbc/mssql/adapter.rb:435:in select’
from
gems/activerecord-3.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in
select_all' from gems/activerecord-3.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in select_all’
from gems/activerecord-3.0.2/lib/active_record/base.rb:467:in
find_by_sql' from gems/jruby-1.5.5/gems/activerecord-3.0.2/lib/active_record/relation.rb:64:in to_a’
from
gems/jruby-1.5.5/gems/activerecord-3.0.2/lib/active_record/relation/finder_methods.rb:333:in
find_first' from gems/jruby-1.5.5/gems/activerecord-3.0.2/lib/active_record/relation/finder_methods.rb:122:in first’
from
gems/jruby-1.5.5/gems/activerecord-3.0.2/lib/active_record/relation/finder_methods.rb:291:in
find_one' from gems/activerecord-3.0.2/lib/active_record/relation/finder_methods.rb:281:in find_with_ids’
from
gems/jruby-1.5.5/gems/activerecord-3.0.2/lib/active_record/relation/finder_methods.rb:107:in
find' from gems/jruby-1.5.5/gems/activerecord-3.0.2/lib/active_record/base.rb:439:in find’
from (irb):5

Should it not be using an SQL dialect that works with SQL Server?

I believe you need to install activerecord-jdbcmssql-adapter and
prefix the adapter name with jdbc so that it reads jdbcmssql.
Additionally, you can specify only jdbc and include a driver attribute
to database.yml:

http://kenai.com/projects/jruby/pages/ActiveRecord-JDBC


Hector

On Mon, Nov 15, 2010 at 6:32 PM, Simon T. [email protected] wrote:

activerecord-jdbc-adapter-1.0.2

Should it not be using an SQL dialect that works with SQL Server?

Indeed it should. As far as I can tell from the environment you’ve
described, this could be a regression. I’ll install the latest Rails
3.0.2 and see if I can reproduce this error.

/Nick

Hector Castro wrote in post #961723:

I believe you need to install activerecord-jdbcmssql-adapter and
prefix the adapter name with jdbc so that it reads jdbcmssql.
Additionally, you can specify only jdbc and include a driver attribute
to database.yml:

http://kenai.com/projects/jruby/pages/ActiveRecord-JDBC


Hector

Thanks, but playing around with the database.yml config has had no
effect. I’ve tried both the ‘jdbc’ and ‘jdbcmssql’ adapter configs, as
well as explicitly specifying the JDBC driver to use and the JDBC URL,
and I get the exact same results ever time. I’ve even tried both the
Microsoft JDBC driver and the open source JTDS driver.

For example, this file produces the exact same error:

development:
adapter: jdbcmssql
driver: net.sourceforge.jtds.jdbc.Driver
url: jdbc:jtds:sqlserver://development_server;databaseName=rails_dev
username: dbuser
password: dbpassword

Simon

Concur. Looking at what’s needed to get SQL server running with ARel 2
right now, hopefully a release will follow soon.

/Nick

It looks like this problem is due to the move to ARel 2.0 as of Rails
3.0.2. Reverting back to rails 3.0.1 fixes the issue until the SQL
Server adapter is updated for the new arel changes.

Here’s more info on the changes:

http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/

Nick,

I had a quick play with this.

Didn’t see you on IRC or I would have asked more questions. I’ll raise
it
with tenderlove to see if he is happy / wants to take it further.

Cheers,

James