Class: PG::Result

Inherits:
Object
  • Object
show all
Defined in:
ext/pg_result.c,
lib/pg/result.rb

Overview

******************************************************************

The class to represent the query result tuples (rows).
An instance of this class is created as the result of every query.
All result rows and columns are stored in a memory block attached to the PG::Result object.
Whenever a value is accessed it is casted to a Ruby object by the assigned #type_map .

Since pg-1.1 the amount of memory in use by a PG::Result object is estimated and passed to ruby's garbage collector.
You can invoke the #clear method to force deallocation of memory of the instance when finished with the result for better memory performance.

Example:
   require 'pg'
   conn = PG.connect(:dbname => 'test')
   res  = conn.exec('SELECT 1 AS a, 2 AS b, NULL AS c')
   res.getvalue(0,0) # '1'
   res[0]['b']       # '2'
   res[0]['c']       # nil

Instance Method Summary collapse

Instance Method Details

#field_names_as(type) ⇒ Object

Set the data type for all field name returning methods.

type: a Symbol defining the field name type.

This method is equal to #field_name_type= , but returns self, so that calls can be chained.



26
27
28
29
# File 'lib/pg/result.rb', line 26

def field_names_as(type)
	self.field_name_type = type
	return self
end

#inspectObject

Return a String representation of the object suitable for debugging.



32
33
34
35
36
37
38
39
40
# File 'lib/pg/result.rb', line 32

def inspect
	str = self.to_s
	str[-1,0] = if cleared?
		" cleared"
	else
		" status=#{res_status(result_status)} ntuples=#{ntuples} nfields=#{nfields} cmd_tuples=#{cmd_tuples}"
	end
	return str
end

#map_types!(type_map) ⇒ Object

Apply a type map for all value retrieving methods.

type_map: a PG::TypeMap instance.

This method is equal to #type_map= , but returns self, so that calls can be chained.

See also PG::BasicTypeMapForResults



16
17
18
19
# File 'lib/pg/result.rb', line 16

def map_types!(type_map)
	self.type_map = type_map
	return self
end