Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Cursor CLOSE fails, but the exception is not handled, and the cursor is reused with the same name without knowing that the cursor CLOSE failed.

  • This is for HDB 5 or later version. In HDB 4 version, there is no error in this case.

  • Example code

    Code Block
    languagecpp
    declare cursor A;
    if (  sqlca.sqlcode != SQL_SUCCESS ) {
       exception handling;
    } 
    open cursor A;
    if (  sqlca.sqlcode != SQL_SUCCESS ) {
       exception handling;
    }
    fetch cursor A;                                          // fetch completed! 
    if (  sqlca.sqlcode != SQL_SUCCESS ) {
       exception handling;
    }                                                               
     
    close cursor A;                                          //  No exception handling.
    /* close cursor A failed!! */ 
                          
    declare cursor A;
    if (  sqlca.sqlcode != SQL_SUCCESS ) {
       exception handling; 
    }
  • If this is the case, add exception handling to the cursor CLOSE statement and figure out what caused the cursor CLOSE to fail.

3. When the cursor is reused while the result of the data to be fetched remains

  • If there is data to be fetched in the DB server, the result is deleted when the cursor is closed.

  • In other words, the cursor with the same name cannot be reused until the data to be fetched is deleted. In order to reuse, the cursor must be FETCHed after OPENed.

    Code Block
    titleExample 1
    languagecpp
    while(1)
    {   
       fetch cursor A             // Data to be fetched remains
       open cursor A             // An error occurs when the cursor with the same name is reused while the data to be fetched remains!
    }
    Code Block
    while(1)
    {
       SQLFetch(stmt)          // Data to be fetched remains
       SQLExecute(stmt)      // An error occurs when the cursor with the same name is reused while the data to be fetched remains!
    }
  • If this is the case, try to reuse the cursor after adding the cursor CLOSE statement.