Skip to content

Commit bb70a25

Browse files
committed
[mysql] more tuning/compatibility backports for AR 4.2 (working boolean emulation)
de-ja-vu fixes boolean type columns #626 (were not working when emulation changed at runtime due missing type map reload on cache clear)
1 parent 0b0e7af commit bb70a25

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

lib/arjdbc/mysql/adapter.rb

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,16 @@ def quote(value, column = nil)
202202
else
203203
super
204204
end
205-
end
205+
end unless AR42
206+
207+
# @private since AR 4.2
208+
def _quote(value)
209+
if value.is_a?(Type::Binary::Data)
210+
"x'#{value.hex}'"
211+
else
212+
super
213+
end
214+
end if AR42
206215

207216
# @override
208217
def quote_column_name(name)
@@ -254,6 +263,10 @@ def supports_rename_index?
254263
(version[0] == 5 && version[1] >= 7) || version[0] >= 6
255264
end
256265

266+
def index_algorithms
267+
{ :default => 'ALGORITHM = DEFAULT', :copy => 'ALGORITHM = COPY', :inplace => 'ALGORITHM = INPLACE' }
268+
end if AR42
269+
257270
# @override
258271
def supports_transaction_isolation?(level = nil)
259272
version[0] && version[0] >= 5 # MySQL 5+
@@ -376,7 +389,7 @@ def indexes(table_name, name = nil)
376389
# Returns an array of `Column` objects for the table specified.
377390
# @override
378391
def columns(table_name, name = nil)
379-
sql = "SHOW FULL COLUMNS FROM #{quote_table_name(table_name)}"
392+
sql = "SHOW FULL #{AR40 ? 'FIELDS' : 'COLUMNS'} FROM #{quote_table_name(table_name)}"
380393
columns = execute(sql, name || 'SCHEMA')
381394
strict = strict_mode?
382395
pass_cast_type = respond_to?(:lookup_cast_type)
@@ -683,6 +696,18 @@ def valid_type?(type)
683696
! native_database_types[type].nil?
684697
end
685698

699+
def clear_cache!
700+
super
701+
reload_type_map
702+
end if AR42
703+
704+
# @private since AR 4.2
705+
def prepare_column_options(column, types)
706+
spec = super
707+
spec.delete(:limit) if column.type == :boolean
708+
spec
709+
end if AR42
710+
686711
# @private
687712
Type = ActiveRecord::Type if AR42
688713

@@ -817,6 +842,7 @@ def full_version
817842

818843
# @private
819844
def emulate_booleans; ::ArJdbc::MySQL.emulate_booleans?; end # due AR 4.2
845+
public :emulate_booleans
820846

821847
# @private
822848
class MysqlDateTime < Type::DateTime
@@ -879,9 +905,9 @@ def adapter
879905

880906
end
881907

882-
def initialize(*args)
883-
super # configure_connection happens in super
884-
end
908+
#def initialize(*args)
909+
# super # configure_connection happens in super
910+
#end
885911

886912
def jdbc_connection_class(spec)
887913
::ArJdbc::MySQL.jdbc_connection_class

test/db/mysql/simple_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def test_time_usec_formatting_when_saved_into_string_column
5050
column_quote_char "`"
5151

5252
def test_column_class_instantiation
53-
text_column = nil
5453
assert_nothing_raised do
55-
assert text_column = mysql_adapter_class::Column.new("title", nil, "text")
54+
text_column = mysql_adapter_class::Column.new("title", nil, "text")
55+
assert text_column.is_a?(ActiveRecord::ConnectionAdapters::Column)
5656
end unless ar_version('4.2')
5757
end
5858

0 commit comments

Comments
 (0)