home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / oledb / tablecopy / tablecopy.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-12  |  3.4 KB  |  134 lines

  1. //-----------------------------------------------------------------------------
  2. // Microsoft OLE DB TABLECOPY Sample
  3. // Copyright (C) 1995-1998 Microsoft Corporation
  4. //
  5. // @doc
  6. //
  7. // @module TABLECOPY.CPP
  8. //
  9. //-----------------------------------------------------------------------------
  10.  
  11.  
  12. /////////////////////////////////////////////////////////////////
  13. // Includes
  14. //
  15. /////////////////////////////////////////////////////////////////
  16. #define DBINITCONSTANTS  //Initilaizes OLEDB Guids / Constants
  17. #define INITGUID
  18.  
  19. #include "winmain.h"
  20. #include "common.h"
  21. #include "tablecopy.h"
  22. #include "table.h"
  23. #include "wizard.h"
  24.  
  25. #include "msdaguid.h"    //CLSID_OLEDB_ENUMERATOR
  26.  
  27.  
  28.  
  29. /////////////////////////////////////////////////////////////////
  30. // CTableCopy::CTableCopy
  31. //
  32. /////////////////////////////////////////////////////////////////
  33. CTableCopy::CTableCopy(CWizard* pCWizard)
  34. {
  35.     ASSERT(pCWizard);
  36.  
  37.     m_pCFromTable    = new CTable(pCWizard);
  38.     m_pCToTable        = new CTable(pCWizard);
  39.  
  40.     //RowOptions
  41.     m_dwRowOpt        = IDR_ALL_ROWS;
  42.     m_ulMaxRows        = 1;
  43.     
  44.     //InsertOptions
  45.     m_dwInsertOpt    = IDR_PARAM_SETS;
  46.     m_ulParamSets    = 10;
  47.     
  48.     //BLOB options
  49.     m_dwBlobOpt        = IDR_BLOB_SIZE;
  50.     m_ulBlobSize    = 5000;        //Some reasonable value less than MAX_COL_SIZE
  51.  
  52.     //Create Options
  53.     m_fCopyTables        = TRUE;    
  54.     m_fCopyIndexes        = TRUE;
  55.     m_fCopyPrimaryKeys    = TRUE;
  56.     m_fShowQuery        = FALSE;
  57.  
  58.     //Data
  59.     m_fTranslate    = TRUE;
  60.     m_pCWizard        = pCWizard;  //Back pointer to windowing class
  61. }
  62.  
  63.  
  64. /////////////////////////////////////////////////////////////////
  65. // CTableCopy::~CTableCopy
  66. //
  67. /////////////////////////////////////////////////////////////////
  68. CTableCopy::~CTableCopy()
  69. {
  70.     delete m_pCFromTable;
  71.     delete m_pCToTable;
  72. }
  73.  
  74.  
  75.  
  76.  
  77. /////////////////////////////////////////////////////////////////
  78. // HRESULT CTableCopy::MapTypes
  79. //
  80. /////////////////////////////////////////////////////////////////
  81. HRESULT CTableCopy::MapTypes()
  82. {
  83.     HRESULT hr = S_OK;
  84.  
  85.     //Now get the TypeInfo for all columns
  86.     //IDBSchemaRowsets may not be supported, which we may be able to do without
  87.     //on the source table, we are going to lose IsNullable, IsAutoInc and other options
  88.     hr = m_pCFromTable->GetTypeInfo();
  89.     
  90.     //Now map all the Types correctly from the Source to the Target
  91.     QTESTC(hr = m_pCToTable->MapTableInfo(m_pCFromTable));
  92.         
  93. CLEANUP:
  94.     if(FAILED(hr))
  95.         wMessageBox(NULL, MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OK, wsz_ERROR, wsz_TYPEMAPPING_FAILURE);
  96.  
  97.     return hr;
  98. }
  99.  
  100.  
  101.  
  102. ///////////////////////////////////////////////////////////////////////
  103. // HRESULT CTableCopy::CopyTables
  104. //
  105. ///////////////////////////////////////////////////////////////////////
  106. HRESULT CTableCopy::CopyTables()
  107. {
  108.     HRESULT hr = S_OK;
  109.     ULONG cRowsCopied = 0;
  110.  
  111.     // Create the Table (if desired)
  112.     if(m_fCopyTables)
  113.         QTESTC(hr = m_pCToTable->CreateTable());
  114.  
  115.     // Create the indexes (if desired)
  116.     if(m_fCopyIndexes)
  117.         QTESTC(hr = m_pCToTable->CopyIndexes(m_pCFromTable));
  118.  
  119.     //GetColInfo for TargetTable
  120.     QTESTC(hr = m_pCToTable->GetColInfo(m_dwInsertOpt));
  121.     
  122.     //Now Copy the Data
  123.     QTESTC(hr = m_pCToTable->CopyData(m_pCFromTable, &cRowsCopied));
  124.  
  125. CLEANUP:
  126.     //Display Results
  127.     if(SUCCEEDED(hr))
  128.         wMessageBox(NULL, MB_TASKMODAL | MB_ICONINFORMATION | MB_OK, wsz_SUCCESS, wsz_COPY_SUCCESS, cRowsCopied);
  129.     else
  130.         wMessageBox(NULL, MB_TASKMODAL | MB_ICONEXCLAMATION | MB_OK, wsz_ERROR, wsz_COPY_FAILURE);
  131.  
  132.     return hr;
  133. }
  134.