sqlfetch() — Fetch Next Row of Open Cursor

Fetches the next row of data for an open cursor. This function supports the EXEC SQL FETCH...INTO... statement.

This function returns normalized values. For more information, see the function return values in the "General Diagnostics" section in this chapter:

SYNTAX
int
sqlfetch ( sqln, flag, prequest, pvformat, psqlv)
  SQLRQHDL    *sqln;    /* INPUT */
  int         flag;       /* INPUT */
  char        *prequest; /* INPUT */
  char        *pvformat; /* INPUT */
  char        *psqlv[];  /* INPUT */ 

sqln

A pointer to the request handle for the open cursor. For more information on request handles, see the "SQL Request Handles" section.

flag

An execution flag that the SQL preprocessor initializes.

prequest

A pointer to the text of the statement.

pvformat

A pointer to a format string that describes the types and lengths of the embedded host variables.

psqlv

A pointer to the host variables to which the current SQL request refers.

EXAMPLE

This example fetches the next row of the open cursor x (associated with request handle sql0), and deposits the column values into the corresponding local variables custnum, nam, city, state, and maxcred:

#include "proesql.h"
static SQLRQHDL *sql0 = (SQLRQHDL *) 0;
            .
            .
            .
    /* EXEC SQL BEGIN DECLARE SECTION; */
    char nam[30];
    long custnum, maxcred;
    char city[20], state[3];
    /* EXEC SQL END DECLARE SECTION; */
            .
            .
            .
    /* EXEC SQL fetch x into :custnum,
         :nam, :city, :state, :maxcred; */
    {
       static char sqltxt[] = {
       ’f’,’e’,’t’,’c’,’h’,’,’x’,’,’i’,’n’,’t’,’o’,’,’e’,’s’,’q’,
       ’l’,’o’,’0’,’,’,’,’e’,’s’,’q’,’l’,’o’,’1’,’,’,’,’e’,’s’,’q’,
       ’l’,’o’,’2’,’,’,’,’e’,’s’,’q’,’l’,’o’,’3’,’,’,’,’e’,’s’,’q’,
       ’l’,’o’,’4’,’.’,0};
       static char sqlfmt[] = 
       {’4’,’l’,’3’,’0’,’s’,’2’,’0’,’s’,’3’,’s’,’4’,’l’,0};
       static char *sqlv[6];
       sqlv[0] = (char *) &custnum;
       sqlv[1] = (char *) nam;
       sqlv[2] = (char *) city;
       sqlv[3] = (char *) state;
       sqlv[4] = (char *) &maxcred;
       sqlv[5] = (char *) 0;
       sqlcdbind(&SQLCODE, (char *)0);
       sqlfetch(sql0,(int) 0x08,sqltxt,sqlfmt,sqlv);
       if (SQLCODE == 100) goto done1;
       if (SQLCODE < 0) goto err;
            .
            .
    } 

SEE ALSO

sqldynftch() — Fetch Next Row of Dynamic Cursor for dynamic fetches, sqlrequest() — Execute a Static ESQL Statement for opening static cursors, and sqldynposfetch() — Fetch Row of Dynamic Open Cursor for positioned fetches.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095