Skip to main content

executeQuery()

Last updated 11/09/2024

Example One

The following code selects all employee names from the Employee table.

JavaScript
executeQuery() using SQL
let queryResults = five.executeQuery(`SELECT Name FROM Employee`);

Example Two

The following code uses an existing query in Five referenced by it's data source ID.

JavaScript
executeQuery() using an existing query
let queryResults = five.executeQuery(`EmployeesQueryDataSourceID`);

Example Three

The following code selects five employee records from the Employee table and displays them in the Five Inspector.

JavaScript
executeQuery() using the optional limit parameter
let queryResult = five.executeQuery('SELECT Name from Employee', 5);
for (let i = 0; i < queryResult.recordCount(); i++) {
five.log('Employee : ' + queryResult.records[i].Name);
}

Example Four

The following code selects all employee records with a post code of 4066. The

limit
parameter is no longer optional when using variable arguments.

JavaScript
executeQuery() using 0 with the limit parameter and variable arguments
const postCode = '4066';
let queryResults = five.executeQuery(`SELECT Name FROM Employee WHERE Employee.PostCode = ?`, 0, postCode);

Example Five

The following code selects the first five employee names that reside in the postcode 4066 using the optional

limit
parameter and
variable
arguments.

JavaScript
executeQuery() with the optional limit parameter and variable arguments
const postCode = '4066';
let queryResults = five.executeQuery(`SELECT Name FROM Employee WHERE Employee.PostCode = ?`, 5, postCode);

Example Six

The following code uses a new transaction in Five and executes the query against the transaction.

JavaScript
executeQuery() using a new transaction and query
const tx = five.startTransaction(db);
let queryResults = five.executeQuery(tx, `SELECT Name FROM Employee`);