START TRANSACTION -

HMG en Español

Moderator: Rathinagiri

Post Reply
User avatar
edufloriv
Posts: 238
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

START TRANSACTION -

Post by edufloriv »

Saludos amigos, yo nuevamente,

Tengo esta rutina para grabar una transacción en mi sistema:

Code: Select all

   nQueryError := 0
   oTransact := oServer:Query( "START TRANSACTION; " ) 

      SELE ADTMP
      PACK
      CLOSE ACTMP
      CLOSE ADTMP
      USE &AC_MEM ALIAS MEMCAB EXCLUSIVE NEW
      APPEND FROM (AC_TMP)
      CLOSE MEMCAB
      USE &AD_MEM ALIAS MEMDET EXCLUSIVE NEW
      APPEND FROM (AD_TMP)
      CLOSE MEMDET
      USE &AC_TMP ALIAS TMPCAB EXCLUSIVE NEW
      USE &AD_TMP ALIAS TMPDET EXCLUSIVE NEW

      IF AlmaGraba_Cab1()
         cEnCurso := 'Operacion:'+INTSTR(TMPCAB->XC_OPENUM)+chr(13)+chr(10)+'Cabecera:'+AC_TMP+chr(13)+chr(10)+'Detalles:'+AD_TMP+chr(13)+chr(10)
         hb_memowrit( 'almacen_en_curso.txt' , cEnCurso )
         IF AlmaGraba_CargaDescarga()
            IF AlmaGraba_Det()
               IF AlmaGraba_Cab2()
                  nAlmaNew := TMPCAB->XC_OPENUM
               ELSE
                  msginfo('ERROR: No se pudo cerrar la cabecera de la operación.')
                  nQueryError++
               ENDIF
            ELSE
               msginfo('ERROR: No se pudieron insertar todos los detalles de la operación.')
               nQueryError++
            ENDIF
         ELSE
            nQueryError++
         ENDIF
      ELSE
         msginfo('ERROR: No se pudo insertar la cabecera de la operación.')
         nQueryError++
      ENDIF

      CLOSE TMPCAB
      CLOSE TMPDET

      IF nQueryError = 0
         oTransact := oServer:Query( "COMMIT; " ) 
         USE &AC_MEM ALIAS MEMCAB EXCLUSIVE NEW
         REPLACE MEMCAB->XC_OPENUM WITH nAlmaNew FOR MEMCAB->XC_STAMP = AC_STM
         CLOSE MEMCAB
         USE &AD_MEM ALIAS MEMDET EXCLUSIVE NEW
         REPLACE MEMDET->XD_OPENUM WITH nAlmaNew FOR MEMDET->XD_STAMP = AC_STM
         CLOSE MEMDET
         DELETE FILE ('almacen_en_curso.txt')
         DELETE FILE ('almacen_temp.txt')
         CLEANDIR( 'AC_' )
         CLEANDIR( 'AD_' )
      ELSE
         oTransact := oServer:Query( "ROLLBACK; " ) 
         USE &AC_TMP ALIAS ACTMP EXCLUSIVE NEW
         USE &AD_TMP ALIAS ADTMP EXCLUSIVE NEW
         nAlmaNew    := 0
         nQueryError := 0
      ENDIF

   oTransact:Destroy()
Supuestamente si no ocurre ningún error en alguna de las operaciones intermedias, la variable nQueryError tendrá valor cero y se ejecutará el COMMIT, de lo contrario se ejecutará el ROLLBACK.

Sin embargo hoy dia me reporto un usuario que le apareció el mensaje msginfo('ERROR: No se pudo cerrar la cabecera de la operación.'), con lo que supuestamente nQueryError se incrementó y debió realizarse el ROLLBACK, sin embargo LO UNICO QUE SE ELIMINO FUE EL REGISTRO DE CABECERA ( AlmaGraba_Cab1() ) y dejó intactos los registros de detalles, kardex y stocks.

Me dá la impresión que el ROLLBACK en el lado del MySQL no está funcionando adecuadamente. Estoy contemplando la posibilidad de no usar START TRANSACTION y realizar mi rollback yo mismo de forma manual (de hecho ya tengo una rutina que lo hace sin ningún problema).

Agradeceré me indiquen si estoy estructurando bien la rutina, quizás algo que no estoy viendo o simplemente realizo mi rollback yo mismo.

Gracias anticipadas por su atención y tiempo. Cordiales saludos.

Eduardo Flores Rivas


LIMA - PERU
franco
Posts: 822
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: START TRANSACTION -

Post by franco »

Hi Eduardo,
Not sure if this could be a problem but in all my programs I create a local temp folder 'c:mytemp' . Then any temporary files created are in the
local terminal, This stops any files in the server getting duplicated and also speeds up the system because the file is local. This even works with
temporary index files. This is why I use temporary indexes instead of filters, much faster.
All The Best,
Franco
Canada
Post Reply