home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / orient / Linux / demo / selectCustomer.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-15  |  1.8 KB  |  75 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.  
  19. //---------------------------------------------------------------------------
  20. int main(int argc, char* argv[])
  21. {
  22.   char    query[100];
  23.  
  24.   if( argc > 1 )
  25.     sprintf( query, "Customer.code = %d", atoi( argv[1] ) );
  26.   else
  27.     query[0] = 0;
  28.  
  29.   // START TRY/CATCH BLOCK FOR EXCEPTIONS CATCHING
  30.   try
  31.   {
  32.     d_Database    db;
  33.     d_Transaction tx;
  34.  
  35.       // OPEN DATABASE
  36.       db.open( "database/business" );
  37.  
  38.     // START TRANSACTION
  39.     tx.begin();
  40.  
  41.     d_Ref<Customer>                objCustomer;
  42.     d_Iterator< d_Ref<Customer> >  itCustomer;
  43.     d_Extent<Customer>             customers( &db );
  44.  
  45.     itCustomer = customers.select( query );
  46.  
  47.     while( itCustomer.next( objCustomer ) )
  48.     {
  49.       // DISPLAY OBJECT
  50.       cout << "\nCode......: " << objCustomer->code;
  51.       cout << "\nName......: " << objCustomer->name;
  52.       cout << "\nSurname...: " << objCustomer->surname;
  53.       cout << "\nAge.......: " << objCustomer->age;
  54.       cout << "\nNotes.....: " << objCustomer->notes;
  55.     }
  56.  
  57.     // COMMIT TRANSACTION
  58.     tx.commit();
  59.   }
  60.   catch( d_Error &e )
  61.   {
  62.     // DATABASE ERROR
  63.       cout << "Database error: " << e.what() << endl;
  64.   }
  65.   catch( ... )
  66.   {
  67.     // APPLICATION ERROR
  68.       cout << "Generic error" << endl;
  69.   }
  70.  
  71.   return 0;
  72. }
  73.  
  74.  
  75.