home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / cdb112.zip / TEST.C < prev    next >
Text File  |  1991-01-31  |  3KB  |  110 lines

  1. /* test.c */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <dbmgr.h>
  6. #include <test.h>
  7.  
  8. void main( void);
  9.  
  10. char *dbNames[] =
  11.     {
  12.     "Customer",
  13.     "acctNbr",
  14.     "company",
  15.     "Address",
  16.     "zip",
  17.     "telephone",
  18.     "Invoice",
  19.     "invNbr",
  20.     "InvoiceLine"
  21.     };
  22.  
  23. #define CUSTOMER        dbNames[0]
  24. #define ACCTNBR         dbNames[1]
  25. #define COMPANY         dbNames[2]
  26. #define ADDRESS         dbNames[3]
  27. #define ZIP             dbNames[4]
  28. #define TELEPHONE       dbNames[5]
  29. #define INVOICE         dbNames[6]
  30. #define INVNBR          dbNames[7]
  31. #define INVOICELINE     dbNames[8]
  32.  
  33. struct Customer customer[3] =
  34.     {
  35.     {1000L,"Fred Gwynne Company",0.00},
  36.     {1001L,"CompuServe Incorporated",0.00},
  37.     {1002L,"Microsoft",0.00},
  38.     };
  39.  
  40. struct Address address[4] =
  41.     {
  42.     {"124 South Columbus St.","Columbus","Oh","43201","6142883222"},
  43.     {"2000 Arlington Center Blvd","Columbus","Oh","43228","6144598600"},
  44.     {"12 North Fork Ave.","Redmond","WA","55555","5332341234"},
  45.     {"13 North Fork Ave.","Redmond","WA","55555","5332341235"},
  46.     };
  47.  
  48.  
  49. void main( void)
  50.     {
  51.     long acctNbr = 1001L;
  52.     struct currency_index currency;
  53.     struct Customer t_customer;
  54.     struct Address t_address;
  55.  
  56.     if( DbOpen( "test.dbd"))
  57.         {
  58.         printf( "Error opening test.dbd\n");
  59.         exit( 1);
  60.         }
  61.  
  62.     /* Customer 1000 */
  63.     DbRecordAdd( CUSTOMER, &customer[0]);
  64.     DbRecordAdd( ADDRESS, &address[0]);
  65.     DbSetAdd( CUSTOMER, ADDRESS);
  66.  
  67.     /* Customer 1001 */
  68.     DbRecordAdd( CUSTOMER, &customer[1]);
  69.     DbRecordAdd( ADDRESS, &address[1]);
  70.     DbSetAdd( CUSTOMER, ADDRESS);
  71.  
  72.     /* Customer 1002 */
  73.     DbRecordAdd( CUSTOMER, &customer[2]);
  74.     DbRecordAdd( ADDRESS, &address[2]);
  75.     DbSetAdd( CUSTOMER, ADDRESS);
  76.     DbRecordAdd( ADDRESS, &address[3]);
  77.     DbSetAdd( CUSTOMER, ADDRESS);
  78.  
  79.     /* Get the first customer by account number */
  80.     DbRecordFindFirst( CUSTOMER, ACCTNBR);
  81.     DbRecordGetCurrent( CUSTOMER, ACCTNBR, &t_customer);
  82.  
  83.     /* Save the currency */
  84.     DbRecordGetCurrency( CUSTOMER, ¤cy);
  85.  
  86.     /* Get the last customer */
  87.     DbRecordGetLast( CUSTOMER, ACCTNBR, &t_customer);
  88.  
  89.     /* Get the addresses */
  90.     DbSetFindFirst( CUSTOMER, ADDRESS);
  91.     DbSetGetFirst( CUSTOMER, ADDRESS, &t_address);
  92.     DbSetGetNext( CUSTOMER, ADDRESS, &t_address);
  93.  
  94.     /* Restore the customer currency and retrieve the current customer */
  95.     DbRecordUpdCurrency( CUSTOMER, ¤cy);
  96.     DbRecordGetCurrent( CUSTOMER, ACCTNBR, &t_customer);
  97.  
  98.     /* Get customer 1001 */
  99.     DbRecordGetByKey( CUSTOMER, ACCTNBR, &t_customer, &acctNbr);
  100.  
  101.     /* Get address */
  102.     DbRecordGetByKey( ADDRESS, ZIP, &t_address, "55555");
  103.  
  104.     /* Get the owner of the address */
  105.     DbSetGetOwner( CUSTOMER, ADDRESS, &t_customer);
  106.  
  107.     DbFlush();
  108.     DbClose();
  109.     }
  110.