Class: Lore::Result

Inherits:
Object show all
Defined in:
lib/lore/adapters/postgres/result.rb,
lib/lore/adapters/postgres-pr/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, result) ⇒ Result

expects PostgresPR::Result



11
12
13
14
15
16
17
18
19
# File 'lib/lore/adapters/postgres/result.rb', line 11

def initialize(query, result) 
  @result = result
  @field_types      = nil
  @result_rows      = Array.new
  @num_fields       = @result.num_fields
  @num_tuples       = @result.num_tuples
  @field_counter    = 0
  @field_names      = @result.fields
end

Instance Attribute Details

#field_namesObject (readonly) Also known as: get_field_names

Returns the value of attribute field_names.



8
9
10
# File 'lib/lore/adapters/postgres/result.rb', line 8

def field_names
  @field_names
end

#query_hashvalObject (readonly)

Returns the value of attribute query_hashval.



8
9
10
# File 'lib/lore/adapters/postgres/result.rb', line 8

def query_hashval
  @query_hashval
end

Instance Method Details

#fieldname(index) ⇒ Object



76
77
78
# File 'lib/lore/adapters/postgres/result.rb', line 76

def fieldname(index)
  return @result.fieldname(index)
end

#get_field_numObject



40
41
42
# File 'lib/lore/adapters/postgres/result.rb', line 40

def get_field_num()
  @num_fields
end

#get_field_typesObject Also known as: field_types

def get_field_value



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lore/adapters/postgres/result.rb', line 26

def get_field_types()
  
  return @field_types unless @field_types.nil?
  
  @field_types = Hash.new
  for field_index in 0...get_field_num()
    @field_types[@result.fields[field_index]] = @result.type(field_index)
  end
  
  return @field_types
end

#get_field_value(row_index, field_name) ⇒ Object

def initialize



21
22
23
24
# File 'lib/lore/adapters/postgres/result.rb', line 21

def get_field_value(row_index, field_name)
  field_index = @result.fieldnum(field_name)
  return @result.getvalue(row_index, field_index)
end

#get_row(row_num = 0) ⇒ Object



48
49
50
# File 'lib/lore/adapters/postgres/result.rb', line 48

def get_row(row_num=0)
  @result[row_num]
end

#get_row_with_field_names(row_num = 0) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/lore/adapters/postgres/result.rb', line 51

def get_row_with_field_names(row_num=0)

  return if @result.num_tuples == 0

  row_result = Array.new
  
  @field_counter = 0
  for @field_counter in 0...@num_fields do
    row_result << @result.getvalue(row_num, @field_counter)
  end
  @fieldnames = []
  for @field_counter in 0...@num_fields do
    @fieldnames << @result.fieldname(@field_counter)
  end
  return { :values => row_result, :fields => @fieldnames }
end

#get_rowsObject



68
69
70
71
72
73
74
# File 'lib/lore/adapters/postgres/result.rb', line 68

def get_rows()
  rows = []
  for tuple_count in 0...@result.num_tuples do
    rows << @result[tuple_count]
  end
  return rows
end

#get_tuple_numObject



44
45
46
# File 'lib/lore/adapters/postgres/result.rb', line 44

def get_tuple_num()
  @num_tuples
end