home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE51.TAR / mbase51 / examples / example6.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-04  |  1.6 KB  |  87 lines

  1. #include <mbase.h>
  2. #include "example6.h"
  3.  
  4. /*
  5.  * PROTOTYPES -----------------------------------------------------------------
  6.  *
  7.  */
  8.  
  9.    void main XARGS( (void) );
  10.  
  11.  
  12. /*
  13.  * CODE -----------------------------------------------------------------------
  14.  *
  15.  */
  16.  
  17. void
  18. main ()
  19. {
  20.    relation *rel;
  21.    example6  rec, comp;
  22.    int       num;
  23.  
  24.  
  25.    if ((rel = mb_inc ("example6", "")) == RNULL)
  26.       {
  27.       fprintf (stderr, "mb_inc() failed: %s\n", mb_error);
  28.       mb_exit (1);
  29.       }
  30.  
  31.  
  32. /*
  33.  * Before we can do a sweeping change like this, we oughta lock the
  34.  * relation to keep anyone else from working with any of the records
  35.  * we might change...
  36.  *
  37.  */
  38.  
  39.    if (mb_lck (rel) != MB_OKAY)
  40.       {
  41.       fprintf (stderr, "couldn't lock: %s\n", mb_error);
  42.       mb_exit (2);
  43.       }
  44.  
  45.  
  46. /*
  47.  * Now, as long as we can find records where the price is under $10,
  48.  * increase it to $10 even.
  49.  *
  50.  */
  51.  
  52.    comp.price = 10.00;
  53.  
  54.    for (num = 0; ; num++)
  55.       {
  56.       if (mb_sel (rel, idxnum(rel,"ix_price"), &rec, LTHAN, &comp) != MB_OKAY)
  57.          break;
  58.       rec.price = 10.00;
  59.  
  60.       printf ("updating tape '%s'\n", rec.tape);
  61.  
  62.       if (mb_upd (rel, &rec) != MB_OKAY)
  63.          {
  64.          fprintf (stderr, "couldn't update record: %s\n", mb_error);
  65.          mb_exit (3);  /* Unlocks relation */
  66.          }
  67.       }
  68.  
  69.  
  70. /*
  71.  * Now unlock the relation.  Of course, mb_exit() would do that for
  72.  * us, but hey...
  73.  *
  74.  */
  75.  
  76.    mb_unl (rel);  /* Okay, so I didn't check the return code. So sue me. */
  77.  
  78.    if (num == 0)
  79.       {
  80.       printf ("couldn't find any records with prices under $10.00\n");
  81.       printf ("use 'vr example6' to add some, and try this again.\n");
  82.       }
  83.  
  84.    mb_exit (0);
  85. }
  86.  
  87.