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

(WIP) Upgrade to rails5.2.1 #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
source 'https://rubygems.org'

gemspec

gem 'activerecord', '5.0.1'
gem 'pry', '~> 0.11.1'
1 change: 0 additions & 1 deletion lib/active_record/connection_adapters/odbc_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'active_record'
require 'arel/visitors/bind_visitor'
require 'odbc'
require 'odbc_utf8'

Expand Down
6 changes: 1 addition & 5 deletions lib/odbc_adapter/adapters/mysql_odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ module Adapters
class MySQLODBCAdapter < ActiveRecord::ConnectionAdapters::ODBCAdapter
PRIMARY_KEY = 'INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'.freeze

class BindSubstitution < Arel::Visitors::MySQL
include Arel::Visitors::BindVisitor
end

def arel_visitor
BindSubstitution.new(self)
Arel::Visitors::MySQL.new(self)
end

# Explicitly turning off prepared statements in the MySQL adapter because
Expand Down
5 changes: 1 addition & 4 deletions lib/odbc_adapter/adapters/null_odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ module Adapters
# registry. This allows for minimal support for DBMSs for which we don't
# have an explicit adapter.
class NullODBCAdapter < ActiveRecord::ConnectionAdapters::ODBCAdapter
class BindSubstitution < Arel::Visitors::ToSql
include Arel::Visitors::BindVisitor
end

# Using a BindVisitor so that the SQL string gets substituted before it is
# sent to the DBMS (to attempt to get as much coverage as possible for
# DBMSs we don't support).
def arel_visitor
BindSubstitution.new(self)
Arel::Visitors::PostgreSQL.new(self)
end

# Explicitly turning off prepared_statements in the null adapter because
Expand Down
11 changes: 8 additions & 3 deletions lib/odbc_adapter/database_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module DatabaseStatements
def execute(sql, name = nil, binds = [])
log(sql, name) do
if prepared_statements
@connection.do(sql, *prepared_binds(binds))
@connection.do(prepare_statement_sub(sql), *prepared_binds(binds))
else
@connection.do(sql)
end
Expand All @@ -24,7 +24,7 @@ def exec_query(sql, name = 'SQL', binds = [], prepare: false) # rubocop:disable
log(sql, name) do
stmt =
if prepared_statements
@connection.run(sql, *prepared_binds(binds))
@connection.do(prepare_statement_sub(sql), *prepared_binds(binds))
else
@connection.run(sql)
end
Expand Down Expand Up @@ -127,8 +127,13 @@ def nullability(col_name, is_nullable, nullable)
col_name == 'id' ? false : result
end

# Adapt to Rails 5.2
def prepare_statement_sub(sql)
sql.gsub(/\$\d+/, '?')
end

def prepared_binds(binds)
prepare_binds_for_database(binds).map { |bind| _type_cast(bind) }
binds.map(&:value_for_database).map { |bind| _type_cast(bind) }
end
end
end
2 changes: 1 addition & 1 deletion lib/odbc_adapter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ODBCAdapter
VERSION = '5.0.5'.freeze
VERSION = '5.0.6'.freeze
end
2 changes: 2 additions & 0 deletions odbc_adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'activerecord', '>= 5.2.1'
spec.add_dependency 'ruby-odbc', '~> 0.9'

spec.add_development_dependency 'bundler', '~> 1.14'
spec.add_development_dependency 'minitest', '~> 5.10'
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'rubocop', '0.48.1'
spec.add_development_dependency 'simplecov', '~> 0.14'
spec.add_development_dependency 'pry', '~> 0.11.1'
end