Note that there are some explanatory texts on larger screens.

plurals
  1. POLIMIT clause in MSSQL RoR ActiveRecord Query
    primarykey
    data
    text
    <p>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:</p> <p><strong>ODBC::Error: 37000 (102) [unixODBC][FreeTDS][SQL Server]Incorrect syntax near 'LIMIT'.: SELECT [club].* FROM [club] WHERE ([club].[ClubID] = N'137') LIMIT 1</strong></p> <p><em>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).</em></p> <p>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.</p> <p>Here is the setup:</p> <p><strong>Gems:</strong> gem 'mysql2' gem 'rails-dbi' gem 'ruby-odbc' gem 'activerecord-sqlserver-adapter'</p> <p><strong>Models (examples):</strong></p> <pre><code>class Club &lt; External ... end class External &lt; ActiveRecord:Base establish_connection('mssql_' + Rails.env) ... end class OtherModel &lt; ActiveRecord:Base ... end </code></pre> <p><strong>database.yml Example:</strong></p> <pre><code>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: </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload