Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with mssql driver, possibly others #35

Open
pareeohnos opened this issue Jul 1, 2014 · 3 comments
Open

Error with mssql driver, possibly others #35

pareeohnos opened this issue Jul 1, 2014 · 3 comments

Comments

@pareeohnos
Copy link

I'm trying to use lol_dba for generating migrations as raw SQL and it is brilliant, but I ran into a problem when testing with SQL server. I'm using jRuby and the source of the active record JDBC driver for SQL server queries the version of the database using select_value.

Tracing the source, this eventually calls select_all which has be redefined by lol_dba to return an array, meaning that the adapter is given an empty array instead of the result from the database, which then causes an exception to be raised.

I've made a minor alteration to a local copy so that the redefinition of select all does a similar test to some of the other implementations so it checks for the type of query. This is my change

connection.class.send(:define_method, :select_all) { |*args| 
  if args.first =~ /SELECT @@version/
    self.orig_select_all(*args)
  else
    []
  end
}

This is very specific to SQL server hence I haven't made a new pull request, but I imagine this may be a problem for other DBMS engines?

@plentz
Copy link
Owner

plentz commented Jul 2, 2014

@pareeohnos Thanks for the report! actually, is the first time I've heard about this kind of problem. But if you want, please, create a PR with this change and also add a commend explaining why this is necessary :)

@pareeohnos
Copy link
Author

It may well be a JDBC specific issue, as the JDBC drivers override various methods that AR normally handles but I couldn't say for sure. I'm not sure if any other database drivers have this issue as we've only really been working with MSSQL and Postgres, but I only ran into the issue with MSSQL

@plentz plentz added the bug label Sep 8, 2014
@plentz plentz added the jruby label Mar 15, 2015
@stonehz
Copy link

stonehz commented Mar 16, 2015

hi,
I had the same problem and found a workaround...
I managed to bypass the issue by adding the sql_version in the database.yml file

development:
  adapter: jdbcmssql
  encoding: utf8
  reconnect: false
  database: db_development
  sqlserver_version: 2008

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants