Object. ResultSet objects are used to access the results of a database action. These objects can not be created manually, but must be retrieved through the LassoSession object to which the set belongs. A ResultSet object can only be used after its LassoSession object has been executed.
The ResultSet object has the following properties:
Property |
Description |
---|---|
Column Name Properties | Properties which allow access to the ResultSet's database data. |
The ResultSet object has the following methods:
Method |
Description |
---|---|
close | Closes the ResultSet so that the database data is no longer accessible. |
columns | Returns the number of columns in the ResultSet. |
next | Advances the row marker to the next row is possible. |
columnName | Returns the name of the specified column. |
columnType | Returns the data type for the specified column. |
columnProtection | Returns the protection for the specified column. |
listValues | Returns the value list associated with a particular column. |
repeats | Returns true if the specified column is repeating. |
related | Returns true if the specified column is a related column. |
foundCount | Returns the number of records found as a result of the database activity. |
shownCount | Returns the number of records whose data is available as a result of the database activity. |
Properties. After a session has executed, the session's ResultSet has zero or more properties defined to allow access to the database data. These properties are named after the columns themselves, so they will vary depending on the database which was accessed.
This example gets the ResultSet from the default session and prints out the column data for the current row. The database has the following columns defined: Field1, Field2, Field3 and Field4.
var mySet = lasso.defaultSession.getResultSet(); if ( mySet.next() ) // move us to the first row { write( "Field1: ", mySet.Field1, "<BR>" ); write( "Field2: ", mySet.Field2, "<BR>" ); write( "Field3: ", mySet.Field3, "<BR>" ); write( "Field4: ", mySet.Field4, "<BR>" ); }
If a column name has characters which are illegal in JavaScript property names (such as a related column containing "::"), the column's data can be accessed using the subscript operator with the quoted column name passed as the index.
This example gets the ResultSet from the default session and prints out the column data for the current row. The database has the following columns defined: Relation::Field1, Relation::Field2, Relation::Field3 and Relation::Field4.
var mySet = lasso.defaultSession.getResultSet(); if ( mySet.next() ) // move us to the first row { write( "Relation::Field1: ", mySet[ "Relation::Field1" ], "<BR>" ); write( "Relation::Field2: ", mySet[ "Relation::Field2" ], "<BR>" ); write( "Relation::Field3: ", mySet[ "Relation::Field3" ], "<BR>" ); write( "Relation::Field4: ", mySet[ "Relation::Field4" ], "<BR>" );
}
Method. This method closes the ResultSet so that the database data is no longer available.
close()
None.
Nothing.
This method closes the ResultSet so that the database data is no longer available. It also enables the ResultSet's LassoSession object to be executed again. close must be called before a session can be re-executed.
This example checks to see if the default session has been executed. If it has, it closes the session's ResultSet and re-executes the session.
if ( lasso.defaultSession.hasExecuted() ) { var mySet = lasso.defaultSession.getResultSet(); mySet.close();
} lasso.defaultSession.execute();
Method. This method returns the number of columns (fields) available in the ResultSet.
columns()
None.
The number of available columns.
Method. This method advances to the next row (record) if possible.
next()
None.
False if the current row is the last row and true if the ResultSet was advanced to the next row.
This method is used to iterate through the rows in the result set. Initially, the ResultSet row marker is positioned before the first row. Next must be called at least once before any database data can be accessed.
This example iterates through all the rows in the ResultSet and outputs the number of rows.
var mySet = lasso.defaultSession.getResultSet(); var count = 0; while ( mySet.next() ) ++count; write( "There are ", count, " rows in the set." );
Method. This method returns the name of the specified column (field).
columnName( columnIndex )
columnIndex is the zero based index of the column.
The name of the column if the specified index is valid.
This method is used to determine the name of a column based on its index.
This example will output the name of every column in the ResultSet.
var mySet = lasso.defaultSession.getResultSet(); for ( var x = 0; x < mySet.columns(); ++x ) { write( "Column ", x + 1, ": ", mySet.columnName( x ), "<BR>" );
}
Method. This method returns the data type of the specified column (field).
columnType( columnIndex )
columnType( columnName )
columnIndex is the zero based index of the column.
columnName is the name of the column.
A string containing the data type of the column if the specified index is valid. The returned string will contain one of the following values:
text
image
boolean
date/time
number
unknown
This method is used to determine the data type of a column based on its index.
This example will output the data type of every column in the ResultSet.
var mySet = lasso.defaultSession.getResultSet(); for ( var x = 0; x < mySet.columns(); ++x ) { write( "Column ", x + 1, ": ", mySet.columnType( x ), "<BR>" );
}
Method. This method returns the protection type of the specified column (field).
columnProtection( columnIndex )
columnProtection( columnName )
columnIndex is the zero based index of the column.
columnName is the name of the column.
A string containing the protection type of the column if the specified index is valid. The returned string will contain one of the following values:
none
read only
This method is used to determine the protection type of a column based on its index.
This example will output the protection type of every column in the ResultSet.
var mySet = lasso.defaultSession.getResultSet(); for ( var x = 0; x < mySet.columns(); ++x ) { write( "Column ", x + 1, ": ", mySet.columnProtection( x ), "<BR>" );
}
Method. This method returns value list associated with a column (field).
listValues( columnIndex )
listValues( columnName )
columnIndex is the zero based index of the column.
columnName is the name of the column
An array of possible values for the column.
This method is a FileMaker specific extension to the ResultSet object and can be ignored when using other datasources. It provides access to the value list associated with a column. If the column does not have a value list, the list returned by this method will be empty.
If a column does have a value list and has multiple values in the field data, the data for the column will be an array of values.
Method. This method is used to determine if a column (field) is repeating.
repeats( columnIndex )
repeats( columnName )
columnIndex is the zero based index of the column.
columnName is the name of the column.
True if the column is repeating, false, otherwise.
This method is a FileMaker specific extension to the ResultSet object and can be ignored when using other datasources. It is used to determine if a column has repeating values.
If a column does have repeating values and there are multiple values in the field data, the data for the column will be an array of values.
Method. This method is used to determine if a column is a related column (field).
related( columnIndex )
related( columnName )
columnIndex is the zero based index of the column.
columnName is the name of the column.
True is the column is related, otherwise, false.
This method is a FileMaker specific extension to the ResultSet object and can be ignored when using other datasources. It is used to determine if a column is related.
If a column is related and has multiple related values, the data for the column will be returns as an array of values.
Method. This method is used to determine the number of database records which were found when the session was executed.
foundCount()
None.
The number of records that were found.
This function can be used to determine how many records were found as the result of a search. The number of found records is not necessarily the number of records whose data is available (the number of shown records).
This example will output the number of records found as a result of the previous database activity.
var mySet = lasso.defaultSession.getResultSet(); write( "The number of found records is: ", mySet.foundCount() );
Method. This method is used to determine the number of database records whose data is available in the current ResultSet object.
shownCount()
None.
The number of records that are available.
This function can be used to determine how many records are available in the current ResultSet object. This number will be equal to the number of times the ResultSet object's next
function can be called.
This example will output the number of records that are available in the result set.
var mySet = lasso.defaultSession.getResultSet(); write( "The number of records available is: ", mySet.shownCount() );