original_string: public static function segmentedFetchFirst($sql, $first, $last, $step, $params = array())
      {
          $result = false;
  
          if ($step > 0) {
              for ($i = $first; $result === false && $i <= $last; $i += $step) {
                  $result = self::fetchOne($sql, array_merge($params, array($i, $i + $step)));
              }
          } else {
              for ($i = $first; $result === false && $i >= $last; $i += $step) {
                  $result = self::fetchOne($sql, array_merge($params, array($i, $i + $step)));
              }
          }
  
          return $result;
      }
code: public static function segmentedFetchFirst($sql, $first, $last, $step, $params = array())
      {
          $result = false;
  
          if ($step > 0) {
              for ($i = $first; $result === false && $i <= $last; $i += $step) {
                  $result = self::fetchOne($sql, array_merge($params, array($i, $i + $step)));
              }
          } else {
              for ($i = $first; $result === false && $i >= $last; $i += $step) {
                  $result = self::fetchOne($sql, array_merge($params, array($i, $i + $step)));
              }
          }
  
          return $result;
      }
code_tokens: public static function segmentedFetchFirst ( $ sql , $ first , $ last , $ step , $ params = array ( ) ) { $ result = false ; if ( $ step > 0 ) { for ( $ i = $ first ; $ result === false && $ i <= $ last ; $ i += $ step ) { $ result = self :: fetchOne ( $ sql , array_merge ( $ params , array ( $ i , $ i + $ step ) ) ) ; } } else { for ( $ i = $ first ; $ result === false && $ i >= $ last ; $ i += $ step ) { $ result = self :: fetchOne ( $ sql , array_merge ( $ params , array ( $ i , $ i + $ step ) ) ) ; } } return $ result ; }
docstring: Performs a `SELECT` statement on a table one chunk at a time and returns the first
  successfully fetched value.
  
  This function will execute a query on one set of rows in a table. If nothing
  is fetched, it will execute the query on the next set of rows and so on until
  the query returns a value.
  
  This function will break up a `SELECT into several smaller `SELECT`s and
  should be used when performing a `SELECT` that can take a long time to finish.
  Using several smaller `SELECT`s will ensure that the table will not be locked
  for too long.
  
  **Example**
  
  // find the most recent visit that is older than a certain date
  $dateStart = // ...
  $sql = "SELECT idvisit
  FROM $logVisit
  WHERE '$dateStart' > visit_last_action_time
  AND idvisit <= ?
  AND idvisit > ?
  ORDER BY idvisit DESC
  LIMIT 1";
  
  // since visits
  return Db::segmentedFetchFirst($sql, $maxIdVisit, 0, -self::$selectSegmentSize);
  
  @param string $sql The SQL to perform. The last two conditions of the `WHERE`
  expression must be as follows: `'id >= ? AND id < ?'` where
  **id** is the int id of the table.
  @param int $first The minimum ID to loop from.
  @param int $last The maximum ID to loop to.
  @param int $step The maximum number of rows to scan in one query.
  @param array $params Parameters to bind in the query, eg, `array(param1 => value1, param2 => value2)`
  
  @return string
docstring_tokens: Performs a SELECT statement on a table one chunk at a time and returns the first successfully fetched value .