Versions Compared

Key

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

...

  • Create a session that uses a cursor and a session that executes modified DML statements. It is described by defining it as CONN1 and CONN2, respectively.

  • Set the session (CONN2) that executes the modified DML statement to non-autocommit mode.

  • Whenever cursor FETCH is executed in the session using the cursor (CONN1), change DML is executed in CONN2, and COMMIT or ROLLBACK is executed.

...

The following is an example of creating an application that reflects this action.

Code Block
languagecpp
/* The cursor is declared using the LIMIT clause. n is the last record value to be returned in the LIMIT clause and must be defined according to the operating environment. The number of records in the communication buffer depends on the record size. */
DECLARE CURSOR
         SELECT ~
           FROM ~
          WHERE ~
          LIMIT :s_start, n;
              

/* Declare the starting value used in the LIMIT clause. */
s_start = 1;
   
while(1)
{ 
    /* Cursor open is repeated until all records meeting the conditions are fetched. */                   
    OPEN CURSOR
    
		while(1)
		{
		    FETCH CURSOR ;
		    
		    if (sqlca.sqlcode == SQL_SUCCESS) {
		    
		       /* Execute change DML */   		     		       
		    }
		    else if (sqlca.sqlcode == SQL_NO_DATA) {
		       ...
		    }
		    else {              
		       ...
		    }   
		}
		
		/* Perform COMMIT or ROLLBACK */    
 
       /* Specify the starting value of the LIMIT clause. n is an example. */ 
       s_start = s_start + n ; 
        
}

CLOSE CURSOR or CLOSE RELEASE CURSOR

...