@@ -159,15 +159,12 @@ def type_cast(value, column, array_member = false)
159159 when Array
160160 case column . sql_type
161161 when 'point'
162- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
163- column_class . point_to_string ( value )
162+ Column . point_to_string ( value )
164163 when 'json'
165- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
166- column_class . json_to_string ( value )
164+ Column . json_to_string ( value )
167165 else
168166 return super ( value , column ) unless column . array?
169- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
170- column_class . array_to_string ( value , column , self )
167+ Column . array_to_string ( value , column , self )
171168 end
172169 when NilClass
173170 if column . array? && array_member
@@ -180,21 +177,17 @@ def type_cast(value, column, array_member = false)
180177 when Hash
181178 case column . sql_type
182179 when 'hstore'
183- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
184- column_class . hstore_to_string ( value )
180+ Column . hstore_to_string ( value )
185181 when 'json'
186- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
187- column_class . json_to_string ( value )
182+ Column . json_to_string ( value )
188183 else super ( value , column )
189184 end
190185 when IPAddr
191186 return super unless column . sql_type == 'inet' || column . sql_type == 'cidr'
192- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
193- column_class . cidr_to_string ( value )
187+ Column . cidr_to_string ( value )
194188 when Range
195189 return super ( value , column ) unless /range$/ =~ column . sql_type
196- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
197- column_class . range_to_string ( value )
190+ Column . range_to_string ( value )
198191 else
199192 super ( value , column )
200193 end
@@ -833,37 +826,30 @@ def quote(value, column = nil)
833826 sql_type && sql_type [ 0 , 3 ] == 'bit' ? quote_bit ( value ) : super
834827 when Array
835828 if AR4_COMPAT && column . array? # will be always falsy in AR < 4.0
836- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
837- "'#{ column_class . array_to_string ( value , column , self ) . gsub ( /'/ , "''" ) } '"
829+ "'#{ Column . array_to_string ( value , column , self ) . gsub ( /'/ , "''" ) } '"
838830 elsif column . type == :json # only in AR-4.0
839- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
840- super ( column_class . json_to_string ( value ) , column )
831+ super ( Column . json_to_string ( value ) , column )
841832 elsif column . type == :point # only in AR-4.0
842- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
843- super ( column_class . point_to_string ( value ) , column )
833+ super ( Column . point_to_string ( value ) , column )
844834 else super
845835 end
846836 when Hash
847837 if column . type == :hstore # only in AR-4.0
848- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
849- super ( column_class . hstore_to_string ( value ) , column )
838+ super ( Column . hstore_to_string ( value ) , column )
850839 elsif column . type == :json # only in AR-4.0
851- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
852- super ( column_class . json_to_string ( value ) , column )
840+ super ( Column . json_to_string ( value ) , column )
853841 else super
854842 end
855843 when Range
856844 sql_type = column . respond_to? ( :sql_type ) && column . sql_type
857845 if sql_type && sql_type [ -5 , 5 ] == 'range' && AR4_COMPAT
858- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
859- escaped = quote_string ( column_class . range_to_string ( value ) )
846+ escaped = quote_string ( Column . range_to_string ( value ) )
860847 "'#{ escaped } '::#{ sql_type } "
861848 else super
862849 end
863850 when IPAddr
864851 if column . type == :inet || column . type == :cidr # only in AR-4.0
865- column_class = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
866- super ( column_class . cidr_to_string ( value ) , column )
852+ super ( Column . cidr_to_string ( value ) , column )
867853 else super
868854 end
869855 else
@@ -913,7 +899,7 @@ def quote_bit(value)
913899
914900 def quote_bit ( value )
915901 "B'#{ value } '"
916- end if PostgreSQL :: AR4_COMPAT
902+ end if AR4_COMPAT
917903
918904 def escape_bytea ( string )
919905 return unless string
@@ -1093,7 +1079,6 @@ def index_name_length
10931079
10941080 # Returns the list of all column definitions for a table.
10951081 def columns ( table_name , name = nil )
1096- klass = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
10971082 pass_cast_type = respond_to? ( :lookup_cast_type )
10981083 column_definitions ( table_name ) . map do |row |
10991084 # name, type, default, notnull, oid, fmod
@@ -1110,9 +1095,9 @@ def columns(table_name, name = nil)
11101095 end
11111096 if pass_cast_type
11121097 cast_type = lookup_cast_type ( type )
1113- klass . new ( name , default , cast_type , type , ! notnull , fmod , self )
1098+ Column . new ( name , default , cast_type , type , ! notnull , fmod , self )
11141099 else
1115- klass . new ( name , default , oid , type , ! notnull , fmod , self )
1100+ Column . new ( name , default , oid , type , ! notnull , fmod , self )
11161101 end
11171102 end
11181103 end
@@ -1520,3 +1505,9 @@ def jdbc_column_class
15201505
15211506 end
15221507end
1508+
1509+ module ArJdbc
1510+ module PostgreSQL
1511+ Column = ::ActiveRecord ::ConnectionAdapters ::PostgreSQLColumn
1512+ end
1513+ end
0 commit comments