Visual c++ 如何将筛选视图与ATL OLE DB一起使用

Visual c++ 如何将筛选视图与ATL OLE DB一起使用,visual-c++,mfc,oledb,atl,Visual C++,Mfc,Oledb,Atl,我正在开发一个访问mysql数据库的MFC应用程序。对于连接性,我使用ATL模板基于CCommand创建了一个consumer类(没有什么特别之处)。现在我想根据某些标准筛选数据。我知道存在IViewFilter接口。但是,我不知道如何在模板的上下文中实现这一点。搜索互联网不会产生很多有用的结果,也不会产生微软提供的任何相关文档。任何指向正确方向的指针或示例代码都将不胜感激 模板代码: // Orders.h : Declaration of the COrders #pragma once

我正在开发一个访问mysql数据库的MFC应用程序。对于连接性,我使用ATL模板基于
CCommand
创建了一个consumer类(没有什么特别之处)。现在我想根据某些标准筛选数据。我知道存在
IViewFilter
接口。但是,我不知道如何在模板的上下文中实现这一点。搜索互联网不会产生很多有用的结果,也不会产生微软提供的任何相关文档。任何指向正确方向的指针或示例代码都将不胜感激

模板代码:

// Orders.h : Declaration of the COrders

#pragma once

// code generated on dinsdag 15 maart 2016, 13:11

class COrdersAccessor
{
public:
    LONG m_ID;
    TCHAR m_OrderNumber[256];
    TCHAR m_Description[256];
    LONG m_CustID;
    TCHAR m_ServiceNumber[256];
    SHORT m_Year;
    TCHAR m_directory[256];

    // The following wizard-generated data members contain status
    // values for the corresponding fields in the column map. You
    // can use these values to hold NULL values that the database
    // returns or to hold error information when the compiler returns
    // errors. See Field Status Data Members in Wizard-Generated
    // Accessors in the Visual C++ documentation for more information
    // on using these fields.
    // NOTE: You must initialize these fields before setting/inserting data!

    DBSTATUS m_dwIDStatus;
    DBSTATUS m_dwOrderNumberStatus;
    DBSTATUS m_dwDescriptionStatus;
    DBSTATUS m_dwCustIDStatus;
    DBSTATUS m_dwServiceNumberStatus;
    DBSTATUS m_dwYearStatus;
    DBSTATUS m_dwdirectoryStatus;

    // The following wizard-generated data members contain length
    // values for the corresponding fields in the column map.
    // NOTE: For variable-length columns, you must initialize these
    //       fields before setting/inserting data!

    DBLENGTH m_dwIDLength;
    DBLENGTH m_dwOrderNumberLength;
    DBLENGTH m_dwDescriptionLength;
    DBLENGTH m_dwCustIDLength;
    DBLENGTH m_dwServiceNumberLength;
    DBLENGTH m_dwYearLength;
    DBLENGTH m_dwdirectoryLength;


    void GetRowsetProperties(CDBPropSet* pPropSet)
    {
        pPropSet->AddProperty(DBPROP_CANFETCHBACKWARDS, true, DBPROPOPTIONS_OPTIONAL);
        pPropSet->AddProperty(DBPROP_CANSCROLLBACKWARDS, true, DBPROPOPTIONS_OPTIONAL);
        pPropSet->AddProperty(DBPROP_IRowsetChange, true, DBPROPOPTIONS_OPTIONAL);
        pPropSet->AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);
    }

    HRESULT OpenDataSource()
    {
        CDataSource _db;
        HRESULT hr;
// #error Security Issue: The connection string may contain a password
// The connection string below may contain plain text passwords and/or
// other sensitive information. Please remove the #error after reviewing
// the connection string for any security related issues. You may want to
// store the password in some other form or use a different user authentication.
        hr = _db.OpenFromInitializationString(L"Provider=MSDASQL.1;Persist Security Info=False;Data Source=HCPSOrders;Extended Properties=\"DSN=HCPSOrders;\"");
        if (FAILED(hr))
        {
#ifdef _DEBUG
            AtlTraceErrorRecords(hr);
#endif
            return hr;
        }
        return m_session.Open(_db);
    }

    void CloseDataSource()
    {
        m_session.Close();
    }

    operator const CSession&()
    {
        return m_session;
    }

    CSession m_session;

    DEFINE_COMMAND_EX(COrdersAccessor, L" \
    SELECT \
        ID, \
        OrderNumber, \
        Description, \
        CustID, \
        ServiceNumber, \
        Year, \
        directory \
        FROM Orders")


    // In order to fix several issues with some providers, the code below may bind
    // columns in a different order than reported by the provider

    BEGIN_COLUMN_MAP(COrdersAccessor)
        COLUMN_ENTRY_LENGTH_STATUS(1, m_ID, m_dwIDLength, m_dwIDStatus)
        COLUMN_ENTRY_LENGTH_STATUS(2, m_OrderNumber, m_dwOrderNumberLength, m_dwOrderNumberStatus)
        COLUMN_ENTRY_LENGTH_STATUS(3, m_Description, m_dwDescriptionLength, m_dwDescriptionStatus)
        COLUMN_ENTRY_LENGTH_STATUS(4, m_CustID, m_dwCustIDLength, m_dwCustIDStatus)
        COLUMN_ENTRY_LENGTH_STATUS(5, m_ServiceNumber, m_dwServiceNumberLength, m_dwServiceNumberStatus)
        COLUMN_ENTRY_LENGTH_STATUS(6, m_Year, m_dwYearLength, m_dwYearStatus)
        COLUMN_ENTRY_LENGTH_STATUS(7, m_directory, m_dwdirectoryLength, m_dwdirectoryStatus)
    END_COLUMN_MAP()
};

class COrders : public CCommand<CAccessor<COrdersAccessor> >
{
public:
    HRESULT OpenAll()
    {
        HRESULT hr;
        hr = OpenDataSource();
        if (FAILED(hr))
            return hr;
        __if_exists(GetRowsetProperties)
        {
            CDBPropSet propset(DBPROPSET_ROWSET);
            __if_exists(HasBookmark)
            {
                if( HasBookmark() )
                    propset.AddProperty(DBPROP_IRowsetLocate, true);
            }
            GetRowsetProperties(&propset);
            return OpenRowset(&propset);
        }
        __if_not_exists(GetRowsetProperties)
        {
            __if_exists(HasBookmark)
            {
                if( HasBookmark() )
                {
                    CDBPropSet propset(DBPROPSET_ROWSET);
                    propset.AddProperty(DBPROP_IRowsetLocate, true);
                    return OpenRowset(&propset);
                }
            }
        }
        return OpenRowset();
    }

    HRESULT OpenRowset(DBPROPSET *pPropSet = NULL)
    {
        HRESULT hr = Open(m_session, NULL, pPropSet);
#ifdef _DEBUG
        if(FAILED(hr))
            AtlTraceErrorRecords(hr);
#endif
        return hr;
    }

    void CloseAll()
    {
        Close();
        ReleaseCommand();
        CloseDataSource();
    }
};
//Orders.h:记录者声明
#布拉格语一次
//dinsdag 15 maart 2016,13:11生成的代码
类无线存取器
{
公众:
长m_ID;
TCHAR m_订单号[256];
TCHAR m_描述[256];
长m_CustID;
TCHAR m_服务编号[256];
短m_年;
tcharm_目录[256];
//以下向导生成的数据成员包含状态
//列映射中相应字段的值。您可以
//可以使用这些值来保存数据库中包含的空值
//返回或在编译器返回时保留错误信息
//错误。请参阅向导生成的字段状态数据成员
/VisualC++文档中的访问器
//关于使用这些字段。
//注意:在设置/插入数据之前,必须初始化这些字段!
DBSTATUS m_dwIDStatus;
DBSTATUS m_dwOrderNumberStatus;
DBSTATUS m_DWDESCRIPTION STATUS;
DBSTATUS m_dwCustIDStatus;
DBSTATUS m_dwServiceNumberStatus;
DBSTATUS m_dwYearStatus;
DBSTATUS m_dw董事地位;
//以下向导生成的数据成员包含长度
//列映射中相应字段的值。
//注意:对于可变长度列,必须初始化这些列
//设置/插入数据之前的字段!
DBLENGTH m_dwIDLength;
DBLENGTH m_dwOrderNumberLength;
DBLENGTH m_dwDescriptionLength;
DBLENGTH m_dwcustildlength;
DBLENGTH m_dwServiceNumberllength;
DBLENGTH m_dwYearLength;
DBLENGTH m_dwdirectoryLength;
void GetRowsetProperties(CDBPropSet*pPropSet)
{
pPropSet->AddProperty(DBPROP\u CANFETCHBACKWARDS、true、DBPROPOPTIONS\u可选);
pPropSet->AddProperty(DBPROP\u可以向后滚动,true,DBPROPOPTIONS\u可选);
pPropSet->AddProperty(DBPROP\u IRowsetChange,true,DBPROPOPTIONS\u可选);
pPropSet->AddProperty(DBPROP_updateability,DBPROPVAL_UP_CHANGE,DBPROPVAL_UP_INSERT,DBPROPVAL_UP_DELETE);
}
HRESULT OpenDataSource()
{
CDATA数据源\u db;
HRESULT-hr;
//#错误安全问题:连接字符串可能包含密码
//下面的连接字符串可能包含纯文本密码和/或
//其他敏感信息。请在审阅后删除#错误
//任何安全相关问题的连接字符串。您可能需要
//以其他形式存储密码或使用其他用户身份验证。
hr=\u db.OpenFromInitializationString(L“Provider=MSDASQL.1;Persist Security Info=False;Data Source=HCPSOrders;Extended Properties=\“DSN=HCPSOrders;\”);
如果(失败(小时))
{
#ifdef_调试
AtlTraceErrorRecords(hr);
#恩迪夫
返回人力资源;
}
返回m_session.Open(_db);
}
void CloseDataSource()
{
m_session.Close();
}
运算符const CSession&()
{
返回m_会话;
}
C会议m_会议;
定义_命令_EX(CorderAccessor,L“\
挑选\
身份证\
订单号\
描述\
卡斯蒂德\
服务编号\
年\
目录\
从订单中提取)
//为了解决某些提供程序的几个问题,下面的代码可能会绑定
//列的顺序与提供程序报告的顺序不同
开始列映射(COrdersAccessor)
列输入长度状态(1,m\u ID,m\u dwIDLength,m\u dwIDStatus)
列输入长度状态(2,m_OrderNumber,m_dwOrderNumberLength,m_dwOrderNumberStatus)
列输入长度状态(3,m描述,m描述长度,m描述状态)
列输入长度状态(4,m_CustID,m_dwCustIDLength,m_dwCustIDStatus)
列输入长度状态(5,m_服务编号,m_dwServiceNumberLength,m_dwServiceNumberStatus)
列输入长度状态(6,m_Year,m_dwYearLength,m_dwYearStatus)
列\条目\长度\状态(7,m\目录,m\ dwdirectoryLength,m\ dwdirectoryStatus)
结束列映射()
};
类别记录员:公共命令
{
公众:
HRESULT OpenAll()
{
HRESULT-hr;
hr=OpenDataSource();
如果(失败(小时))
返回人力资源;
__如果存在(GetRowsetProperties)
{
CDBPropSet propset(DBPROPSET_行集);
__如果存在(HasBookmark)
{
if(HasBookmark())
AddProperty(DBPROP_IRowsetLocate,true);
}
GetRowsetProperties(&propset);
返回OpenRowset(&propset);
}
__如果不存在(GetRowsetProperties)
{
__如果存在(HasBookmark)
{
if(HasBookmark())
{
CDBPropSet propset(DBPROPSET_行集);
AddProperty(DBPROP_IRowsetLocate,true);
返回OpenRowset(&propset);
}
}
}
返回OpenRowset();
}
HRESULT OpenRowset(DBPROPSET*pPropSet=NULL)
{
HRESULT hr=打开(m_会话,NULL,pPropSet);
#ifdef_调试
如果(失败(小时))
AtlTraceErrorRecords(hr);
#恩迪夫
返回人力资源;
}
void CloseAll()
{
Close();
释放命令();
CloseDataSource();
}
};