for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Spiral Framework.
*
* @license MIT
* @author Anton Titov (Wolfy-J)
*/
namespace Spiral\Database\Drivers\SQLServer;
use Spiral\Database\Query\PDOResult;
* SQLServer specific result reader, required due server need additional column for sorting in some
* cases.
* Attention: spiral_row_number column WILL be included in results generated by fetchAll method but
* will be removed from fetch method automatically.
* todo: make sure there is no much inconsistency with SQLServer selections
class SQLServerResult extends PDOResult
{
* Helper column used to create limit, offset statements in older versions of sql server.
const ROW_NUMBER_COLUMN = 'spiral_row_number';
* {@inheritdoc}
public function columnCount()
return parent::columnCount() + ($this->hasHelpColumn() ? -1 : 0);
}
public function fetch(
$fetch_style = null,
$cursor_orientation = \PDO::FETCH_ORI_NEXT,
$cursor_offset = 0
) {
$result = parent::fetch($fetch_style, $cursor_orientation, $cursor_offset);
if (!$this->hasHelpColumn() || !is_array($result)) {
return $result;
if (is_array($result) && $this->hasHelpColumn()) {
//Sorting column is always first in result
array_pop($result);
* Provides support for old SQLServer versions.
* @return bool
private function hasHelpColumn()
return $this->getColumnMeta($this->countColumns() - 1)['name'] == self::ROW_NUMBER_COLUMN;