Generating Query Results

There are several ways to generate query results:

rigDBresult()

This function returns the query result data as an array. Typically you'll use this in a loop, like this:

get rigDbQuery("YOUR QUERY")
  
put rigDBresult() into tResult
  
repeat for each key tKey in tResult
  put tResult[tKey] into tRow
  put tRow[2] & comma after tResultData
  put tRow[4] & comma after tResultData
  put tRow[7] & return after tResultData
end repeat

In the example above index 2, 4 and 7 of tRow define the value in the second, fourth and seventh column of the current row. Note: If you need to keep the order of the result values, you need to add an incrementer:

get rigDbQuery("YOUR QUERY")
  
put rigDBresult() into tResult
  
put 0 into tIncr
repeat for each key tKey in tResult
  add 1 to tIncr
  
  put tResult[tIncr] into tRow
  put tRow[2] & comma after tResultData
  put tRow[4] & comma after tResultData
  put tRow[7] & return after tResultData
end repeat

You may fetch the values for each row by column name like in the following example:

get rigDbQuery("YOUR QUERY")
  
put rigDBresult() into tResult
  
put 0 into tIncr
repeat for each key tKey in tResult
  add 1 to tIncr
  
  put rigDbRow(tIncr) 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 rigDbQuery("YOUR QUERY") into tQuery
  
# CHECK IF THE QUERY RESULT HAS DATA
if tQuery["numrows"] > 0 then
  put rigDBresult() into tResult
  
  put 0 into tIncr
  repeat for each key tKey in tResult
    add 1 to tIncr
  
    put rigDbRow(tIncr) 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 rigDbQuery("YOUR QUERY") into tQuery
  
repeat for each key tKey in tQuery["resultarray"]
  
  put tQuery["resultarray"][tKey] into tRow
  put tRow[2] & comma after tResultData
  put tRow[4] & comma after tResultData
  put tRow[7] & return after tResultData
end repeat

yourQuery["fieldnames"]

This query result index contains the table field names in a numbered array.

 yourQuery["fieldnumbers"]

This query result index contains the table field numbers in an associative array where the keys are the field names. Using this array allows you to write the code above referencing field names instead of field numbers like:

put rigDbQuery("YOUR QUERY") into tQuery
  
repeat for each key tKey in tQuery["resultarray"]
  
  put tQuery["resultarray"][tKey] into tRow
  put tRow[tQuery["fieldnumbers"]["title"]] & comma after tResultData
  put tRow[tQuery["fieldnumbers"]["name"]] & comma after tResultData
  put tRow[tQuery["fieldnumbers"]["body"]] & return after tResultData
end repeat

rigDbRow()

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 rigDbQuery("YOUR QUERY") into tQuery
  
if tQuery["numrows"] > 0 then
  
  put rigDbRow() 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 rigDbRow(5) into tRow

In addition, you can walk forward/backwards/first/last through your results using these variations:

put rigDbFirstRow() into tRow
put rigDbLastRow() into tRow
put rigDbNextRow() into tRow
put rigDbPreviousRow() into tRow
put rigDbCurrentRow() into tRow

They all return an array.

Result Helper Functions

rigNumRows()

The number of rows returned by the query.

put rigDbQuery("SELECT * FROM myTable") into tQuery
  
get rigNumRows()

Note: You can always use tQuery["numrows"].

rigNumFields()

The number of FIELDS (columns) returned by the query.

put rigDbQuery("SELECT * FROM myTable") into tQuery
  
get rigNumFields()