SQLFETCH() Function - Get SQL Result

Syntax

SQLFETCH(sqlchan{,IND=1}{,END=lineref}{,ERR=lineref})

Description

The SQLFETCH() function returns the next element in the result set from the execution of the SQL command on sqlchan. If no results remain, an !ERROR=2 is returned. Other errors require using SQLERR to diagnose.

Use the optional IND=1 parameter to return the number of records modified by an update or delete.

Examples

Example 1

The following demonstrates the use of SQLFETCH in a loop to retrieve the result set records from a "Select" clause. Note that it uses the "ERR=label" option to terminate the loop when there are no more records.

0110 SQLOPEN(1)"ChileCompany"

0120 SQLPREP(1)"select * from item"

0130 DIM A$:SQLTMPL(1);SQLEXEC(1)

0140 WHILE 1

0150 A$=SQLFETCH(1,ERR=NO_MORE)

0160 PRINT A.DESCRIPTION$,A.COST:"$###,###.00-"

0170 WEND

0180 NO_MORE:

0190 SQLCLOSE(1)

Example 2

The following demonstrates the use of the IND=1 parameter to retrieve the result set count on an "Update" command.

0110 SQLOPEN(1)"ChileCompany"

0120 SQLPREP(1)"update item set cost=cost*1.1 where cost<10"

0130 DIM A$:SQLTMPL(1,IND=1);SQLEXEC(1)

0140 A$=SQLFETCH(1,IND=1)

0150 PRINT "Rows updated: ",A.ROWS_AFFECTED

0160 SQLCLOSE(1)

See Also

Functions - Alphabetical Listing