MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / fetchRelative

Method fetchRelative

src/jrd/recsrc/Cursor.cpp:368–446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

366}
367
368bool Cursor::fetchRelative(thread_db* tdbb, SINT64 offset) const
369{
370 if (!m_rse->isScrollable())
371 {
372 // error: invalid fetch direction
373 status_exception::raise(Arg::Gds(isc_invalid_fetch_option) << Arg::Str("RELATIVE"));
374 }
375
376 if (!validate(tdbb))
377 return false;
378
379 const auto request = tdbb->getRequest();
380 Impure* const impure = request->getImpure<Impure>(m_impure);
381
382 if (!impure->irsb_active)
383 {
384 // error: invalid cursor state
385 status_exception::raise(Arg::Gds(isc_cursor_not_open));
386 }
387
388 if (!offset)
389 return (impure->irsb_state == POSITIONED);
390
391 const auto buffer = static_cast<const BufferedStream*>(m_root);
392 const auto count = buffer->getCount(tdbb);
393 SINT64 position = impure->irsb_position;
394
395 if (impure->irsb_state == BOS)
396 {
397 if (offset < 0)
398 return false;
399
400 position = offset - 1;
401 }
402 else if (impure->irsb_state == EOS)
403 {
404 if (offset > 0)
405 return false;
406
407 position = count + offset;
408 }
409 else
410 {
411 position += offset;
412 }
413
414 if (position < 0)
415 {
416 impure->irsb_state = BOS;
417 return false;
418 }
419 else if (position >= (SINT64) count)
420 {
421 impure->irsb_state = EOS;
422 return false;
423 }
424
425 ProfilerSelectStopWatcher profilerSelectStopWatcher(tdbb, this,

Callers

nothing calls this directly

Calls 10

raiseFunction · 0.85
GdsClass · 0.85
StrClass · 0.85
isScrollableMethod · 0.80
bumpFetchedMethod · 0.80
validateFunction · 0.70
getRequestMethod · 0.45
getCountMethod · 0.45
locateMethod · 0.45
getRecordMethod · 0.45

Tested by

no test coverage detected