home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / orient / Linux / demo / countCustomer.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-15  |  1.3 KB  |  59 lines

  1. #ifdef COMP_BCB
  2. // BORLAND C++ BUILDER INCLUDES
  3. #include <condefs.h>
  4. #else
  5. #define USELIB( arg )
  6. #endif
  7.  
  8.  
  9. //---------------------------------------------------------------------------
  10. // CUSTOM DATABASE HEADER
  11. #include "business.h"
  12. //---------------------------------------------------------------------------
  13. #include <stdio.h>
  14. //---------------------------------------------------------------------------
  15. // BORLAND C++ BUILDER DIRECTIVES
  16. USELIB("..\..\..\lib\win32\bcb\ojust.lib");
  17. //---------------------------------------------------------------------------
  18. int main(int argc, char* argv[])
  19. {
  20.   // START TRY/CATCH BLOCK FOR EXCEPTIONS CATCHING
  21.   try
  22.   {
  23.     d_Database    db;
  24.     d_Transaction tx;
  25.  
  26.       // OPEN DATABASE
  27.       db.open( "database/business" );
  28.  
  29.     // START TRANSACTION
  30.     tx.begin();
  31.  
  32.     d_Extent<Customer>    customers( &db );
  33.  
  34.     cout << "Total objects in <Customer> class are: ";
  35.  
  36.     if( argc == 1 )
  37.       cout << customers.cardinality() << endl;
  38.     else
  39.       cout << customers.count( argv[1] ) << endl;
  40.       
  41.     // COMMIT TRANSACTION
  42.     tx.commit();
  43.   }
  44.   catch( d_Error &e )
  45.   {
  46.     // DATABASE ERROR
  47.       cout << "Database error: " << e.what() << endl;
  48.   }
  49.   catch( ... )
  50.   {
  51.     // APPLICATION ERROR
  52.       cout << "Generic error" << endl;
  53.   }
  54.  
  55.   return 0;
  56. }
  57.  
  58.  
  59.