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.



266
267
268
269
# File 'lib/pg/basic_type_mapping.rb', line 266

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



271
272
273
274
275
276
277
278
279
# File 'lib/pg/basic_type_mapping.rb', line 271

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