SclQueryOrder
Overview
This command defines the order in which rows are to be retrieved from the database table.
Synopsis
$QueryHandle SclQueryOrder $ColumnName $Order
Description
Define the order in which rows are to be retrieved from the table. The behavior of this command is database dependent. The simplest databases (Paradox, DBASE) have little flexibility with the ordering and can only return rows in the order defined by the indexed fields in the table. For these databases it is only permissable to use fields that already have an associated index and then only using the order of the index. That is, if the index is ascending then it is illegal to request the rows to be ordered descending.
More sophisticated database types (Oracle, SQL Server, etc.) may permit greater flexibility in the ordering of rows. Some trial and error will be required to determine the capabilities of a particular database engine.
Arguments
- QueryHandle
- ColumnName
- Order
- ascending
- descending
The variable must contain a valid query handle.
Passed by value. The name of the column for which the ordering is to be defined.
Passed by value. The order in which the rows are to be returned. Permitted values are:
Examples
#
# Get the handle to an existing database and query the collar table
# displaying hole ID and max depth for each hole
#
if {[sclDatabases SclCountItems] < 1} {
error "No databases are connected"
}
sclDatabases SclGetItem DatabaseHandle 0
#
# create a query to iterate over all holes in the collar table
#
$DatabaseHandle SclQuery QueryHandle "collar"
$QueryHandle SclQueryColumn "hole_id" "max_depth"
$QueryHandle SclQueryOrder "hole_id" "ascending"
$QueryHandle SclProcess
$QueryHandle SclGetIterator QueryIterator
while {[$QueryIterator SclIterateNext RowHandle] == $SCL_TRUE} {
set hole_id [$RowHandle SclGetValueByName "hole_id"]
set max_depth [$RowHandle SclGetValueByName "max_depth"]
puts "Hole ID=$hole_id, maxdepth=$max_depth"
}
SclDestroy QueryHandle
|