home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CDB114.ZIP / TEST.C < prev    next >
Text File  |  1991-03-15  |  6KB  |  202 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.     if( DbRecordAdd( CUSTOMER, &customer[0]))
  64.         {
  65.         printf( "Call: DbRecordAdd( CUSTOMER, &customer[0]))\n");
  66.         exit( 1);
  67.         }
  68.     if( DbRecordAdd( ADDRESS, &address[0]))
  69.         {
  70.         printf( "Call: DbRecordAdd( ADDRESS, &address[0]))\n");
  71.         exit( 1);
  72.         }
  73.     if( DbSetAdd( CUSTOMER, ADDRESS))
  74.         {
  75.         printf( "Call: DbSetAdd( CUSTOMER, ADDRESS))\n");
  76.         exit( 1);
  77.         }
  78.  
  79.     /* Customer 1001 */
  80.     if( DbRecordAdd( CUSTOMER, &customer[1]))
  81.         {
  82.         printf( "Call: DbRecordAdd( CUSTOMER, &customer[1]))\n");
  83.         exit( 1);
  84.         }
  85.     if( DbRecordAdd( ADDRESS, &address[1]))
  86.         {
  87.         printf( "Call: DbRecordAdd( ADDRESS, &address[1]))\n");
  88.         exit( 1);
  89.         }
  90.     if( DbSetAdd( CUSTOMER, ADDRESS))
  91.         {
  92.         printf( "Call: DbSetAdd( CUSTOMER, ADDRESS))\n");
  93.         exit( 1);
  94.         }
  95.  
  96.     /* Customer 1002 */
  97.     if( DbRecordAdd( CUSTOMER, &customer[2]))
  98.         {
  99.         printf( "Call: DbRecordAdd( CUSTOMER, &customer[2]))\n");
  100.         exit( 1);
  101.         }
  102.     if( DbRecordAdd( ADDRESS, &address[2]))
  103.         {
  104.         printf( "Call: DbRecordAdd( ADDRESS, &address[2]))\n");
  105.         exit( 1);
  106.         }
  107.     if( DbSetAdd( CUSTOMER, ADDRESS))
  108.         {
  109.         printf( "Call: DbSetAdd( CUSTOMER, ADDRESS))\n");
  110.         exit( 1);
  111.         }
  112.     if( DbRecordAdd( ADDRESS, &address[3]))
  113.         {
  114.         printf( "Call: DbRecordAdd( ADDRESS, &address[3]))\n");
  115.         exit( 1);
  116.         }
  117.     if( DbSetAdd( CUSTOMER, ADDRESS))
  118.         {
  119.         printf( "Call: DbSetAdd( CUSTOMER, ADDRESS))\n");
  120.         exit( 1);
  121.         }
  122.  
  123.     /* Get the first customer by account number */
  124.     if( DbRecordFindFirst( CUSTOMER, ACCTNBR))
  125.         {
  126.         printf( "Call: DbRecordFindFirst( CUSTOMER, ACCTNBR))\n");
  127.         exit( 1);
  128.         }
  129.     if( DbRecordGetCurrent( CUSTOMER, ACCTNBR, &t_customer))
  130.         {
  131.         printf( "Call: DbRecordGetCurrent( CUSTOMER, ACCTNBR, &t_customer))\n");
  132.         exit( 1);
  133.         }
  134.  
  135.     /* Save the currency */
  136.     if( DbRecordGetCurrency( CUSTOMER, ¤cy))
  137.         {
  138.         printf( "Call: DbRecordGetCurrency( CUSTOMER, ¤cy))\n");
  139.         exit( 1);
  140.         }
  141.  
  142.     /* Get the last customer */
  143.     if( DbRecordGetLast( CUSTOMER, ACCTNBR, &t_customer))
  144.         {
  145.         printf( "Call: DbRecordGetLast( CUSTOMER, ACCTNBR, &t_customer))\n");
  146.         exit( 1);
  147.         }
  148.  
  149.     /* Get the addresses */
  150.     if( DbSetFindFirst( CUSTOMER, ADDRESS))
  151.         {
  152.         printf( "Call: DbSetFindFirst( CUSTOMER, ADDRESS))\n");
  153.         exit( 1);
  154.         }
  155.     if( DbSetGetFirst( CUSTOMER, ADDRESS, &t_address))
  156.         {
  157.         printf( "Call: DbSetGetFirst( CUSTOMER, ADDRESS, &t_address))\n");
  158.         exit( 1);
  159.         }
  160.     if( DbSetGetNext( CUSTOMER, ADDRESS, &t_address))
  161.         {
  162.         printf( "Call: DbSetGetNext( CUSTOMER, ADDRESS, &t_address))\n");
  163.         exit( 1);
  164.         }
  165.  
  166.     /* Restore the customer currency and retrieve the current customer */
  167.     if( DbRecordUpdCurrency( CUSTOMER, ¤cy))
  168.         {
  169.         printf( "Call: DbRecordUpdCurrency( CUSTOMER, ¤cy))\n");
  170.         exit( 1);
  171.         }
  172.     if( DbRecordGetCurrent( CUSTOMER, ACCTNBR, &t_customer))
  173.         {
  174.         printf( "Call: DbRecordGetCurrent( CUSTOMER, ACCTNBR, &t_customer))\n");
  175.         exit( 1);
  176.         }
  177.  
  178.     /* Get customer 1001 */
  179.     if( DbRecordGetByKey( CUSTOMER, ACCTNBR, &t_customer, &acctNbr))
  180.         {
  181.         printf( "Call: DbRecordGetByKey( CUSTOMER, ACCTNBR, &t_customer, &acctNbr))\n");
  182.         exit( 1);
  183.         }
  184.  
  185.     /* Get address */
  186.     if( DbRecordGetByKey( ADDRESS, ZIP, &t_address, "55555"))
  187.         {
  188.         printf( "Call: DbRecordGetByKey( ADDRESS, ZIP, &t_address, \"55555\"))\n");
  189.         exit( 1);
  190.         }
  191.  
  192.     /* Get the owner of the address */
  193.     if( DbSetGetOwner( CUSTOMER, ADDRESS, &t_customer))
  194.         {
  195.         printf( "Call: DbSetGetOwner( CUSTOMER, ADDRESS, &t_customer))\n");
  196.         exit( 1);
  197.         }
  198.  
  199.     DbFlush();
  200.     DbClose();
  201.     }
  202.