home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / orient / Linux / demo / selectInvoice.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-15  |  2.2 KB  |  89 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.   int     invoice = 0;
  23.  
  24.   if( argc > 1 )
  25.     // GET CUSTOMERS
  26.     invoice = atoi( argv[1] );
  27.  
  28.   // START TRY/CATCH BLOCK FOR EXCEPTIONS CATCHING
  29.   try
  30.   {
  31.     d_Database    db;
  32.     d_Transaction tx;
  33.  
  34.     // OPEN DATABASE
  35.     db.open( "database/business" );
  36.  
  37.     // START TRANSACTION
  38.     tx.begin();
  39.  
  40.     d_Ref<Invoice>                objInvoice;
  41.     d_Iterator< d_Ref<Invoice> >  itInvoice;
  42.     d_Extent<Invoice>             invoices( &db );
  43.     char                          query[100];
  44.     d_Iterator< d_Ref<Product> >  itProduct;
  45.     d_Ref<Product>                objProduct;
  46.     int                           i, k;
  47.  
  48.     /* FORMAT QUERY COMMAND */
  49.     sprintf( query, "Invoice->ownCustomer->code = %d", invoice );
  50.     itInvoice = invoices.select( query );
  51.  
  52.     while( itInvoice.next( objInvoice ) )
  53.     {
  54.       // DISPLAY OBJECT
  55.       cout << endl << endl << "INVOICE:";
  56.       cout << endl << "Number....: " << objInvoice->number;
  57.  
  58.       cout << endl << endl << "CUSTOMER:";
  59.       cout << endl << "Code......: " << objInvoice->ownCustomer->code;
  60.  
  61.       cout << endl << endl << "PRODUCT:";
  62.       itProduct = objInvoice->products.create_iterator();
  63.       while( itProduct.next( objProduct ) )
  64.         // DISPLAY PRODUCT OBJECT
  65.         cout << endl << "\tPrice...: " << objProduct->price;
  66.     }
  67.  
  68.     cout << endl;;
  69.  
  70.     // COMMIT TRANSACTION
  71.     tx.commit();
  72.   }
  73.   catch( d_Error &e )
  74.   {
  75.     // DATABASE ERROR
  76.       cout << "d_Error " << e.what() << endl;
  77.   }
  78.   catch( ... )
  79.   {
  80.     // APPLICATION ERROR
  81.       cout << "ERRORE" << endl;
  82.   }
  83.  
  84.   return 0;
  85. }
  86.  
  87.  
  88.  
  89.