Skip to content

Commit

Permalink
Merge pull request #3 from jbender/rails-5-2
Browse files Browse the repository at this point in the history
Rails 5.2 support
  • Loading branch information
nickelser authored Feb 20, 2019
2 parents 34cd3e8 + e563ec8 commit c85aab1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/active_record/connection_adapters/odbc_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'active_record'
require 'arel/visitors/bind_visitor'
# BindVisitor was removed in Arel 9 aka Rails 5.2
require 'arel/visitors/bind_visitor' if Arel::VERSION.to_i < 9
require 'odbc'

require 'odbc_adapter/database_limits'
Expand Down Expand Up @@ -173,7 +174,7 @@ def translate_exception(exception, message)
error_number = exception.message[/^\d+/].to_i

if error_number == ERR_DUPLICATE_KEY_VALUE
ActiveRecord::RecordNotUnique.new(message, exception)
ActiveRecord::RecordNotUnique.new(message)
elsif error_number == ERR_QUERY_TIMED_OUT || exception.message =~ ERR_QUERY_TIMED_OUT_MESSAGE
::ODBCAdapter::QueryTimeoutError.new(message)
else
Expand Down
3 changes: 2 additions & 1 deletion lib/odbc_adapter/adapters/mysql_odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ 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
# BindVisitor was removed in Arel 9 aka Rails 5.2
include Arel::Visitors::BindVisitor if Arel::VERSION.to_i < 9
end

def arel_visitor
Expand Down
3 changes: 2 additions & 1 deletion lib/odbc_adapter/adapters/null_odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Adapters
# have an explicit adapter.
class NullODBCAdapter < ActiveRecord::ConnectionAdapters::ODBCAdapter
class BindSubstitution < Arel::Visitors::ToSql
include Arel::Visitors::BindVisitor
# BindVisitor was removed in Arel 9, or Rails 5.2
include Arel::Visitors::BindVisitor if Arel::VERSION.to_i < 9
end

# Using a BindVisitor so that the SQL string gets substituted before it is
Expand Down
2 changes: 1 addition & 1 deletion lib/odbc_adapter/database_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def nullability(col_name, is_nullable, nullable)
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

0 comments on commit c85aab1

Please sign in to comment.