@@ -1114,9 +1114,8 @@ def index_name_length
11141114 # Returns the list of all column definitions for a table.
11151115 def columns ( table_name , name = nil )
11161116 column = jdbc_column_class
1117- pass_cast_type = respond_to? ( :lookup_cast_type )
1118- column_definitions ( table_name ) . map do |row |
1119- # name, type, default, notnull, oid, fmod
1117+ column_definitions ( table_name ) . map! do |row |
1118+ # |name, type, default, notnull, oid, fmod|
11201119 name = row [ 0 ] ; type = row [ 1 ] ; default = row [ 2 ]
11211120 notnull = row [ 3 ] ; oid = row [ 4 ] ; fmod = row [ 5 ]
11221121 # oid = OID::TYPE_MAP.fetch(oid.to_i, fmod.to_i) { OID::Identity.new }
@@ -1128,18 +1127,41 @@ def columns(table_name, name = nil)
11281127 elsif default =~ /^\( ([-+]?[\d \. ]+)\) $/ # e.g. "(-1)" for a negative default
11291128 default = $1
11301129 end
1131- if pass_cast_type
1132- cast_type = lookup_cast_type ( type )
1133- column . new ( name , default , cast_type , type , ! notnull , fmod , self )
1134- else
1135- column . new ( name , default , oid , type , ! notnull , fmod , self )
1136- end
1130+
1131+ column . new ( name , default , oid , type , ! notnull , fmod , self )
11371132 end
11381133 end
11391134
1135+ # @private documented above
1136+ def columns ( table_name )
1137+ column = jdbc_column_class
1138+ # Limit, precision, and scale are all handled by the superclass.
1139+ column_definitions ( table_name ) . map! do |row |
1140+ # |name, type, default, notnull, oid, fmod|
1141+ name = row [ 0 ] ; type = row [ 1 ] ; default = row [ 2 ]
1142+ notnull = row [ 3 ] ; oid = row [ 4 ] ; fmod = row [ 5 ]
1143+ notnull = notnull == 't' if notnull . is_a? ( String ) # JDBC gets true/false
1144+
1145+ oid_type = get_oid_type ( oid . to_i , fmod . to_i , name , type )
1146+ default_value = extract_value_from_default ( oid , default )
1147+ default_function = extract_default_function ( default_value , default )
1148+
1149+ column . new ( name , default_value , oid_type , type , ! notnull , default_function , oid , self )
1150+ end
1151+ end if AR42_COMPAT
1152+
1153+ # @private only for API compatibility
1154+ def new_column ( name , default , cast_type , sql_type = nil , null = true , default_function = nil )
1155+ jdbc_column_class . new ( name , default , cast_type , sql_type , null , default_function )
1156+ end if AR42_COMPAT
1157+
11401158 # @private
11411159 def column_for ( table_name , column_name )
1142- columns ( table_name ) . detect { |c | c . name == column_name . to_s }
1160+ column_name = column_name . to_s
1161+ for column in columns ( table_name )
1162+ return column if column . name == column_name
1163+ end
1164+ nil
11431165 end
11441166
11451167 # Returns the list of a table's column names, data types, and default values.
0 commit comments