Вход Регистрация
Файл: src/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
Строк: 106
<?php

namespace IlluminateDatabaseQueryGrammars;

use 
IlluminateDatabaseQueryBuilder;

class 
MySqlGrammar extends Grammar
{
    
/**
     * The components that make up a select clause.
     *
     * @var array
     */
    
protected $selectComponents = [
        
'aggregate',
        
'columns',
        
'from',
        
'joins',
        
'wheres',
        
'groups',
        
'havings',
        
'orders',
        
'limit',
        
'offset',
        
'lock',
    ];

    
/**
     * Compile a select query into SQL.
     *
     * @param  IlluminateDatabaseQueryBuilder  $query
     * @return string
     */
    
public function compileSelect(Builder $query)
    {
        
$sql parent::compileSelect($query);

        if (
$query->unions) {
            
$sql '('.$sql.') '.$this->compileUnions($query);
        }

        return 
$sql;
    }

    
/**
     * Compile a single union statement.
     *
     * @param  array  $union
     * @return string
     */
    
protected function compileUnion(array $union)
    {
        
$joiner $union['all'] ? ' union all ' ' union ';

        return 
$joiner.'('.$union['query']->toSql().')';
    }

    
/**
     * Compile the lock into SQL.
     *
     * @param  IlluminateDatabaseQueryBuilder  $query
     * @param  bool|string  $value
     * @return string
     */
    
protected function compileLock(Builder $query$value)
    {
        if (
is_string($value)) {
            return 
$value;
        }

        return 
$value 'for update' 'lock in share mode';
    }

    
/**
     * Compile an update statement into SQL.
     *
     * @param  IlluminateDatabaseQueryBuilder  $query
     * @param  array  $values
     * @return string
     */
    
public function compileUpdate(Builder $query$values)
    {
        
$sql parent::compileUpdate($query$values);

        if (isset(
$query->orders)) {
            
$sql .= ' '.$this->compileOrders($query$query->orders);
        }

        if (isset(
$query->limit)) {
            
$sql .= ' '.$this->compileLimit($query$query->limit);
        }

        return 
rtrim($sql);
    }

    
/**
     * Compile a delete statement into SQL.
     *
     * @param  IlluminateDatabaseQueryBuilder  $query
     * @return string
     */
    
public function compileDelete(Builder $query)
    {
        
$table $this->wrapTable($query->from);

        
$where is_array($query->wheres) ? $this->compileWheres($query) : '';

        if (isset(
$query->joins)) {
            
$joins ' '.$this->compileJoins($query$query->joins);

            
$sql trim("delete $table from {$table}{$joins} $where");
        } else {
            
$sql trim("delete from $table $where");
        }

        if (isset(
$query->orders)) {
            
$sql .= ' '.$this->compileOrders($query$query->orders);
        }

        if (isset(
$query->limit)) {
            
$sql .= ' '.$this->compileLimit($query$query->limit);
        }

        return 
$sql;
    }

    
/**
     * Wrap a single string in keyword identifiers.
     *
     * @param  string  $value
     * @return string
     */
    
protected function wrapValue($value)
    {
        if (
$value === '*') {
            return 
$value;
        }

        if (
str_contains($value'->')) {
            return 
$this->wrapJsonSelector($value);
        }

        return 
'`'.str_replace('`''``'$value).'`';
    }

    
/**
     * Wrap the given JSON selector.
     *
     * @param  string  $value
     * @return string
     */
    
protected function wrapJsonSelector($value)
    {
        
$path explode('->'$value);

        return 
array_shift($path).'->'.'"$.'.implode('.'$path).'"';
    }
}
Онлайн: 2
Реклама