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

  1. #include <mbase.h>
  2. #include "example7.h"
  3.  
  4.  
  5. /*
  6.  * PROTOTYPES -----------------------------------------------------------------
  7.  *
  8.  */
  9.  
  10.    void main XARGS( (void) );
  11.  
  12.  
  13. /*
  14.  * CODE -----------------------------------------------------------------------
  15.  *
  16.  */
  17.  
  18. void
  19. main ()
  20. {
  21.    relation *rel;
  22.    example7  rec;    /* typedef example7 is defined in example7.h */
  23.    int       num;
  24.  
  25.    if ((rel = mb_inc ("example7", "books")) == 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 delete...
  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.    if (recInit (rel, &rec) != MB_OKAY)
  46.       {
  47.       fprintf (stderr, "recInit() failed: %s\n", mb_error);
  48.       mb_exit (3); /* will unlock/close relation automatically */
  49.       }
  50.  
  51.    for (num = 0; ; num++)
  52.       {
  53.       strcpy (rec.author, "Heinlein");
  54.  
  55.       if (mb_sel (rel, idxnum(rel,"ix_author"), &rec, EQUAL, NULL) != MB_OKAY)
  56.          break;
  57.  
  58.       printf ("deleting title '%s'\n", rec.title);
  59.  
  60.       if (mb_del (rel) != MB_OKAY)
  61.          {
  62.          fprintf (stderr, "mb_del() failed: %s\n", mb_error);
  63.          mb_exit (3);
  64.          }
  65.       }
  66.  
  67.  
  68.    recFree (rel, &rec);
  69.  
  70. /*
  71.  * Now unlock the relation and exit.
  72.  *
  73.  */
  74.  
  75.    mb_unl (rel);
  76.  
  77.    if (num == 0)
  78.       {
  79.       printf ("couldn't find any Heinlein books to delete.\n");
  80.       printf ("use VR to add some records to example7.rel, with the \n");
  81.       printf ("author set to \"Heinlein\", and re-run this example.\n");
  82.       printf ("\n");
  83.       printf ("use the encryption key 'books' to access this relation.\n");
  84.       }
  85.  
  86.    mb_exit (0);
  87. }
  88.  
  89.