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

JSFoundSet

Properties Summarized

Type
Name
Summary

Returns true if this foundset is in multiselect mode and false if it's in single-select mode.

Methods Summarized

Type
Name
Summary

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.

The datasource this foundset is build on

Get the index of a record object inside a foundset

Returns the internal SQL of the JSFoundset.

Returns the internal SQL of the JSFoundset.

Returns the parameters for the internal SQL of the QBSelect.

Returns the parameters for the internal SQL of the QBSelect.

Get the current record index of the foundset.

Get the indexes of the selected records.

Get the size of present cached row identifiers (primary keys)

void

void

Set the current record index.

void

Set the selected records indexes.

void

void

void

Properties Detailed

multiSelect

Returns true if this foundset is in multiselect mode and false if it's in single-select mode.

Type Boolean true if this foundset is in multiselect mode and false if it's in single-select mode.

Methods Detailed

dispose()

Returns: Boolean

duplicateFoundSet()

Returns: JSFoundSet

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

foundset.forEach(function(record,recordIndex,foundset) {
 	//handle the record here
 });

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

foundset.forEach(function(record,recordIndex,foundset) {
 	//handle the record here
 });

getCurrentSort()

Returns: String

getDataSource()

The datasource this foundset is build on

Returns: String the datasource

getName()

Returns: String

getRecordByPk(pk)

Parameters

Returns: JSBaseSQLRecord

getRecordIndex(record)

Get the index of a record object inside a foundset

Parameters

Returns: Number the index or -1 if not present (anymore)

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

var sql = foundset.getSQL(true)

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

var sql = foundset.getSQL(true)

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

var parameters = foundset.getSQLParameters(true)

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

var parameters = foundset.getSQLParameters(true)

getSelectedIndex()

Get the current record index of the foundset.

Returns: Number int current index (1-based)

Sample

//gets the current record index in the current foundset
var current = foundset.getSelectedIndex();
//sets the next record in the foundset
foundset.setSelectedIndex(current+1);

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

// modify selection to the first selected item and the following row only
var current = foundset.getSelectedIndexes();
if (current.length > 1)
{
	var newSelection = new Array();
	newSelection[0] = current[0]; // first current selection
	newSelection[1] = current[0] + 1; // and the next row
	foundset.setSelectedIndexes(newSelection);
}

getSelectedRecords()

Returns: Array

getSize()

Get the size of present cached row identifiers (primary keys)

Returns: Number the number of rows which can be received via getRecord

loadAllRecords()

Returns: Boolean

revertEditedRecords()

Returns: void

save()

Returns: Boolean

setSelectedIndex(index)

Set the current record index.

Parameters

  • Number index index to set (1-based)

Returns: void

Sample

//gets the current record index in the current foundset
var current = foundset.getSelectedIndex();
//sets the next record in the foundset
foundset.setSelectedIndex(current+1);

setSelectedIndexes(indexes)

Set the selected records indexes.

Parameters

  • Array indexes An array with indexes to set.

Returns: void

Sample

// modify selection to the first selected item and the following row only
var current = foundset.getSelectedIndexes();
if (current.length > 1)
{
	var newSelection = new Array();
	newSelection[0] = current[0]; // first current selection
	newSelection[1] = current[0] + 1; // and the next row
	foundset.setSelectedIndexes(newSelection);
}

sort(sortString)

Parameters

Returns: void

sort(sortString, defer)

Parameters

Returns: void

sort(recordComparisonFunction)

Parameters

Returns: void


Last updated