DBGETRESULTS        Get results from a SQL database query

Top  Previous  Next

Syntax:

DBGETRESULTS

 

Arguments:

None

 

Options:

None

 

 

This script command is used to obtain the results of a previous query into a SQL database file submitted by the DBQUERY script command.

 

DBGETRESULTS returns query results sequentially one row at a time. Up to a maximum of 1000 rows are permitted. (More result rows than 1000 will result in a DBQUERY error.) If multiple rows are expected from a given query, DBGETRESULTS would be called multiple times to fetch the data from all rows.

 

Script variable(s) of the form %db_xxxx corresponding to each column in the database table are created by this command and are assigned the value found in the particular database row being returned. The %dbqueryvariables script variable is assigned to the total number of variables created.

 

For example, if a table in a given SQL database is created with two columns, one named “fld1” and the other “fld2” then two %db_xxxx variables will be created by the DBGETRESULTS command as shown .

 

DBGETRESULTS

DISPLAY %db_fld1

DISPLAY %db_fld2

 

The following example shows how multiple rows may be retrieved when a suitable query has been issued to the database.

 

:loop

DBGETRESULTS

IFERROR $ERROR_DB_ALL_RESULTS_RTND GOTO done

DISPLAY %db_fld1

DISPLAY %db_fld2

DISPLAY %dbqueryvariables

GOTO loop

:done

 

In some cases DBGETRESULTS may not recognize the results of a query and/or is unable to create corresponding %db_xxxx variables. In such a case, DBGETRESULTS returns $ERROR_DB_RAW_QUERY_RESULTS and the raw results string is assigned to the %dbqueryrawresult script variable. If you are expecting a differently formatted query result then you can parse this string programatically or, otherwise, use this variable for troubleshooting purposes.

 

 

Related Command(s): DBCLOSE, DBUSE, DBQUERY, DBREWIND