Generating Query Results
There are several ways to generate query results:
DBresult()
This function returns the query result data as an array. Typically you'll use this in a loop, like this:
get dbQuery("YOUR QUERY")
put DBresult() into tResult
repeat for each key tKey in tResult
put tResult[tKey] into tRow
put tRow["title"] & comma after tResultData
put tRow["name"] & comma after tResultData
put tRow["body"] & return after tResultData
end repeat
If you run queries that might not produce a result, you are encouraged to test the result first:
put dbQuery("YOUR QUERY") into tQuery
# CHECK IF THE QUERY RESULT HAS DATA
if tQuery["numrows"] > 0 then
put DBresult() into tResult
repeat for each key tKey in tResult
put tResult[tKey] into tRow
put tRow["title"] & comma after tResultData
put tRow["name"] & comma after tResultData
put tRow["body"] & return after tResultData
end repeat
end if
yourQuery["resultarray"]
This query result index contains the pure result data as an array. Typically you'll use this in a loop, like this:
put dbQuery("YOUR QUERY") into tQuery
repeat for each key tKey in tQuery["resultarray"]
put tQuery["resultarray"][tKey] into tRow
put tRow["title"] & comma after tResultData
put tRow["name"] & comma after tResultData
put tRow["body"] & return after tResultData
end repeat
dbRow()
This function returns a single result row as an array. If your query has more than one row, it returns only the first row. The result is returned as an array. Here's a usage example:
put dbQuery("YOUR QUERY") into tQuery
if tQuery["numrows"] > 0 then
put dbRow() into tRow
put tRow["title"] & comma after tResultData
put tRow["name"] & comma after tResultData
put tRow["body"] & return after tResultData
end if
If you want a specific row returned you can submit the row number as a digit in the first parameter:
put dbRow(5) into tRow
In addition, you can walk forward/backwards/first/last through your results using these variations:
put dbFirstRow() into tRow
put dbLastRow() into tRow
put dbNextRow() into tRow
put dbPreviousRow() into tRow
put dbCurrentRow() into tRow
They all return an array.
Result Helper Functions
numRows()
The number of rows returned by the query.
put dbQuery("SELECT * FROM myTable") into tQuery
get numRows()
Note: You can always use tQuery["numrows"].
numFields()
The number of FIELDS (columns) returned by the query.
put dbQuery("SELECT * FROM myTable") into tQuery
get numFields()