JSBaseSQLFoundset
Overview
JSBaseSQLFoundSet
is the foundational class for SQL-based foundsets, including JSFoundSet
and ViewFoundSet
. It provides functionality to handle SQL-driven data operations within Servoy environments. This class extends JSFoundSet
, enabling inheritance of its capabilities and adding specific methods for SQL-based operations.
Features
The JSBaseSQLFoundSet
supports multiselect mode, allowing multiple records to be selected simultaneously, making it suitable for batch operations. It includes mechanisms to iterate over records using the forEach
method, which dynamically loads records while accounting for concurrent inserts and deletes, ensuring data consistency during operations.
Developers can retrieve the internal SQL used by the foundset through the getSQL
method, along with parameters via getSQLParameters
. Options are available to include or exclude table filters from the returned SQL and parameters. Additional capabilities include sorting records with sort
, duplicating the foundset using duplicateFoundSet
, saving changes with save
, and reverting unsaved edits using revertEditedRecords
.
Extends
Properties Summarized
Methods Summarized
Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time.
Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time.
Properties Detailed
multiSelect
Type Boolean true if the foundset is in multi-select mode; false otherwise.
Methods Detailed
dispose()
Returns: Boolean true if the foundset was successfully disposed; false otherwise.
duplicateFoundSet()
Returns: JSFoundSet a new instance of the duplicated foundset.
forEach(callback)
Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time. It will dynamically load all records in the foundset (using Servoy lazy loading mechanism). If callback function returns a non null value the traversal will be stopped and that value is returned. If no value is returned all records of the foundset will be traversed. Foundset modifications( like sort, omit...) cannot be performed in the callback function. If foundset is modified an exception will be thrown. This exception will also happen if a refresh happens because of a rollback call for records on this datasource when iterating. When an exception is thrown from the callback function, the iteration over the foundset will be stopped.
Parameters
Function callback The callback function to be called for each loaded record in the foundset. Can receive three parameters: the record to be processed, the index of the record in the foundset, and the foundset that is traversed.
Returns: Object Object the return value of the callback
Sample
forEach(callback, thisObject)
Iterates over the records of a foundset taking into account inserts and deletes that may happen at the same time. It will dynamically load all records in the foundset (using Servoy lazy loading mechanism). If callback function returns a non null value the traversal will be stopped and that value is returned. If no value is returned all records of the foundset will be traversed. Foundset modifications( like sort, omit...) cannot be performed in the callback function. If foundset is modified an exception will be thrown. This exception will also happen if a refresh happens because of a rollback call for records on this datasource when iterating. When an exception is thrown from the callback function, the iteration over the foundset will be stopped.
Parameters
Function callback The callback function to be called for each loaded record in the foundset. Can receive three parameters: the record to be processed, the index of the record in the foundset, and the foundset that is traversed.
Object thisObject What the this object should be in the callback function (default it is the foundset)
Returns: Object Object the return value of the callback
Sample
getCurrentSort()
Returns: String the current sort order as a string.
getDataSource()
Returns: String the data source of the foundset as a string.
getName()
Returns: String the name of the foundset.
getRecordByPk(pk)
Parameters
Array pk ;
Returns: JSBaseSQLRecord The record corresponding to the given primary key(s), or null if no matching record is found.
getRecordIndex(record)
Parameters
JSRecord record ;
Returns: Number the 0-based index of the given record in the foundset.
getSQL()
Returns the internal SQL of the JSFoundset. Optionally, the foundset and table filter params can be excluded in the sql (includeFilters=false).
Returns: String String representing the sql of the JSFoundset.
Sample
getSQL(includeFilters)
Returns the internal SQL of the JSFoundset. Optionally, the foundset and table filter params can be excluded in the sql (includeFilters=false).
Parameters
Boolean includeFilters include the foundset and table filters [default true].
Returns: String String representing the sql of the JSFoundset.
Sample
getSQLParameters()
Returns the parameters for the internal SQL of the QBSelect. Table filters are on by default.
Returns: Array An Array with the sql parameter values.
Sample
getSQLParameters(includeFilters)
Returns the parameters for the internal SQL of the QBSelect. Table filters are on by default.
Parameters
Boolean includeFilters include the foundset and table filters [default true].
Returns: Array An Array with the sql parameter values.
Sample
getSelectedIndex()
Get the current record index of the foundset.
Returns: Number int current index (1-based)
Sample
getSelectedIndexes()
Get the indexes of the selected records. When the foundset is in multiSelect mode (see property multiSelect), a selection can consist of more than one index.
Returns: Array Array current indexes (1-based)
Sample
getSelectedRecords()
Returns: Array an array of currently selected records in the foundset.
getSize()
Returns: Number the number of records in the foundset.
loadAllRecords()
Returns: Boolean true if all records are successfully loaded; false otherwise.
revertEditedRecords()
Returns: void
save()
Returns: Boolean true if the changes are successfully saved; false otherwise.
setSelectedIndex(index)
Set the current record index.
Parameters
Number index index to set (1-based)
Returns: void
Sample
setSelectedIndexes(indexes)
Set the selected records indexes.
Parameters
Array indexes An array with indexes to set.
Returns: void
Sample
sort(sortString)
Parameters
String sortString ;
Returns: void
sort(sortString, defer)
Parameters
Returns: void
sort(recordComparisonFunction)
Parameters
Function recordComparisonFunction ;
Returns: void
Last updated
Was this helpful?