What is the OleDb equivalent for INFORMATION_SCHEMA

二次信任 提交于 2019-12-10 17:21:19

问题


In SQL you can use

SELECT * FROM INFORMATION_SCHEMA.TABLES

etc to get information about the database structure. I need to know how to achieve the same thing for an Access database.


回答1:


The equivalent operation can be accomplished using

OleDbConnection.GetOleDbSchemaTable() method.

see http://support.microsoft.com/kb/309488 for more information




回答2:


In OLEDB it can be accessed as DBSCHEMA_TABLES. Following C++ code demonstrates the retrieval of the tables information from an OLEDB provider:

#include <atldb.h>
...
        // Standard way of obtaining table node info.
        CAccessorRowset<CDynamicAccessor, CBulkRowset> pRS;
        pRS.SetRows(100);

        CSchemaTables<CSession>* pBogus;
        hr = session.CreateSchemaRowset(NULL, 0, NULL, IID_IRowset, 0, NULL, (IUnknown**)&pRS.m_spRowset, pBogus);
        if (FAILED(hr))
            goto lblError;

        hr = pRS.Bind();
        if (FAILED(hr))
            goto lblError;

        hr = pRS.MoveFirst();
        if (FAILED(hr))
            goto lblError;

        while (S_OK == hr)
        {
            wstring sTableSchema(pRS.GetWCharValue(L"TABLE_SCHEMA"));
            wstring sTableName(pRS.GetWCharValue(L"TABLE_NAME"));
            wstring sTableType(pRS.GetWCharValue(L"TABLE_TYPE"));
            ...

            hr = pRS.MoveNext(); 
        }
        pRS.Close();


来源:https://stackoverflow.com/questions/117974/what-is-the-oledb-equivalent-for-information-schema

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!