Mimer SQL Documentation TOC PREV NEXT INDEX

Mimer SQL Developer Site


Extended Dynamic Cursors


A typical cursor is identified by an SQL identifier. An extended cursor makes it possible to represent a dynamic cursor by a host variable or a literal. An extended cursor is allocated by the application with the ALLOCATE CURSOR statement, see the Mimer SQL Reference Manual, ALLOCATE CURSOR, for the syntax description.

When the application is finished with the processing of the SQL statement, the prepared statement may be destroyed by executing the DEALLOCATE PREPARE statement, see the Mimer SQL Reference Manual, DEALLOCATE PREPARE, for the syntax description. DEALLOCATE PREPARE also destroys any extended cursor that was associated with the statement.

Example of how extended cursors are used:

 ...
 EXEC SQL BEGIN DECLARE SECTION;
    string SQL_TXT(255);
    string C1(128);
    string STM1(128);
    integer HOSTVAR1;
    string HOSTVAR2(10);
    ...
 EXEC SQL END DECLARE SECTION;
 ...
 
 SQL_TXT := "SELECT col1, col2
                FROM tab1";
 STM1 := "STMT_1";
 EXEC SQL PREPARE :STM1 FROM :SQL_TXT;
 
 C1 := "CUR_1";
 EXEC SQL ALLOCATE :C1 CURSOR FOR :STM1;
 ...
 
 EXEC SQL ALLOCATE DESCRIPTOR 'SQLA' WITH MAX 50;
 EXEC SQL DESCRIBE OUTPUT :STM1 USING SQL DESCRIPTOR 'SQLA';
 ...
 EXEC SQL OPEN :C1;
 EXEC SQL WHENEVER NOT FOUND GOTO done;
 
 loop
    EXEC SQL FETCH :C1
                INTO SQL DESCRIPTOR 'SQLA';
    EXEC SQL GET DESCRIPTOR 'SQLA' VALUE 1 :HOSTVAR1 = DATA;
    EXEC SQL GET DESCRIPTOR 'SQLA' VALUE 2 :HOSTVAR2 = DATA;
    ...
    display HOSTVAR1, HOSTVAR2, ...;
 end loop;
 
 done:
 EXEC SQL CLOSE :C1;
 EXEC SQL DEALLOCATE DESCRIPTOR 'SQLA';
 EXEC SQL DEALLOCATE PREPARE :STM1;
 ...

Mimer
Mimer Information Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40
info@mimer.se
Mimer SQL Documentation TOC PREV NEXT INDEX