@@ -632,78 +632,76 @@ def database_version # :nodoc:
632
632
def check_version # :nodoc:
633
633
end
634
634
635
- private
636
- def type_map
637
- @type_map ||= Type ::TypeMap . new . tap do |mapping |
638
- initialize_type_map ( mapping )
635
+ class << self
636
+ private
637
+ def initialize_type_map ( m )
638
+ register_class_with_limit m , %r(boolean)i , Type ::Boolean
639
+ register_class_with_limit m , %r(char)i , Type ::String
640
+ register_class_with_limit m , %r(binary)i , Type ::Binary
641
+ register_class_with_limit m , %r(text)i , Type ::Text
642
+ register_class_with_precision m , %r(date)i , Type ::Date
643
+ register_class_with_precision m , %r(time)i , Type ::Time
644
+ register_class_with_precision m , %r(datetime)i , Type ::DateTime
645
+ register_class_with_limit m , %r(float)i , Type ::Float
646
+ register_class_with_limit m , %r(int)i , Type ::Integer
647
+
648
+ m . alias_type %r(blob)i , "binary"
649
+ m . alias_type %r(clob)i , "text"
650
+ m . alias_type %r(timestamp)i , "datetime"
651
+ m . alias_type %r(numeric)i , "decimal"
652
+ m . alias_type %r(number)i , "decimal"
653
+ m . alias_type %r(double)i , "float"
654
+
655
+ m . register_type %r(^json)i , Type ::Json . new
656
+
657
+ m . register_type ( %r(decimal)i ) do |sql_type |
658
+ scale = extract_scale ( sql_type )
659
+ precision = extract_precision ( sql_type )
660
+
661
+ if scale == 0
662
+ # FIXME: Remove this class as well
663
+ Type ::DecimalWithoutScale . new ( precision : precision )
664
+ else
665
+ Type ::Decimal . new ( precision : precision , scale : scale )
666
+ end
667
+ end
639
668
end
640
- end
641
669
642
- def initialize_type_map ( m = type_map )
643
- register_class_with_limit m , %r(boolean)i , Type ::Boolean
644
- register_class_with_limit m , %r(char)i , Type ::String
645
- register_class_with_limit m , %r(binary)i , Type ::Binary
646
- register_class_with_limit m , %r(text)i , Type ::Text
647
- register_class_with_precision m , %r(date)i , Type ::Date
648
- register_class_with_precision m , %r(time)i , Type ::Time
649
- register_class_with_precision m , %r(datetime)i , Type ::DateTime
650
- register_class_with_limit m , %r(float)i , Type ::Float
651
- register_class_with_limit m , %r(int)i , Type ::Integer
652
-
653
- m . alias_type %r(blob)i , "binary"
654
- m . alias_type %r(clob)i , "text"
655
- m . alias_type %r(timestamp)i , "datetime"
656
- m . alias_type %r(numeric)i , "decimal"
657
- m . alias_type %r(number)i , "decimal"
658
- m . alias_type %r(double)i , "float"
659
-
660
- m . register_type %r(^json)i , Type ::Json . new
661
-
662
- m . register_type ( %r(decimal)i ) do |sql_type |
663
- scale = extract_scale ( sql_type )
664
- precision = extract_precision ( sql_type )
665
-
666
- if scale == 0
667
- # FIXME: Remove this class as well
668
- Type ::DecimalWithoutScale . new ( precision : precision )
669
- else
670
- Type ::Decimal . new ( precision : precision , scale : scale )
670
+ def register_class_with_limit ( mapping , key , klass )
671
+ mapping . register_type ( key ) do |*args |
672
+ limit = extract_limit ( args . last )
673
+ klass . new ( limit : limit )
671
674
end
672
675
end
673
- end
674
676
675
- def reload_type_map
676
- type_map . clear
677
- initialize_type_map
678
- end
677
+ def register_class_with_precision ( mapping , key , klass )
678
+ mapping . register_type ( key ) do |*args |
679
+ precision = extract_precision ( args . last )
680
+ klass . new ( precision : precision )
681
+ end
682
+ end
679
683
680
- def register_class_with_limit ( mapping , key , klass )
681
- mapping . register_type ( key ) do |*args |
682
- limit = extract_limit ( args . last )
683
- klass . new ( limit : limit )
684
+ def extract_scale ( sql_type )
685
+ case sql_type
686
+ when /\( (\d +)\) / then 0
687
+ when /\( (\d +)(,(\d +))\) / then $3. to_i
688
+ end
684
689
end
685
- end
686
690
687
- def register_class_with_precision ( mapping , key , klass )
688
- mapping . register_type ( key ) do |*args |
689
- precision = extract_precision ( args . last )
690
- klass . new ( precision : precision )
691
+ def extract_precision ( sql_type )
692
+ $1. to_i if sql_type =~ /\( (\d +)(,\d +)?\) /
691
693
end
692
- end
693
694
694
- def extract_scale ( sql_type )
695
- case sql_type
696
- when /\( (\d +)\) / then 0
697
- when /\( (\d +)(,(\d +))\) / then $3. to_i
695
+ def extract_limit ( sql_type )
696
+ $1. to_i if sql_type =~ /\( (.*)\) /
698
697
end
699
- end
698
+ end
700
699
701
- def extract_precision ( sql_type )
702
- $1. to_i if sql_type =~ /\( (\d +)(,\d +)?\) /
703
- end
700
+ TYPE_MAP = Type ::TypeMap . new . tap { |m | initialize_type_map ( m ) }
704
701
705
- def extract_limit ( sql_type )
706
- $1. to_i if sql_type =~ /\( (.*)\) /
702
+ private
703
+ def type_map
704
+ TYPE_MAP
707
705
end
708
706
709
707
def translate_exception_class ( e , sql , binds )
0 commit comments