?
Solved

LPMAPITABLE QueryRows does not return all rows to SRowSet

Posted on 2003-03-14
5
Medium Priority
?
884 Views
Last Modified: 2012-08-14
Good-day,
I am having a problem with LPMAPITABLE::QueryRows not returning all available rows to the SRowSet object.  Here is a snippet of code that seems to work great for folders that are under 100 emails or so.  When trying to access a folder that has a large number of emails, the assert on the last line will fail. The QueryRows() does not seem to obtain all of the availible rows when trying to retreive many emails.

************************
  LPMAPIFOLDER pFolder = NULL;
    hr = HrMAPIOpenFolderEx(pDefMsgStore,
       '\\',
       Folder,
       &pFolder);
    if (FAILED(hr)) throw -1;

    // Get contents table.
    LPMAPITABLE pContentsTable = NULL;
     hr = pFolder->GetContentsTable(0, &pContentsTable);
    if (FAILED(hr)) throw -1;

    // Get row count
    ULONG ulRows = 0;
    hr = pContentsTable->GetRowCount(0, &ulRows);
    if (FAILED(hr)) throw -1;
     
    assert(ulRows > 0);

    // Get all rows
    SRowSet * pRowSet = NULL;

     hr = pContentsTable->QueryRows(ulRows,0 ,&pRowSet);
     
   assert(ulRows == pRowSet->cRows);
***********************************

I am guessing that I will need to call QueryRows again and somehow merge it to another SRowSet, but I'm not sure how to do this, (or if it is even possible).
Any help would be appriciated.
Thanks.
0
Comment
Question by:PastorDwayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:Hermetic
ID: 8139284
Straight from the MSDN Library for GetRowCount:
Notes to Callers
Use GetRowCount to find out how many rows a table holds before making a call to the IMAPITable::QueryRows method to retrieve the data. If there are less than twenty rows in the table, it is safe to call QueryRows to retrieve the whole table. If there are more than twenty rows in the table, consider making multiple calls to QueryRows and limit the number of rows retrieved in each call.

According to the documentation, when you call QueryRows,
it sets an internal pointer.  You can call QueryRows again and it should just start from where you left off.
0
 

Author Comment

by:PastorDwayne
ID: 8139317
Would I have to create a new SRowSet pointer, or could I use the original one..  Using the example above, could you give a rough idea of how to implement this into my code?
0
 
LVL 1

Expert Comment

by:Hermetic
ID: 8139601
It depends on exactly what you are doing with the rows but I will attempt an example:

---------------------------------YOUR CODE
   // Get row count
   ULONG ulRows = 0;
   hr = pContentsTable->GetRowCount(0, &ulRows);
   if (FAILED(hr)) throw -1;
   
   assert(ulRows > 0);

   // Get all rows
   SRowSet * pRowSet = NULL;
   
//---------CHANGES
   ULONG ulCurRows = 0;
   ULONG ulCumulativeRowCount = 0;
   do
   {
      hr = pContentsTable->QueryRows(20, 0 ,&pRowSet);
      //Do something with the rowset.
      //Whatever you do, it will have to store it's own
      //copy of the information because you are about
      //to free it.
      ulCumulativeRowCount += pRowSet->cRows;
      FreeProws(pRowSet);
   } while (pRowSet->cRows > 0)
   
  assert(ulRows == ulCumulativeRowCount);
//---------END CHANGES
***********************************
---------------------------------YOUR CODE
0
 
LVL 1

Accepted Solution

by:
Hermetic earned 1000 total points
ID: 8139621
sorry.  I realized that I had made a mistake.
replace the do loop with this:
ULONG ulRowsRetrieved = 0;
  do
  {
     hr = pContentsTable->QueryRows(20, 0 ,&pRowSet);
     //Do something with the rowset.
     //Whatever you do, it will have to store it's own
     //copy of the information because you are about
     //to free it.
     ulCumulativeRowCount += pRowSet->cRows;
     ulRowsRetrieved = pRowSet->cRows;
     FreeProws(pRowSet);
  } while (ulRowsRetrieved > 0)
0
 

Author Comment

by:PastorDwayne
ID: 8142502
Thanks Hermetic; That seemed to do the trick...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question