Syntax
SQLQueryRetrieve(ConnectNum, Column, DataVar$, DataSize)
Remarks
Assigns to the DataVar$ variable the data in the specified Column of the current row (the row where SQLQueryFetch or SQLSetRowPos positioned the cursor) of the query result. To use SQLQueryRetrieve, a macro must have already established a connection using SQLOpen. Also, a query must have already been executed using SQLQueryExec, and results must be pending.
You cannot use SQLQueryRetrieve to return data from a query executed by SQLExecQuery.
Caution
SQLQueryRetrieve assigns the data to the characters in DataVar$, up to the number of characters specified by DataSize. If the number of characters assigned to DataVar$ before it is used by SQLQueryRetrieve is less than DataSize, SQLQueryRetrieve may cause memory errors.
To avoid memory errors, the macro must ensure that the value of DataVar$ is at least DataSize characters long before it is used in a SQLQueryRetrieve instruction.
Argument | Explanation |
ConnectNum | The unique connection ID for a data source. The data source specified must have pending query results. If ConnectNum is not valid, SQLQueryExec would have returned an error value. In such a case, SQLQueryRetrieve places error information in memory for the error functions, if such information is available. |
Column | The number of a column in the data source from which to retrieve data. Use SQLRetrieveColumns to determine the valid range of values. If the column value is out of range, SQLQueryRetrieve returns 0 (zero) and places the error information in memory for the error functions. |
DataVar$ | The variable to which SQLQueryRetrieve assigns the data, up to the number of characters specified by DataSize. Before the SQLQueryRetrieve instruction is run, the value of DataVar$ must be at least DataSize characters long. Otherwise, memory errors may occur. |
DataSize | Specifies the width of the data at Column. To determine the value for DataSize, use SQLRetrieveColSize. If the length of the data in Column exceeds DataSize, SQLQueryRetrieve truncates the data. |
If the data cannot be returned successfully, SQLQueryRetrieve returns 0 (zero) or a negative error value.
Example
The following example uses a While...Wend loop to return the data in each column of each row in the pending data source with SQLQueryRetrieve so it can be processed.
cols = SQLRetrieveColumns(connect_no) ret = SQLQueryFetch(connect_no) While ret = 1 For i = 1 To cols storsize = SQLRetrieveColSize(connect_no, i) stor$ = String$(storsize, 50) SQLQueryRetrieve(connect_no, i, stor$, storsize) ' Statement block that processes the value of stor$ Next i ret = SQLQueryFetch(connect_no)