Class: PG::BasicTypeMapForResults::WarningTypeMap

Inherits:
TypeMapInRuby show all
Defined in:
lib/pg/basic_type_mapping.rb

Instance Method Summary collapse

Methods inherited from TypeMapInRuby

#typecast_copy_get, #typecast_query_param

Methods included from TypeMap::DefaultTypeMappable

#default_type_map, #default_type_map=, #with_default_type_map

Constructor Details

#initialize(typenames) ⇒ WarningTypeMap

Returns a new instance of WarningTypeMap.



245
246
247
248
# File 'lib/pg/basic_type_mapping.rb', line 245

def initialize(typenames)
  @already_warned = Hash.new{|h, k| h[k] = {} }
  @typenames_by_oid = typenames
end

Instance Method Details

#typecast_result_value(result, _tuple, field) ⇒ Object



250
251
252
253
254
255
256
257
258
# File 'lib/pg/basic_type_mapping.rb', line 250

def typecast_result_value(result, _tuple, field)
  format = result.fformat(field)
  oid = result.ftype(field)
  unless @already_warned[format][oid]
    STDERR.puts "Warning: no type cast defined for type #{@typenames_by_oid[format][oid].inspect} with oid #{oid}. Please cast this type explicitly to TEXT to be safe for future changes."
     @already_warned[format][oid] = true
  end
  super
end