protected QueryResultPart GetResultPart(int resultId, int startRow, int countRows)
{
AssertNotDisposed();
QueryResult table = GetResult(resultId);
if (table == null)
{
throw new DatabaseException("'resultId' invalid.");
}
int rowEnd = startRow + countRows;
if (startRow < 0 || startRow >= table.RowCount ||
rowEnd > table.RowCount)
{
throw new DatabaseException("Result part out of range.");
}
try {
int colCount = table.ColumnCount;
var block = new QueryResultPart(colCount);
for (int r = startRow; r < rowEnd; ++r)
{
var row = new object[colCount];
for (int c = 0; c < colCount; ++c)
{
TObject value = table.GetCellContents(c, r);
// If this is a IRef, we must assign it a streamable object
// id that the client can use to access the large object.
object clientOb;
if (value.Object is IRef)
{
var reference = (IRef)value.Object;
clientOb = new StreamableObject(reference.Type, reference.RawSize, reference.Id);
}
else
{
clientOb = value.Object;
}
row[c] = clientOb;
}
block.AddRow(row);
}
return(block);
} catch (Exception e) {
Logger.Warning(this, e);
// If an exception was generated while getting the cell contents, then
// throw an DataException.
throw new DatabaseException("Exception while reading results: " + e.Message, e);
}
}