Why rollback does not work?

Why rollback does not work?

Post by Marko Naiv » Sat, 21 Jul 2001 00:20:15



Hello!
ROLLBACK should undo the uncommitted changes, but it looks like it does not
work allways. Inside a transaction I call several INSERTs in a loop (to add
table rows), but if one of those inserts causes a "Foreign key constraint
violation" error, ROLLBACK call doesn't do anything.

Are there really situations when rollback call doesn't undo the whole
transaction (with BEGIN TRAN)?

Yours,
Marko

 
 
 

Why rollback does not work?

Post by Ivan Santhumayo » Sat, 21 Jul 2001 02:18:50


yes, depends on the severity of the error in the statements within the tran.

Severities 16 and greater are considered for rollback usually.

> Hello!
> ROLLBACK should undo the uncommitted changes, but it looks like it does not
> work allways. Inside a transaction I call several INSERTs in a loop (to add
> table rows), but if one of those inserts causes a "Foreign key constraint
> violation" error, ROLLBACK call doesn't do anything.

> Are there really situations when rollback call doesn't undo the whole
> transaction (with BEGIN TRAN)?

> Yours,
> Marko


 
 
 

Why rollback does not work?

Post by Marko Naiv » Sat, 21 Jul 2001 16:40:32


>yes, depends on the severity of the error in the statements within the
tran.

>Severities 16 and greater are considered for rollback usually.

I think we already do the manual rollback.
In our case error situation launches allways the general error handling in
the application (supported by Centura, the software development tool) and
there we call manually that rollback. I suppose it's the same thing as you
mentioned. Unlikely it won't undo the changes in the database table. Nor
local rollback call after general error handling.

Here is more specific illustration about the case:

...
! Insert statement, which is done for all application table rows.
SqlPrepare( hSql1, 'INSERT INTO EGDBTABLE...')
Loop
  ...
  ! One validity checking inside the loop
  SqlPrepareAndExecute( hSql3, 'SELECT...')
  SqlFetchNext( hSql3 )
  ...
  ! In my example case that insert is done successfully several (8) times,
    but on the 9th row that SqlExecute call halts to a
    "Foreign key constraint violation" error (I know the reason for error,
    that's not the problem) and it launches our general error handling:

         [ If SqlPrepare(hSql1,'ROLLBACK')
              Call SqlExecute(hSql1)
         ]
  ...
  If NOT SqlExecute( hSql1 )
    ! For safety's safe there's also a local rollback call.
    Call SqlPrepareAndExecute( hSql2, 'ROLLBACK TRANSACTION' )
    Return FALSE

! Process stops, but unlikely the first 8 rows are still in the database.
Rollback call didn't make the undoing.

Btw, table EGDBTABLE has an insert trigger, which launches some other update
triggers elsewhere. Usually in error case also trigger changes are rolled
back, but not now... Is this a special "Foreign key constraint violation"
feature?

- Marko -

 
 
 

Why rollback does not work?

Post by Ivan Santhumayo » Sun, 22 Jul 2001 11:32:22


I am surprised that the manual rollback fails in this case. maybe someone from
sybase can comment.
But, regards to trigger, yes, it does behave differently and rolls back the
subsequent insert statements following the one causing the error. I believe the
ROLLBACK TRIGGER statement would rollback only that particular insert statement.

> >yes, depends on the severity of the error in the statements within the
> tran.

> >Severities 16 and greater are considered for rollback usually.

> I think we already do the manual rollback.
> In our case error situation launches allways the general error handling in
> the application (supported by Centura, the software development tool) and
> there we call manually that rollback. I suppose it's the same thing as you
> mentioned. Unlikely it won't undo the changes in the database table. Nor
> local rollback call after general error handling.

> Here is more specific illustration about the case:

> ...
> ! Insert statement, which is done for all application table rows.
> SqlPrepare( hSql1, 'INSERT INTO EGDBTABLE...')
> Loop
>   ...
>   ! One validity checking inside the loop
>   SqlPrepareAndExecute( hSql3, 'SELECT...')
>   SqlFetchNext( hSql3 )
>   ...
>   ! In my example case that insert is done successfully several (8) times,
>     but on the 9th row that SqlExecute call halts to a
>     "Foreign key constraint violation" error (I know the reason for error,
>     that's not the problem) and it launches our general error handling:

>          [ If SqlPrepare(hSql1,'ROLLBACK')
>               Call SqlExecute(hSql1)
>          ]
>   ...
>   If NOT SqlExecute( hSql1 )
>     ! For safety's safe there's also a local rollback call.
>     Call SqlPrepareAndExecute( hSql2, 'ROLLBACK TRANSACTION' )
>     Return FALSE

> ! Process stops, but unlikely the first 8 rows are still in the database.
> Rollback call didn't make the undoing.

> Btw, table EGDBTABLE has an insert trigger, which launches some other update
> triggers elsewhere. Usually in error case also trigger changes are rolled
> back, but not now... Is this a special "Foreign key constraint violation"
> feature?

> - Marko -

 
 
 

1. Why does this code work/Not work?

All,

I have the code below, sometimes it work, most of the time it doesn't. I
thought I had it down till it doesn't always give me the right result.
Let me know how to fix if you could.

#include "postgres.h"
#include "fmgr.h"

PG_FUNCTION_INFO_V1(f_call_useragent);

Datum f_call_useragent(PG_FUNCTION_ARGS) {

  text   *t0 = PG_GETARG_TEXT_P(0);
  text   *t1 = PG_GETARG_TEXT_P(1);
  text   *t2 = PG_GETARG_TEXT_P(2);
  text   *t3 = PG_GETARG_TEXT_P(3);
  text   *t4 = PG_GETARG_TEXT_P(4);

  int status=0
     ,len0 = VARSIZE(t0) - VARHDRSZ
     ,len1 = VARSIZE(t1) - VARHDRSZ
     ,len2 = VARSIZE(t2) - VARHDRSZ
     ,len3 = VARSIZE(t3) - VARHDRSZ
     ,len4 = VARSIZE(t4) - VARHDRSZ;

  char *command = (char *)
palloc(32+len0+2+len1+2+len2+2+len3+2+len4+2);

  strcpy(command,"perl /var/lib/pgsql/c/callLWP.pl ");
  strncat(command,VARDATA(t0),VARSIZE(t0));
  strcat(command," ");
  strncat(command,VARDATA(t1),VARSIZE(t1));
  strcat(command," ");
  strncat(command,VARDATA(t2),VARSIZE(t2));
  strcat(command," ");
  strncat(command,VARDATA(t3),VARSIZE(t3));
  strcat(command," ");
  strncat(command,VARDATA(t4),VARSIZE(t4));

  status=system(command);

  pfree(command);
  PG_RETURN_INT32(status);

Thanks,
Jeff

2. Read char at screen position

3. Why isn't Rollback working?

4. how to get a column list with SQL cmd?

5. why NOT IN cluase not working?

6. help : VB 5.0 and Crystal Report

7. Why not rollback?

8. A way to run perl DBD::Informix with RDS?

9. Why it is not recommended to use Commit or Rollback in Trigger

10. Herlp: LIKE in SQL doe not work anymore

11. Rollback not working

12. DTS bulk insert, commit or rollback not working?

13. Rollback Does not work