Using the Resultset object and its associated methods you can read records from a data table in a DataWeb web. For an explanation
of the method arguments see the Data Access Method
Arguments discussion.
Constructor
[new] Resultset (tablename, columns, filter[, sort]) |
A Resultset object instance is constructed and returned or an exception is thrown. tablename specifies the table on which the query operates, columns specifies the columns to return, filter is used to select a subset of the entries of the data table to be returned, and, optionally, sort names a column with a +/- preceding the name to determine the ascending or descending order of the returned data. |
|
Instance
Properties
A
Resultset object instance has properties corresponding to
the columns in the table specified at resultset construction.
The values of these properties depend on the position
of the resultset cursor. If the cursor does not point
at a valid record, attempting to access a field will throw
an exception. If the cursor points to a valid record,
the property values correspond to the current record's
database values.
Instance
Methods
afterLast |
Positions
the record cursor after the last record. |
beforeFirst |
Positions
the record cursor before the first record.
|
getCount |
Returns
the number of records actually present in
the resultset.
|
getCSV |
Returns
the Resultset formatted as a CSV file. |
getFieldList |
Returns
an Array object instance containing the names of all
the columns returned by the query. |
getTablename |
Returns
the name of the table from which this resultset
was selected. |
getXML |
Returns
the Resultset formatted as an XML file. |
hasPosition |
Returns
a boolean value indicating whether the cursor
points to a valid record. |
isComplete |
Returns
TRUE or
FALSE depending
on whether the resultset represents all the
database records that actually match the specified
filter. |
next |
Advances
the record cursor by one record. |
previous |
Moves
the cursor back one record. |
sendCSV |
Sends the
Resultset directly to the browser formatted
as a CSV file. |
sendXML |
Send the
Resultset directly to the browser formatted
as an XML file. |
|
Example
The following example constructs and returns a ResultSet object containing data from three fields (LastName, FirstName, and Email) of the AddressBook data table. Only those records where the LastName field has the value "Smith" are returned. The records are returned sorted alphabetically on the FirstName field.
var rs = new ResultSet("AddressBook",
"FirstName, LastName, Email",
"LastName='Smith'",
"+FirstName");
while(rs.next())
{
response.write(rs.FirstName + " " +
rs.LastName + " " +
rs.Email + "<br>");
}
Aggregation functions may be included in the columns argument. The following example retrieves the maximum value of the UnitPrice field.
var rs = new Resultset("Products",
"MaxPrice = Max(UnitPrice)", "*");
if(rs.next())
response.write(rs.MaxPrice);
SQL expressions may be included. In the following example, a SQL expression is used to add the appropriate title (Mr. or Ms.) to a name.
var rs = Resultset("AddressBook",
"CalcFullName = CASE
WHEN [SEX] = 'Male'
THEN 'Mr. ' + [FirstName] + ' ' + [LastName]
WHEN [Sex] = 'Female'
THEN 'Ms. ' + [FirstName] + ' ' + [LastName]", "*");
while(rs.next())
response.write(rs.CalcFullName);