More nvarchar(max) columns in one table

  • Hi,

    I am using MS SQL 2008 and the MS SQL native client ole db interface. My program is writen in C++.

    I have more than one nvarchar(max) columns in one table. I would like to read them. Accoding to MS SQL help, I should use the ISequentialStream Interface. That works also for one column. But if there are more than one columns in a table, it doesnot work any more. Does anyone know how can I fix it?

    Many thanks!

  • wenna.geyer (4/12/2010)


    Hi,

    I am using MS SQL 2008 and the MS SQL native client ole db interface. My program is writen in C++.

    I have more than one nvarchar(max) columns in one table. I would like to read them. Accoding to MS SQL help, I should use the ISequentialStream Interface. That works also for one column. But if there are more than one columns in a table, it doesnot work any more. Does anyone know how can I fix it?

    Many thanks!

    Hard to say without seeing your source code, how about using multiple instances of ISequentialStream?

  • Sorry, there is too much code. Here is just a part of the IAccessor of the columns and the IOpenRowset for the results.

    HRESULT hr = p_pIRowset->QueryInterface(IID_IColumnsInfo, (void **)&pIColumnsInfo);

    if (SUCCEEDED(hr))

    {

    // Retrieve the column information.

    pIColumnsInfo->GetColumnInfo(&dwNumCols, &pDBColumnInfo, &pStringsBuffer);

    // Free the column information interface.

    //pIColumnsInfo->Release();

    pIColumnsInfo = NULL;

    SQL_ACCESSOR sColAccessor;

    sColAccessor.m_ulOffset = 0;

    std::vector<DBBINDING> rgBindings4Col;

    rgBindings4Col.reserve(dwNumCols);

    // Using the ColumnInfo structure, fill out the pBindings array.

    for (DWORD dwColumn = 0 ; dwColumn < dwNumCols ; dwColumn ++ )

    {

    rgBindings4Col[dwColumn].iOrdinal = pDBColumnInfo[dwColumn].iOrdinal;

    rgBindings4Col[dwColumn].dwPart = DBPART_VALUE | DBPART_LENGTH| DBPART_STATUS;

    rgBindings4Col[dwColumn].dwMemOwner = DBMEMOWNER_CLIENTOWNED;

    rgBindings4Col[dwColumn].eParamIO = DBPARAMIO_NOTPARAM;

    rgBindings4Col[dwColumn].pBindExt = NULL;

    rgBindings4Col[dwColumn].bPrecision = pDBColumnInfo[dwColumn].bPrecision;

    rgBindings4Col[dwColumn].bScale = pDBColumnInfo[dwColumn].bScale;

    rgBindings4Col[dwColumn].pTypeInfo = NULL;

    rgBindings4Col[dwColumn].dwFlags = 0;

    if(DBTYPE_IUNKNOWN == pDBColumnInfo[dwColumn].wType ||

    (pDBColumnInfo[dwColumn].dwFlags & DBCOLUMNFLAGS_ISLONG) )

    {

    // Create the DBBINDING, requesting a storage-object pointer from

    // The SQL Server Native Client OLE DB provider.

    rgBindings4Col[dwColumn].pObject = (DBOBJECT *)CoTaskMemAlloc(sizeof(DBOBJECT));

    // Set up the DBOBJECT structure.

    rgBindings4Col[dwColumn].pObject->dwFlags = STGM_READ;

    rgBindings4Col[dwColumn].pObject->iid = IID_ISequentialStream;

    rgBindings4Col[dwColumn].cbMaxLen = sizeof(ISequentialStream *);

    rgBindings4Col[dwColumn].wType = DBTYPE_IUNKNOWN;

    }

    else

    {

    rgBindings4Col[dwColumn].wType = pDBColumnInfo[dwColumn].wType;

    rgBindings4Col[dwColumn].cbMaxLen = (pDBColumnInfo[dwColumn].wType == DBTYPE_WSTR) ? (pDBColumnInfo[dwColumn].ulColumnSize + 1) * sizeof(WCHAR) : pDBColumnInfo[dwColumn].ulColumnSize;

    }

    rgBindings4Col[dwColumn].obStatus = sColAccessor.m_ulOffset;

    sColAccessor.m_ulOffset += sizeof(DBSTATUS);

    rgBindings4Col[dwColumn].obLength = sColAccessor.m_ulOffset;

    sColAccessor.m_ulOffset += sizeof(ULONG);

    rgBindings4Col[dwColumn].obValue = sColAccessor.m_ulOffset;

    sColAccessor.m_ulOffset += rgBindings4Col[dwColumn].cbMaxLen;

    }

    // Get the IAccessor interface.

    if(m_vecColumnAccessor.size()<=p_dwRowsetNum)

    {

    //save the IAccessor interface in the vector for future use

    m_vecColumnAccessor.push_back(sColAccessor);

    hr = p_pIRowset->QueryInterface(IID_IAccessor, (void **) &sColAccessor.m_pIAccessor);

    if (SUCCEEDED(hr) && sColAccessor.m_pIAccessor)

    {

    // Create an accessor from the set of bindings (pBindings).

    hr = sColAccessor.m_pIAccessor->CreateAccessor(DBACCESSOR_ROWDATA, dwNumCols, &rgBindings4Col[0], sColAccessor.m_ulOffset, &sColAccessor.m_hAccessor, NULL);

    if(SUCCEEDED(hr))

    {

    BYTE * pBuffer = new BYTE[m_vecColumnAccessor[p_dwRowsetNum].m_ulOffset];

    HROW* hRows = new HROW[dwNumRows2Get];

    HROW* pRows = &hRows[0];

    hr = p_pIRowset->GetNextRows(DB_NULL_HCHAPTER, lRowOffset, dwNumRows2Get, &dwNumRowsRetrieved, &pRows);

    for ( DWORD j = 0 ; j < dwNumRowsRetrieved ; j++ )

    {

    // Get the row data values.

    hr2 = p_pIRowset->GetData(hRows[j], m_vecColumnAccessor[p_dwNumOfRows].m_hAccessor, pBuffer);

    here it returns E_NOINTERFACE

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply