Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 12 of 12 total
Thread About locks
Tue, Aug 5 2008 11:26 AMPermanent Link

Francisco Fernandez
Ok, i've changed the trigger like that:

BEGIN
 DECLARE TempCursor CURSOR FOR stmt;
 DECLARE TempCantidad DECIMAL(12,2);        
 WHILE TRUE DO
   START TRANSACTION ON TABLES Proveedores;
   BEGIN
     PREPARE stmt FROM 'SELECT * FROM Proveedores WHERE CODIGO COLLATE ESP_CI=?';
     OPEN TempCursor USING NEWROW.PROVEEDOR;
     FETCH FROM TempCursor (TOTALC) INTO TempCantidad;
     If TempCantidad IS NULL THEN
       UPDATE TempCursor SET TotalC=NEWROW.TOTALBASE;
     ELSE
       UPDATE TempCursor SET TotalC=TempCantidad+NEWROW.TOTALBASE;
     END IF;
     UPDATE TempCursor SET FECHAULTC=NEWROW.FECHA;
     COMMIT;
     LEAVE;
   EXCEPTION
     RAISE ERROR CODE 10000 MESSAGE 'Error al grabar';
   END;
 END WHILE;
END

... but it don't leave after commit and it save and save and save all the time, i must cut
program.
Tue, Aug 5 2008 12:26 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Francisco,

<< .. but it don't leave after commit and it save and save and save all the
time, i must cut program. >>

Well, you don't need the WHILE loop if you're just always issuing an
exception with RAISE in the EXCEPTION block.

But, if you want to keep the loop because you're going to add some more
processing in the EXCEPTION block for retrying, etc., then use this:

BEGIN
 DECLARE TempCursor CURSOR FOR stmt;
 DECLARE TempCantidad DECIMAL(12,2);
 WHILE TRUE DO
   START TRANSACTION ON TABLES Proveedores;
   BEGIN
     PREPARE stmt FROM 'SELECT * FROM Proveedores WHERE CODIGO COLLATE
ESP_CI=?';
     OPEN TempCursor USING NEWROW.PROVEEDOR;
     FETCH FROM TempCursor (TOTALC) INTO TempCantidad;
     If TempCantidad IS NULL THEN
       UPDATE TempCursor SET TotalC=NEWROW.TOTALBASE;
     ELSE
       UPDATE TempCursor SET TotalC=TempCantidad+NEWROW.TOTALBASE;
     END IF;
     UPDATE TempCursor SET FECHAULTC=NEWROW.FECHA;
     COMMIT;
   EXCEPTION
     ROLLBACK;
     RAISE ERROR CODE 10000 MESSAGE 'Error al grabar';
   END;
   LEAVE;
 END WHILE;
END

Notice that I included a ROLLBACK call - you were missing that.

--
Tim Young
Elevate Software
www.elevatesoft.com

« Previous PagePage 2 of 2
Jump to Page:  1 2
Image