123456789_123456789_123456789_123456789_123456789_

Class: PG::BasicTypeMapForResults::WarningTypeMap

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: PG::TypeMapInRuby
Defined in: lib/pg/basic_type_map_for_results.rb

Class Method Summary

Instance Attribute Summary

::PG::TypeMap::DefaultTypeMappable - Included

#default_type_map

Returns the default ::PG::TypeMap that is currently set for values that could not be casted by this type map.

#default_type_map=

Set the default ::PG::TypeMap that is used for values that could not be casted by this type map.

Instance Method Summary

::PG::TypeMapInRuby - Inherited

#typecast_copy_get

Cast a field string received by Connection#get_copy_data.

#typecast_query_param

Cast a field string for transmission to the server.

#typecast_result_value

Retrieve and cast a field of the given result.

::PG::TypeMap::DefaultTypeMappable - Included

#with_default_type_map

Set the default ::PG::TypeMap that is used for values that could not be casted by this type map.

Constructor Details

.new(typenames) ⇒ WarningTypeMap

[ GitHub ]

  
# File 'lib/pg/basic_type_map_for_results.rb', line 74

def initialize(typenames)
	@already_warned = {}
	@typenames_by_oid = typenames
end

Instance Method Details

#typecast_result_value(result, _tuple, field)

[ GitHub ]

  
# File 'lib/pg/basic_type_map_for_results.rb', line 79

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