Class: Rfm::Result::ResultSet

Inherits:
Array
  • Object
show all
Defined in:
lib/rfm_result.rb

Overview

The ResultSet object represents a set of records in FileMaker. It is, in every way, a real Ruby Array, so everything you expect to be able to do with an Array can be done with a ResultSet as well. In this case, the elements in the array are Record objects.

Here’s a typical example, displaying the results of a Find:

myServer = Rfm::Server.new(...)
results = myServer["Customers"]["Details"].find("First Name" => "Bill")
results.each {|record|
  puts record["First Name"]
  puts record["Last Name"]
  puts record["Email Address"]
}

Attributes

The ResultSet object has several useful attributes:

  • server is the server object this ResultSet came from

  • fields is a hash with field names for keys and Field objects for values; it provides metadata about the fields in the ResultSet

  • portals is a hash with table occurrence names for keys and arrays of Field objects for values; it provides metadata about the portals in the ResultSet and the Fields on those portals

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, fmresultset, layout = nil) ⇒ ResultSet

Initializes a new ResultSet object. You will probably never do this your self (instead, use the Layout object to get various ResultSet obejects).

If you feel so inclined, though, pass a Server object, and some fmpxmlresult compliant XML in a String.

Attributes

The ResultSet object includes several useful attributes:

  • fields is a hash (with field names for keys and Field objects for values). It includes an entry for every field in the ResultSet. Note: You don’t use Field objects to access data. If you’re after data, get a Record object (ResultSet is an array of records). Field objects tell you about the fields (their type, repetitions, and so forth) in case you find that information useful programmatically.

    Note: keys in the fields hash are downcased for convenience (and [] automatically downcases on lookup, so it should be seamless). But if you each a field hash and need to know a field’s real name, with correct case, do myField.name instead of relying on the key in the hash.

  • portals is a hash (with table occurrence names for keys and Field objects for values). If your layout contains portals, you can find out what fields they contain here. Again, if it’s the data you’re after, you want to look at the Record object.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rfm_result.rb', line 62

def initialize(server, fmresultset, layout = nil)
  @server = server
  @resultset = nil
  @layout = layout
  @fields = Rfm::Util::CaseInsensitiveHash.new
  @portals = Rfm::Util::CaseInsensitiveHash.new
  @date_format = nil
  @time_format = nil
  @timestamp_format = nil
  
  doc = REXML::Document.new(fmresultset)
  root = doc.root
  
  # check for errors
  error = root.elements['error'].attributes['code'].to_i
  if error != 0 && (error != 401 || @server.state[:raise_on_401])
    raise Rfm::Error::FileMakerError.getError(error) 
  end
  
  # ascertain date and time formats
  datasource = root.elements['datasource']
  @date_format = convertFormatString(datasource.attributes['date-format'])
  @time_format = convertFormatString(datasource.attributes['time-format'])
  @timestamp_format = convertFormatString(datasource.attributes['timestamp-format'])
  
  # process field metadata
  root.elements['metadata'].each_element('field-definition') { |field|
    name = field.attributes['name']
    @fields[name] = Field.new(self, field)
  }
  @fields.freeze
  
  # process relatedset metadata
  root.elements['metadata'].each_element('relatedset-definition') { |relatedset|
    table = relatedset.attributes['table']
    fields = {}
    relatedset.each_element('field-definition') { |field|
      name = field.attributes['name'].sub(Regexp.new(table + '::'), '')
      fields[name] = Field.new(self, field)
    }
    @portals[table] = fields
  }
  @portals.freeze
  
  # build rows
  root.elements['resultset'].each_element('record') { |record|
    self << Record.new(record, self, @fields, @layout)
  }
end

Instance Attribute Details

#date_formatObject (readonly)

Returns the value of attribute date_format.



112
113
114
# File 'lib/rfm_result.rb', line 112

def date_format
  @date_format
end

#fieldsObject (readonly)

Returns the value of attribute fields.



112
113
114
# File 'lib/rfm_result.rb', line 112

def fields
  @fields
end

#layoutObject (readonly)

Returns the value of attribute layout.



112
113
114
# File 'lib/rfm_result.rb', line 112

def layout
  @layout
end

#portalsObject (readonly)

Returns the value of attribute portals.



112
113
114
# File 'lib/rfm_result.rb', line 112

def portals
  @portals
end

#serverObject (readonly)

Returns the value of attribute server.



112
113
114
# File 'lib/rfm_result.rb', line 112

def server
  @server
end

#time_formatObject (readonly)

Returns the value of attribute time_format.



112
113
114
# File 'lib/rfm_result.rb', line 112

def time_format
  @time_format
end

#timestamp_formatObject (readonly)

Returns the value of attribute timestamp_format.



112
113
114
# File 'lib/rfm_result.rb', line 112

def timestamp_format
  @timestamp_format
end