Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,49 @@ language: ruby
cache: bundler
matrix:
include:
- rvm: 2.3.1
- rvm: 2.3.6
env:
- DB=mysql
- CONN_STR='DRIVER=MySQL;SERVER=localhost;DATABASE=odbc_test;USER=root;PASSWORD=;'
addons:
mysql: "5.5"
apt:
packages:
- unixodbc
- unixodbc-dev
- libmyodbc
- mysql-client
- rvm: 2.3.1
- mysql-client-5.6
services:
- mysql
- rvm: 2.3.6
env:
- DB=postgresql
- CONN_STR='DRIVER={PostgreSQL ANSI};SERVER=localhost;PORT=5432;DATABASE=odbc_test;UID=postgres;'
addons:
postgresql: "9.1"
postgresql: "9.2"
apt:
packages:
- unixodbc
- unixodbc-dev
- odbc-postgresql
- rvm: 2.4.3
env:
- DB=mysql
- CONN_STR='DRIVER=MySQL;SERVER=localhost;DATABASE=odbc_test;USER=root;PASSWORD=;'
addons:
apt:
packages:
- unixodbc
- unixodbc-dev
- libmyodbc
- mysql-client-5.6
services:
- mysql
- rvm: 2.4.3
env:
- DB=postgresql
- CONN_STR='DRIVER={PostgreSQL ANSI};SERVER=localhost;PORT=5432;DATABASE=odbc_test;UID=postgres;'
addons:
postgresql: "9.2"
apt:
packages:
- unixodbc
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Or install it yourself as:

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
After checking out the repo, run `bin/setup` to install dependencies. Next, configure your system with a PostgreSQL data source called `ODBCAdapterPostgreSQLTest` (you can alternatively set the environment variables `CONN_STR` or `DSN`). Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

Expand Down
11 changes: 6 additions & 5 deletions lib/active_record/connection_adapters/odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def odbc_connection(config) # :nodoc:
end

dbms = ::ODBCAdapter::DBMS.new(connection)
dbms.adapter_class.new(connection, logger, dbms)
dbms.adapter_class.new(connection, logger, dbms, options)
end

private
Expand Down Expand Up @@ -79,10 +79,11 @@ class ODBCAdapter < AbstractAdapter

attr_reader :dbms

def initialize(connection, logger, dbms)
def initialize(connection, logger, dbms, options)
super(connection, logger)
@connection = connection
@dbms = dbms
@options = options
@visitor = self.class::BindSubstitution.new(self)
end

Expand Down Expand Up @@ -112,10 +113,10 @@ def active?
def reconnect!
disconnect!
@connection =
if options.key?(:dsn)
ODBC.connect(options[:dsn], options[:username], options[:password])
if @options.key?(:dsn)
ODBC.connect(@options[:dsn], @options[:username], @options[:password])
else
ODBC::Database.new.drvconnect(options[:driver])
ODBC::Database.new.drvconnect(@options[:driver])
end
super
end
Expand Down
44 changes: 44 additions & 0 deletions test/connections_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'test_helper'

# Dummy class for this test
class ConnectionsTestDummyActiveRecordModel < ActiveRecord::Base
self.abstract_class = true
end

# This test makes sure that all of the connection methods work properly
class ConnectionsTest < Minitest::Test
def setup
@options = { adapter: 'odbc' }
@options[:conn_str] = ENV['CONN_STR'] if ENV['CONN_STR']
@options[:dsn] = ENV['DSN'] if ENV['DSN']
@options[:dsn] = 'ODBCAdapterPostgreSQLTest' if @options.values_at(:conn_str, :dsn).compact.empty?

ConnectionsTestDummyActiveRecordModel.establish_connection @options

@connection = ConnectionsTestDummyActiveRecordModel.connection
end

def teardown
@connection.disconnect!
end

def test_active?
assert_equal @connection.raw_connection.connected?, @connection.active?
end

def test_disconnect!
@raw_connection = @connection.raw_connection

assert_equal true, @raw_connection.connected?
@connection.disconnect!
assert_equal false, @raw_connection.connected?
end

def test_reconnect!
@old_raw_connection = @connection.raw_connection
assert_equal true, @connection.active?
@connection.reconnect!
refute_equal @old_raw_connection, @connection.raw_connection
assert_equal true, @connection.active?
end
end