/** * Modifies the original insert query to append a "RETURNING *" epilogue * so that the latest insert id can be retrieved * * @param \Cake\Database\Query $query The query to translate. * @return \Cake\Database\Query */ protected function _insertQueryTranslator($query) { if (!$query->clause('epilog')) { $query->epilog('RETURNING *'); } return $query; }
/** * Generates the LIMIT part of a SQL query * * @param int $limit the limit clause * @param \Cake\Database\Query $query The query that is being compiled * @return string */ protected function _buildLimitPart($limit, $query) { if (intval($limit) < 1) { return ''; } $endRow = intval($query->clause('offset')) + $limit; $origEpilog = $query->clause('epilog'); $offsetEndWrap = ''; if (is_array($origEpilog) && array_key_exists('snelgOracleOrigEpilog', $origEpilog)) { $offsetEndWrap = empty($origEpilog['snelgOracleOffsetEndWrap']) ? '' : $origEpilog['snelgOracleOffsetEndWrap']; $origEpilog = $origEpilog['snelgOracleOrigEpilog']; } //See note in _buildOffsetPart about ->bind being potentially //more efficient here $query->epilog(['snelgOracleOrigEpilog' => $origEpilog, 'snelgOracleLimitEndWrap' => ") a WHERE ROWNUM <= {$endRow}", 'snelgOracleOffsetEndWrap' => $offsetEndWrap]); return 'SELECT /*+ FIRST_ROWS(n) */ a.*, ROWNUM snelg_oracle_sub_rnum FROM ('; }