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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config

#config, #config_clear, #get_config, #sanitize_config

Methods inherited from Array

#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.



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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rfm/resultset.rb', line 73

def initialize(*args) # xml_response, caller, portals
	#Was (server_obj, xml_response, layout_obj, portals=nil)
	
	options = args.rfm_extract_options!      
  config :parent=>'caller'
  config sanitize_config(options, {}, true)
  
  xml_response			= args[0] || options[:xml_response]
  doc = XmlParser.parse(xml_response, :namespace=>false, :parser=>(state[:parser] rescue nil))
  
  error = doc.error
  check_for_errors(error, (server.state[:raise_on_401] rescue nil))
  
  @doc							= doc
			@caller						= args[1] || options[:caller]
  @layout           = (@caller.class.ancestors.include? Rfm::Layout::LayoutModule) ? @caller : options[:layout_object]
  @database					= (@layout.database rescue nil) || (@caller.class == Rfm::Database ? @caller : options[:database_object])
  @server           = (@database.server rescue nil) || (@caller.class == Rfm::Server ? @caller : options[:server_object])
  @field_meta     ||= Rfm::CaseInsensitiveHash.new
  @portal_meta    ||= Rfm::CaseInsensitiveHash.new
  @include_portals  = args[2] || options[:include_portals]            

  @datasource       = doc.datasource
  meta              = doc.meta
  resultset         = doc.resultset

  @date_format      = doc.date_format
  @time_format      = doc.time_format
  @timestamp_format = doc.timestamp_format

  @foundset_count   = doc.foundset_count
  @total_count      = doc.total_count
  @table            = doc.table
        
  (layout.table = @table) if layout and layout.table_no_load.blank?
  
  parse_fields(doc)
  
  # This will always load portal meta, even if :include_portals was not specified.
  # See Record for control of portal data loading.
  parse_portals(doc)
  
  # These were added for loading resultset from file
  # Kind of a hack. This should ideally condense down to just another option on the main @layout = ...
			#       unless @layout
			#       	@layout = @datasource['layout']
			#       	@layout.instance_variable_set '@database', @datasource['database']
			#       	@layout.instance_eval do
			#       		def database
			#       			@database
			#       		end
			#       	end
			#       end			
  
  return if doc.records.blank?
  Rfm::Record.build_records(doc.records, self, @field_meta, @layout)
end

Instance Attribute Details

#callerObject (readonly)

Returns the value of attribute caller.



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

def caller
  @caller
end

#databaseObject (readonly) Also known as: db

Returns the value of attribute database.



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

def database
  @database
end

#datasourceObject (readonly)

Returns the value of attribute datasource.



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

def datasource
  @datasource
end

#date_formatObject (readonly)

Returns the value of attribute date_format.



43
44
45
# File 'lib/rfm/resultset.rb', line 43

def date_format
  @date_format
end

#docObject (readonly)

Returns the value of attribute doc.



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

def doc
  @doc
end

#field_metaObject (readonly)

Returns the value of attribute field_meta.



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

def field_meta
  @field_meta
end

#foundset_countObject (readonly)

Returns the value of attribute foundset_count.



44
45
46
# File 'lib/rfm/resultset.rb', line 44

def foundset_count
  @foundset_count
end

#include_portalsObject (readonly)

Returns the value of attribute include_portals.



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

def include_portals
  @include_portals
end

#layoutObject (readonly)

Returns the value of attribute layout.



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

def layout
  @layout
end

#portal_metaObject (readonly)

Returns the value of attribute portal_meta.



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

def portal_meta
  @portal_meta
end

#serverObject (readonly)

Returns the value of attribute server.



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

def server
  @server
end

#tableObject (readonly)

Returns the value of attribute table.



44
45
46
# File 'lib/rfm/resultset.rb', line 44

def table
  @table
end

#time_formatObject (readonly)

Returns the value of attribute time_format.



43
44
45
# File 'lib/rfm/resultset.rb', line 43

def time_format
  @time_format
end

#timestamp_formatObject (readonly)

Returns the value of attribute timestamp_format.



43
44
45
# File 'lib/rfm/resultset.rb', line 43

def timestamp_format
  @timestamp_format
end

#total_countObject (readonly)

Returns the value of attribute total_count.



44
45
46
# File 'lib/rfm/resultset.rb', line 44

def total_count
  @total_count
end

Instance Method Details

#field_namesObject



140
141
142
# File 'lib/rfm/resultset.rb', line 140

def field_names
 	field_meta.collect{|k,v| v.name}
end

#portal_namesObject



144
145
146
# File 'lib/rfm/resultset.rb', line 144

def portal_names
	portal_meta.keys
end

#state(*args) ⇒ Object

def self.load_data(file_or_string)

	self.new(file_or_string, nil)
end


136
137
138
# File 'lib/rfm/resultset.rb', line 136

def state(*args)
	get_config(*args)
end