We are having an issue with a Ruby on Rails 3.0.3 application. It seems that for some reason, ActiveRecord is using a query formatted for MySQL when we do a find() on an MSSQL model. The rails app is using MySQL for its models; however, also has reference models that are backed within an MSSQL database. As shown in the below message, we are using an ODBC connection. When I call Club.find(137) I get the following error:
ODBC::Error: 37000 (102) [unixODBC][FreeTDS][SQL Server]Incorrect syntax near 'LIMIT'.: SELECT [club].* FROM [club] WHERE ([club].[ClubI开发者_运维知识库D] = N'137') LIMIT 1
Note that Club.find(:all) works fine so connectivity is working, the problem lies in the generation of the SQL query format. OtherModel.find(1) also works (the model that is connected to the MySQL database).
Is what I'm doing impossible? I'm assuming its something with the caching of queries... Does anyone know how to resolve the above? Thanks so much for all the help in advance.
Here is the setup:
Gems: gem 'mysql2' gem 'rails-dbi' gem 'ruby-odbc' gem 'activerecord-sqlserver-adapter'
Models (examples):
class Club < External
...
end
class External < ActiveRecord:Base
establish_connection('mssql_' + Rails.env)
...
end
class OtherModel < ActiveRecord:Base
...
end
database.yml Example:
environment:
adapter: mysql2
encoding: utf8
host: localhost
pool: 5
username:
password:
database: my_app_development
mssql_environment:
adapter: sqlserver
mode: odbc
pool: 5
dsn: MYDSN
username:
password:
I am the author for the adapter and some things we have in the Arel visitor for SQL Server has to extend the visitors for limit/offset. I think this was a bug we have fixed in the latest versions so those working with the SQL Server adapter in a multi-db environment have a better experience.
精彩评论