Re: How to hold an update cursor with ESQL/C
Posted in 2003
On Thu, 29 May 2003 16:38:17 -0400, Eduardo Bispo wrote:
BTW check out my dbdelete utility in the package utils2_ak.
Art S. Kagel
> Hello everybody.
> I am starting with ESQL/C and I am getting problems to produce a program
> to remove rows from a table executing COMMIT at each 10000 rows deleted.
> After the first COMMIT I am losing the cursor. Could anybody give me
> some guidance and show what is missing?
>
> #include <stdio.h>
> #include <stdlib.h>
>
> #define DATAREF "1899-12-31"
>
> EXEC SQL include datetime;
>
> int ibsdate();
>
> main()
> {
> int data_ibs=ibsdate();
> int contareg=0;
> long contador=0;
>
> EXEC SQL BEGIN DECLARE SECTION;
>
> int datalimite=data_ibs-366;
>
> integer v_mis1date;
>
> EXEC SQL END DECLARE SECTION;
>
> printf("Data Limite: %d\\n", datalimite);
>
> EXEC SQL connect to 'ibs';
> EXEC SQL set isolation dirty read ;
> EXEC SQL declare cur_mis1 cursor for
> select mis1date
> from mis1
> where mis1date < :datalimite
> for update ;> EXEC SQL BEGIN WORk;
> EXEC SQL open cur_mis1;
>
> for(;;) {
> EXEC SQL fetch cur_mis1 into :v_mis1date ; EXEC SQL delete from mis1
> where current of cur_mis1 ; contareg++; if ( contareg > 10000 ) {
> EXEC SQL COMMIT WORK;
> printf("Registros eliminados: %ld\\n", contador); contareg=0; EXEC
> SQL BEGIN WORK;
> }
> contador++;
> }
> EXEC SQL COMMIT WORK;
> if (strncmp(SQLSTATE, "02", 2) != 0)
> printf("SQLSTATE after fetch is %s\\n", SQLSTATE);
>
> EXEC SQL close cur_mis1;
> EXEC SQL free cur_mis1;
> EXEC SQL disconnect current;
>
> printf("Fim da limpeza.\\nRegistros eliminados: %ld\\n\\n", contador);
>
>
> }