Class: Rfm::Resultset

Inherits:
Array show all
Includes:
Config
Defined in:
lib/rfm/resultset.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 these attributes:

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

  • portal_meta 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

Constant Summary

Constants included from Config

Config::CONFIG_DONT_STORE, Config::CONFIG_KEYS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config

#config_clear, #get_config, #log, #state

Methods inherited from Array

#_merge_object!, #rfm_extend_member, #rfm_extend_members, #rfm_extract_options!

Constructor Details

#initialize(*args) ⇒ 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.



79
80
81
82
# File 'lib/rfm/resultset.rb', line 79

def initialize(*args) # parent, layout
			config *args
			self.meta
end

Instance Attribute Details

#calling_objectObject (readonly)

Returns the value of attribute calling_object.



41
42
43
# File 'lib/rfm/resultset.rb', line 41

def calling_object
  @calling_object
end

#layoutObject (readonly)

This method was added for situations where a layout was not provided at resultset instantiation, such as when loading a resultset from an xml file.



95
96
97
# File 'lib/rfm/resultset.rb', line 95

def layout
  @layout
end

#metaObject (readonly)

Returns the value of attribute meta.



41
42
43
# File 'lib/rfm/resultset.rb', line 41

def meta
  @meta
end

Class Method Details

.load_data(data, object = self.new) ⇒ Object



52
53
54
55
# File 'lib/rfm/resultset.rb', line 52

def load_data(data, object=self.new)
	Rfm::Connection
	Rfm::SaxParser.parse(data, :fmresultset, object)
end

Instance Method Details

#config(*args) ⇒ Object

initialize



84
85
86
87
88
89
90
91
# File 'lib/rfm/resultset.rb', line 84

def config(*args)
	super do |params|
		(@layout = params[:objects][0]) if params &&
			params[:objects] &&
			params[:objects][0] &&
			params[:objects][0].is_a?(Rfm::Layout)
	end
end

#databaseObject Also known as: db



99
100
101
# File 'lib/rfm/resultset.rb', line 99

def database
	layout.database
end

#end_datasource_element_callback(cursor) ⇒ Object



121
122
123
124
# File 'lib/rfm/resultset.rb', line 121

def end_datasource_element_callback(cursor)
	%w(date_format time_format timestamp_format).each{|f| convert_date_time_format(send(f))}
	@meta.attach_layout_object_from_cursor(cursor)
end

#handle_new_record(attributes) ⇒ Object

Deprecated on 7/29/2014. Stop using.



115
116
117
118
119
# File 'lib/rfm/resultset.rb', line 115

def handle_new_record(attributes)
	r = Rfm::Record.new(self, attributes, {})
	self << r
	r
end

#serverObject



105
106
107
# File 'lib/rfm/resultset.rb', line 105

def server
	database.server
end