-
Notifications
You must be signed in to change notification settings - Fork 558
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
Use fully qualified database name when retrieving column definitions … #426
Use fully qualified database name when retrieving column definitions … #426
Conversation
…to support linked servers.
Use fully qualified database name when retrieving column definitions …
Brilliant side step solution for 2008 and Rails 4.2 and up! I just merged this in and published v4.2.6 of the adapter. Cheers! |
@jippeholwerda Also... may I introduce you to my favorite minitest/rails gem :) https://github.com/metaskills/minitest-spec-rails |
Sorry for intruding, but I've got a question for @jippeholwerda - I had assumed that linked servers were passed SQL verbatim. Unfortunately I'm not in a position where I can test this until the end of the week and I'm dying to know the answer 😅 Are you saying that with a small 2012 (or newer instance) with a linked 2008 R2 server, I can issue FETCH and OFFSET queries (for example), and they're appropriately translated for 2008 R2? |
That was my assumption too. I'd like to hear the answer @jippeholwerda |
@theangryangel That is correct. The 2012 engine correctly translates the FETCH and OFFSET queries so that 2008 understands. |
Shit. I wish I'd actually tried that rather than assumed it wouldn't. Would've saved me a bunch of trouble 😆 Cheers for the update @jippeholwerda I appreciate it ❤️ |
However, when testing I did run into an issue with INSERT statements. Apparently, specifying the Arel table alias adds it to the INSERT as well, resulting in a syntax error. Will have to dive further into that. |
Great stuff. And out-of-the box solution! |
* Rename `remote_server?` to `database_prefix_remote_server?` * Make `database_prefix_remote_server?` stronger by checking if #object is left blank. Misc refactors. * Remove `@config` init ivar. Not used. * Use `connection_options` helper in tests for terse win. cc @jippeholwerda
…to support linked servers.
We have to retrieve data from SQL Server 2008. Since that doesn't work with the latest activerecord-sqlserver-adapter and we do have the possibility of using a SQL Server 2012 instance, we've configured the 2012 database engine to be able to execute queries/commands against the 2008 instance. This can be achieved by adding the 2008 server as a "linked server" in the 2012 instance.
However, querying a linked server requires using the fully qualified database name:
In the current master, using a linked server fails with the following error:
TinyTds::Error: Invalid object name 'database.INFORMATION_SCHEMA.COLUMNS'
when retrieving the table definition of a linked server.
This pull request should fix that by using the fully qualified database name.
An example of a model that uses a linked server is: