mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
66 lines
1.4 KiB
PHP
66 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 8.0
|
|
*
|
|
* @package phpOMS\DataStorage\Database\Query\Grammar
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link https://orange-management.org
|
|
*/
|
|
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 1.0
|
|
* @link https://orange-management.org
|
|
* @since 1.0.0
|
|
*/
|
|
class MysqlGrammar 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 = '*';
|
|
}
|
|
|
|
return 'SELECT ' . $expression . ' ' . $this->compileFrom($query, $query->from) . ' ' . $this->compileWheres($query, $query->wheres) . ' ORDER BY \rand() ' . $this->compileLimit($query, $query->limit ?? 1);
|
|
}
|
|
}
|