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?