clusteredx.cpp

来自「visual c++ 很全的ado的sample」· C++ 代码 · 共 96 行

CPP
96
字号
#import "c:\Program Files\Common Files\system\ado\msadox.dll" \
    no_namespace

#include "iostream.h"
#include "stdio.h"
#include "conio.h"

//Function declarations
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void ClusteredX(void);

//////////////////////////////////////////////////////////
//                                                      //
//     Main Function                                    //
//                                                      //
//////////////////////////////////////////////////////////
void main()
{
    if(FAILED(::CoInitialize(NULL)))
        return;

    ClusteredX();

    ::CoUninitialize();
}

//////////////////////////////////////////////////////////
//                                                      //
//       ClusteredX Function                            //
//                                                      //
//////////////////////////////////////////////////////////
void ClusteredX()
{
    HRESULT hr = S_OK;

    // Define ADOX object pointers.
    // Initialize pointers on define.
    // These are in the ADOX::  namespace.
    _CatalogPtr m_pCatalog = NULL;
    _TablePtr m_pTable = NULL;
    _IndexPtr m_pIndex = NULL;

    //Define other variables here
    _variant_t vIndex;
    try
    {
        TESTHR(hr = m_pCatalog.CreateInstance(__uuidof(Catalog)));

        // Connect to the catalog.
        m_pCatalog->PutActiveConnection(
            "Provider=Microsoft.Jet.OLEDB.4.0;data source="
            "c:\\Program Files\\Microsoft Office\\Office\\Samples"
            "\\Northwind.mdb;");

        int iLineCnt = 1; 
        //Enumerate Tables.
        for(short iTable = 0;iTable < m_pCatalog->Tables->Count;iTable++)
        {
            vIndex = iTable;
            m_pTable = m_pCatalog->Tables->GetItem(vIndex);

            //Enumerate Indexes.
            for(short iIndex = 0;iIndex < m_pTable->Indexes->Count;
                iIndex++)
            {
                vIndex = iIndex;
                m_pIndex = m_pTable->Indexes->GetItem(vIndex);
                cout << m_pTable->Name << "   " ;
                cout << m_pIndex->Name << "   " << (m_pIndex->
                    GetClustered() ? "True" : "False") << endl;

                 if (iLineCnt%15 == 0)
                {
                    printf("\nPress any key to continue...\n");
                    getch();
                }
                iLineCnt++;
            }
        }
    }
    catch(_com_error &e)
    {
        // Notify the user of errors if any.
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());

        printf("\n\tSource :  %s \n\tdescription : %s \n ",
            (LPCSTR)bstrSource,(LPCSTR)bstrDescription);
    }

    catch(...)
    {
        cout << "Error occured in include files...."<< endl;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?