activerecord-jdbc-adapter
activerecord-jdbc-adapter copied to clipboard
Issue with generated query when using non-default schema (!= dbo) on mssql
I'm having this issue when doing even a simple query like User.first on my development environment.
If I create my table with a custom schema:
class CreatePartyPartners < ActiveRecord::Migration
def change
execute <<-SQL
CREATE SCHEMA Party
SQL
create_table('Party.Partners', primary_key: 'Id') do |t|
...
And create a model by manually set self.table_name
class Party::Partner < ActiveRecord::Base
self.table_name = 'Party.Partners'
self.primary_key = 'Id'
...
Firing up the rails console and type Party::Partner.first will result in an error like this:
jruby-1.7.12 :012 > Party::Partner.first
ActiveRecord::JDBCError: table: Party].[Partners does not exist
from arjdbc/jdbc/RubyJdbcConnection.java:1098:in `columns'
This is the generated query of Party::Partner.limit(1)
SELECT t.* FROM ( SELECT ROW_NUMBER() OVER(ORDER BY Partners.Id) AS _row_num, [Party].[Partners].* FROM [Party].[Partners] ) AS t WHERE t._row_num BETWEEN 1 AND 1
If I remove the square brackets from FROM [Party].[Partners] like this FROM Party.Partners: the query will work normally
I'm using JRuby 1.7.12, Rails 4.1.0, activerecord-jdbcmssql-adapter 1.3.7 and sql server 2008 r2
you can support MS-SQL fixes at BountySource
@giosakti thanks for the report(s) ... we'll pretty low on maintainers thus would recommend looking into this on your own. try setting up the tests against a test DB to get you started.
Ok, thanks for the heads up :)