Class: PG::BasicTypeMapForResults::WarningTypeMap

Inherits:
TypeMapInRuby show all
Defined in:
lib/pg/basic_type_map_for_results.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.



74
75
76
77
# 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) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# 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