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 SQL statement executed by the DBQUERY command. Each time the DBGETRESULTS command is called, another row of the resultset is returned. This command may be called repeatedly in a loop. When using the built-in SQLite database engine a maximum of 1000 rows are available. This row limit does not apply to ODBC connections made using a DSN. The DBREWIND command is available to restart from the first row.

 

This command works by creating script variables of the form %db_ColumnName corresponding to the name of each column in the resultset. These variables are assigned the column values of the current row. The total number of column variables created is stored in a variable named %dbqueryvariables. These variables are subject to the same 4096 character limit that applies to all Robo-FTP variables.

 

For example, if a table in a given SQL database is created with two columns, one named “animal” and the other “color”, then two %db_ColumnName variables will be created by the DBGETRESULTS command as shown below:

 

DBGETRESULTS

DISPLAY %db_animal

DISPLAY %db_color

 

The following example calls the DBGETRESULTS command in a loop to process a multi-row resultset and exits the loop when the error value $ERROR_DB_ALL_RESULTS_RTND is returned:

 

:loop

DBGETRESULTS

IFERROR= $ERROR_DB_ALL_RESULTS_RTND GOTO done

DISPLAY %db_animal

DISPLAY %db_color

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_ColumnName variables. In such a case, DBGETRESULTS returns the error value $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 programmatically or, otherwise, use this variable for debugging purposes.

 

Calling the DBCLOSE command when you are done working with your database will remove the %db_ColumnName variables created by DBGETRESULTS. The DISPLAY command used without any arguments will show a list of all currently declared script variables, including the %db_ColumnName variables created by DBGETRESULTS.  Like with other user-created variables, using the SET command with only name of a %db_ColumnName variable and no values will cause that variable to be removed.

 

 

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

See also: Using the built-in database engine