Public Member Functions |
| Number | at () |
| void | bind (Mixed aValue) |
| | Bind a value to a SQL parameter.
|
|
void | clear () |
| | Clears the result set and releases any local or database ressources held by the query.
|
| void | execute (Mixed aSqlOrParams=Null) |
| | Execute a query.
|
| Boolean | first () |
| | Retrieves the first record in the result, if available, and positions the query on the retrieved record.
|
| Boolean | isActive () |
| Boolean | isNull (Number aField) |
| | Check if a value within the current cursor row is NULL.
|
| Boolean | isSelect () |
| Boolean | isValid () |
| Boolean | last () |
| | Retrieves the last record in the result, if available, and positions the query on the retrieved record.
|
| Boolean | next () |
| | Retrieves the next record in the result, if available, and positions the query on the retrieved record.
|
| Number | numRowsAffected () |
| void | prepare (String aSql) |
| | Prepare a SQL statement.
|
| Boolean | previous () |
| | Retrieves the previous record in the result, if available, and positions the query on the retrieved record.
|
| | Query (Datastore aDatastore) |
| | Constructor for a new Query.
|
| Array | recordAsArray () |
| | Get the record from the current cursor row.
|
| Object | recordAsObject () |
| | Get the record from the current cursor row as an object.
|
| Boolean | seek (Number aIndex, Boolean aRelative) |
| | Retrieves the record at position index, if available, and positions the query on the retrieved record.
|
| Number | size () |
| | return The size of the result (number of rows returned).
|
| String | sql () |
| Mixed | value (Number aField) |
| | Get a field value from the current cursor row.
|
| SqlValues | values () |
| | Get the SQL values from the current cursor row.
|
The query class is used to process SQL queries.
Example:
with (bps) {
log(
"connect to database");
var ds = new bps.Datastore();
with (ds) {
connection = "test";
username = "test12";
password = "test44";
connect();
}
var q = new bps.Query(ds);
q.execute("select ident, value from mytable order by ident");
log(
"found "+q.size()+
" rows:");
while (q.next())
log(q.value(0)+
" - "+q.value(1));
if (!q.forwardOnly) {
log(
"now list result set backward");
while (q.previous()) bps.log(q.value(0)+" - "+q.value(1));
log(
"display middle row");
if (q.seek(1)) bps.log(q.value(0)+" - "+q.value(1));
}
log(
"disconnect from database");
ds.disconnect();
}
| Boolean bps::Query::seek |
( |
Number |
aIndex, |
|
|
Boolean |
aRelative |
|
) |
| |
Retrieves the record at position index, if available, and positions the query on the retrieved record.
The first record is at position 0. Note that the query must be in an active state and select must be true before calling this function.
If relative is false (the default), the following rules apply:
- If index is negative, the result is positioned before the first record and false is returned.
- Otherwise, an attempt is made to move to the record at position index.
- If the record at position index could not be retrieved, the result is positioned after the last record and false is returned.
If relative is true, the following rules apply:
- If the result is currently positioned before the first record or on the first record, and index is negative, there is no change, and false is returned.
- If the result is currently located after the last record, and index is positive, there is no change, and false is returned.
- If the result is currently located somewhere in the middle, and the relative offset index moves the result below zero, the result is positioned before the first record and false is returned.
- Otherwise, an attempt is made to move to the record index records ahead of the current record (or index records behind the current record if index is negative).
- If the record at offset index could not be retrieved, the result is positioned after the last record if index >= 0, (or before the first record if index is negative), and false is returned.
- Parameters
-
| aIndex | The absolute or relative index. |
| aRelative | True for relative mode, false for absolute mode. |
- Returns
- True if record successfully retrieved, false otherwise.