Transaction Processing
by Charles Curley

Listing One

/* Start Wilma */
/*     if (Begin(ctTRNLOG|ctENABLE) == 0) { */
/*       printf("Error beginning transaction: %d\n", uerr_cod); */
/*     } */
    AddName ("Wilma", "Flintstone");
    AddPhone ("213-555-1212", "Home");
    /* "PL" for Paleolithic. */
    AddAddress ("1234 Jurassic Park", "", "Bedrock", "PL", "12345", "Home");
/*     if (Commit(ctFREE)) { */
/*       printf("Error committing transaction: %d.\n", uerr_cod); */
/*     } */
    printf ("LatestIndex is %ld\n", LatestIndex);
    /* End Wilma */

Listing Two

/* Start Barney */
if (Begin(ctTRNLOG|ctENABLE) == 0) {
  printf("Error beginning transaction: %d\n", uerr_cod);
}
oops = AddName ("Barney", "Rubble");
oops |= AddAddress ("Box 432", "1244 Jurassic Park", 
                                          "Bedrock", "PL", "12345", "Home");
oops |= AddPhone ("213-555-5555", "Home");
oops |= AddPhone ("213-555-4444", "Work");

if (oops) {
  printf ("Transaction Failed!. Error is %d\n", oops);
  Abort ();                 /* Stop the transaction */
  StopUser ();              /* Close out the connection */
  ctrt_exit(4);
}
if (Commit(ctFREE)) {
  printf("Error committing transaction: %d.\n", uerr_cod);
}
printf ("LatestIndex is %ld\n", LatestIndex);
/* End Barney */


Listing Three

/* Start Betty */
do {
  if (Begin(ctTRNLOG|ctENABLE) == 0) {
    printf("Error beginning transaction: %d\n", uerr_cod);
  }
  oops = AddName ("Betty", "Rubble");
  oops |= AddPhone ("213-555-5555", "Home");
  oops |= AddAddress ("Box 432", "1244 Jurassic Park", 
                                      "Bedrock", "PL", "12345", "Home");
  if (oops) {
    Abort ();               /* Stop the transaction */
    cycles++;
    if (cycles > 5) {
      printf ("Transaction Failed after 6 tries!");
      StopUser ();          /* Close out the connection */
      ctrt_exit(4);
    }
  }
} while (oops);
if (Commit(ctFREE)) {
  printf("Error committing transaction: %d.\n", uerr_cod);
}
printf ("LatestIndex is %ld\n", LatestIndex);
/* End Betty */


Listing Four

/* Start Fred */
if (Begin(ctTRNLOG|ctENABLE) == 0) {
  printf("Error beginning transaction: %d\n", uerr_cod);
}
AddName ("Fred", "Flintstone");
AddPhone ("213-555-1212", "home");
cycles = 0;
/* Save our position in the transaction for now */
SavePoint = SetSavePoint ();
do {
  /* Try it */
  oops = AddAddress ("1234 Jurassic Park", "","Bedrock","PL","12345","Home");
  oops |= AddPhone ("213-555-6666", "work");
  oops |= AddPhone ("213-555-7777", "mobile");
  /* Were we sucessful? */
  if (oops) {
    /* No, go back on our transaction. */
    cycles++;
    if (cycles > 5) {
      printf ("Transaction Failed after 6 tries!");
      Abort ();             /* Stop the transaction */
      StopUser ();          /* Close out the connection */
      ctrt_exit(4);
    } else {
      RestoreSavePoint (SavePoint);
    }
  }
} while (oops);
if (Commit(ctFREE)) {
  printf("Error committing transaction: %d.\n", uerr_cod);
}
printf ("LatestIndex is %ld\n", LatestIndex);
/* End Fred */






2



