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.



295
296
297
298
# File 'lib/pg/basic_type_mapping.rb', line 295

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



300
301
302
303
304
305
306
307
308
# File 'lib/pg/basic_type_mapping.rb', line 300

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