phpOMS/DataStorage/Database/Query/Grammar/SqlServerGrammar.php
2024-03-20 07:21:26 +00:00

68 lines
1.4 KiB
PHP
Executable File

<?php
/**
* Jingga
*
* PHP Version 8.2
*
* @package phpOMS\DataStorage\Database\Query\Grammar
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder;
/**
* Grammar class.
*
* @package phpOMS\DataStorage\Database\Query\Grammar
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class SqlServerGrammar extends Grammar
{
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
public string $systemIdentifierStart = '[';
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
public string $systemIdentifierEnd = ']';
/**
* Compile random.
*
* @param Builder $query Builder
* @param array $columns Columns
*
* @return string
*
* @since 1.0.0
*/
protected function compileRandom(Builder $query, array $columns) : string
{
$expression = $this->expressionizeTableColumn($columns);
if ($expression === '') {
$expression = '*';
}
$query->limit = $query->limit ?? 1;
return 'SELECT TOP ' . $query->limit . ' ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ORDER BY IDX FETCH FIRST ' . ($query->limit ?? 1) . ' ROWS ONLY';
}
}