| 314 | } |
| 315 | |
| 316 | bool DsqlCursor::cacheInput(thread_db* tdbb, FB_UINT64 position) |
| 317 | { |
| 318 | fb_assert(!m_eof); |
| 319 | |
| 320 | const ULONG prefetchCount = MAX(PREFETCH_SIZE / m_message->msg_length, 1); |
| 321 | const UCHAR* const msgBuffer = m_dsqlRequest->req_msg_buffers[m_message->msg_buffer_number]; |
| 322 | |
| 323 | while (position >= m_cachedCount) |
| 324 | { |
| 325 | for (ULONG count = 0; count < prefetchCount; count++) |
| 326 | { |
| 327 | if (!m_dsqlRequest->fetch(tdbb, NULL)) |
| 328 | { |
| 329 | m_eof = true; |
| 330 | break; |
| 331 | } |
| 332 | |
| 333 | const FB_UINT64 offset = m_cachedCount * m_message->msg_length; |
| 334 | const FB_UINT64 writtenBytes = m_space.write(offset, msgBuffer, m_message->msg_length); |
| 335 | fb_assert(writtenBytes == m_message->msg_length); |
| 336 | m_cachedCount++; |
| 337 | } |
| 338 | |
| 339 | if (m_eof) |
| 340 | break; |
| 341 | } |
| 342 | |
| 343 | return (position < m_cachedCount); |
| 344 | } |