Skip to content

Commit c344e94

Browse files
Zach Ankerkares
authored andcommitted
Fixed an undefined exception error in type_to_sql for MySQL
1 parent 4534fa2 commit c344e94

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/arjdbc/mysql/adapter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil)
642642
when 0..0xfff; "varbinary(#{limit})"
643643
when nil; "blob"
644644
when 0x1000..0xffffffff; "blob(#{limit})"
645-
else raise(ActiveRecordError, "No binary type has character length #{limit}")
645+
else raise ActiveRecord::ActiveRecordError, "No binary type has character length #{limit}"
646646
end
647647
when 'integer'
648648
case limit
@@ -651,15 +651,15 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil)
651651
when 3; 'mediumint'
652652
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
653653
when 5..8; 'bigint'
654-
else raise(ActiveRecordError, "No integer type has byte size #{limit}")
654+
else raise ActiveRecord::ActiveRecordError, "No integer type has byte size #{limit}"
655655
end
656656
when 'text'
657657
case limit
658658
when 0..0xff; 'tinytext'
659659
when nil, 0x100..0xffff; 'text'
660660
when 0x10000..0xffffff; 'mediumtext'
661661
when 0x1000000..0xffffffff; 'longtext'
662-
else raise(ActiveRecordError, "No text type has character length #{limit}")
662+
else raise ActiveRecord::ActiveRecordError, "No text type has character length #{limit}"
663663
end
664664
else
665665
super

test/db/mysql/types_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ def test_binary_types
99
assert_equal 'blob', type_to_sql(:binary)
1010
end
1111

12+
def test_error_handling
13+
assert_raise ActiveRecord::ActiveRecordError { type_to_sql(:binary, 5_000_000_000) }
14+
assert_raise ActiveRecord::ActiveRecordError { type_to_sql(:integer, 10) }
15+
assert_raise ActiveRecord::ActiveRecordError { type_to_sql(:text, 5_000_000_000) }
16+
end
17+
1218
def type_to_sql(*args)
1319
ActiveRecord::Base.connection.type_to_sql(*args)
1420
end

0 commit comments

Comments
 (0)