sqlanywhere / activerecord-sqlanywhere-adapter

An adapter that allows ActiveRecord to communicate with SQL Anywhere
http://sqlanywhere.rubyforge.org/
Other
7 stars 25 forks source link

ActiveRecord 3.1 support #2

Open bjorntrondsen opened 12 years ago

bjorntrondsen commented 12 years ago

Hi Eric

It doesn't look like the adapter works in Rails 3.1. When I try to fetch all records from a table through ActiveRecord, I get this error when calling "MyModel.all":

wrong number of arguments (3 for 2)
activerecord-sqlanywhere-adapter (1.0.0) lib/active_record/connection_adapters/sqlanywhere_adapter.rb:437:in `select'
activerecord (3.1.1.rc2) lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
activerecord (3.1.1.rc2) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `block in select_all'
activerecord (3.1.1.rc2) lib/active_record/connection_adapters/abstract/query_cache.rb:75:in `cache_sql'
activerecord (3.1.1.rc2) lib/active_record/connection_adapters/abstract/query_cache.rb:61:in `select_all'
activerecord (3.1.1.rc2) lib/active_record/base.rb:470:in `find_by_sql'
activerecord (3.1.1.rc2) lib/active_record/relation.rb:111:in `to_a'
activerecord (3.1.1.rc2) lib/active_record/relation/finder_methods.rb:159:in `all'
activerecord (3.1.1.rc2) lib/active_record/base.rb:441:in `all'

I have tested against ActiveRecord v3.0.10 and the same code runs fine there

bjorntrondsen commented 12 years ago

There are problems with compatability against Rails 3.0.10 too. For intance MyModel.find(params[:id]) yields this error:

ActiveRecord::StatementInvalid (ActiveRecord::ConnectionAdapters::SQLAnywhereException: Syntax error near '<' on line 1: SELECT TOP #<Arel::Nodes::Limit:0x00000008291d70> "my_table".* FROM "my_table" WHERE (my_id = '4'))

There seem to be a general incompatibility with Arel. Statements like .first, .last and .find yields the error above.

springbok commented 12 years ago

I can confirm this problem in 3.0.10 and have an open issue on the SQLA support forum:

http://sqlanywhere-forum.sybase.com/questions/7372/errors-with-rails-3010-ruby-192

I've just been too busy to put together a small test app.

bjorntrondsen commented 12 years ago

I have a fork that fixes .find, .first and .last in Rails 3.0.10. I'm looking into fixing the Rails 3.1 related issues.

springbok commented 12 years ago

Well done, I'll definitely give it a go.

bjorntrondsen commented 12 years ago

Eric, are there any plans to look into this from you guys are Sybase? I have some "emergency fixes" for 3.1 on my branch, but I am not confident about putting them into production.

brandonburke commented 12 years ago

Did anyone ever get this working for rails 3.1?

springbok commented 12 years ago

I've not tried it yet, we are planning on moving from 3.0.7 to 3.2 in the near future so I'm hoping it will be fixed by then. Eric did say he would look at updating it to work but I've not heard anything for some time.

bjorntrondsen commented 12 years ago

It's a while since I've fiddled with it, but I believe I had a "read only" version working on my rails31 branch. Inserts where broken. I wouldn't recommend anybody use that branch for anything important though, as it was just some experimental work.

KevinGreen commented 12 years ago

For anyone who's still looking for a solution I've made a "fork" re-write based on active record 3.1.1. Everything seems to be working but it's still experimental. Let me know if you find something that isn't right. There's a compiled gem in my fork.

Source here

bjorntrondsen commented 12 years ago

Awesome, I will definitely give your fork a spin in the near future and let you know if I run into any issues

glennfu commented 8 years ago

For anyone still looking for a working fork for Rails 3 or Rails 4.0/4.1, from all of my tests, this works great: https://github.com/jgrevzie/activerecord-sqlanywhere-adapter/tree/rails40

Note the "rails40" branch and "rails31" and "rails32" branches.

Only thing missing now is beyond that, Arel 6.0.0 which comes with Rails 4.2 will involve some major structural changes.