使用 CDynamicAccessor 连接数据库时如何判断列是 text 还是 ntext?

发布于 2024-08-03 00:16:24 字数 231 浏览 4 评论 0原文

我有一个 C++ 应用程序使用 CDynamicAccessor 连接到 MS SQL Server 2005。 当我的列是 text 或 ntext 时,CDynamicAccessor::GetColumnType 始终返回 DBTYPE_IUNKNOWN。我可以将数据绑定为 ISequentialStream 并读取字节流。但是,我如何判断我正在读取的列是 text 还是 ntext,从而将字节流解释为 ASCII 还是 Unicode?

I'm having a C++ application connecting to the MS SQL Server 2005 using CDynamicAccessor.
When my column is text or ntext, the CDynamicAccessor::GetColumnType always return DBTYPE_IUNKNOWN. I can bind the data as ISequentialStream and read the byte stream out. However, how can I tell if the column that I'm reading is text or ntext, and hence, to interpret the byte stream as ASCII or Unicode?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天赋异禀 2024-08-10 00:16:24

CDynamicAccessor 类用 DBTYPE_UNKNOWN 覆盖该列的原始 DBTYPE 值。为了获得原始的DBTYPE,我们需要调用GetColumnInfo函数。如何执行此操作的一个示例是 Visual Studio 2008 示例中包含的 DynamicConsumer 示例应用程序:

// the following case will handle BLOBs binded as ISequentialStream/IStream pointer
if( dbtype == DBTYPE_IUNKNOWN )
{
    // first we have to determine what was the column's type originally reported by the provider
    CComHeapPtr<DBCOLUMNINFO> spColumnInfo;
    CComHeapPtr<OLECHAR> spStringsBuffer;
    DBORDINAL nColumns = 0;
    HRESULT hres = rs.CDynamicAccessor::GetColumnInfo( rs.m_spRowset, &nColumns, &spColumnInfo, &spStringsBuffer );
    ATLASSERT( SUCCEEDED( hres ) );
    ATLASSERT( col <= nColumns );
    DBTYPE wType = spColumnInfo[col-1].wType;
    ...
}

替代解决方案是将 CDynamicAccessor 设置为 DBBLOBHANDLING_NOSTREAMS,这似乎会导致处理数据加载的代码更加简单(您可以在完整的 VS2008 示例代码)。
但是,我不确定为什么使用流是默认选项,以及不使用流是否有任何缺点。

The CDynamicAccessor class overwrites the original DBTYPE value of the column with DBTYPE_UNKNOWN. In order to get the original DBTYPE, we need to call the GetColumnInfo function. An example of how to do this is the DynamicConsumer sample application included in the Visual Studio 2008 samples:

// the following case will handle BLOBs binded as ISequentialStream/IStream pointer
if( dbtype == DBTYPE_IUNKNOWN )
{
    // first we have to determine what was the column's type originally reported by the provider
    CComHeapPtr<DBCOLUMNINFO> spColumnInfo;
    CComHeapPtr<OLECHAR> spStringsBuffer;
    DBORDINAL nColumns = 0;
    HRESULT hres = rs.CDynamicAccessor::GetColumnInfo( rs.m_spRowset, &nColumns, &spColumnInfo, &spStringsBuffer );
    ATLASSERT( SUCCEEDED( hres ) );
    ATLASSERT( col <= nColumns );
    DBTYPE wType = spColumnInfo[col-1].wType;
    ...
}

The alternative solution is to set the CDynamicAccessor to DBBLOBHANDLING_NOSTREAMS, which seems to result in much less complicated code to handle data loading (you can see this in the full VS2008 sample code).
However, I'm not sure why using stream is the default option, and if there is any disadvantages with using no streams.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文