class MySqlGrammar extends Grammar (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected string $tablePrefix

The grammar table prefix.

from  Grammar
protected string[] $operators

The grammar specific operators.

protected array $bitwiseOperators

The grammar specific bitwise operators.

from  Grammar
protected string[] $selectComponents

The components that make up a select clause.

from  Grammar

Methods

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

array
wrapArray(array $values)

Wrap an array of values.

from  Grammar
string
wrapTable(Expression|string $table)

Wrap a table in keyword identifiers.

from  Grammar
string
wrap(Expression|string $value, bool $prefixAlias = false)

Wrap a value in keyword identifiers.

from  Grammar
string
wrapAliasedValue(string $value, bool $prefixAlias = false)

Wrap a value that has an alias.

from  Grammar
string
wrapSegments(array $segments)

Wrap the given value segments.

from  Grammar
string
wrapValue(string $value)

Wrap a single string in keyword identifiers.

string
columnize(array $columns)

Convert an array of column names into a delimited string.

from  Grammar
string
parameterize(array $values)

Create query parameter place-holders for an array.

from  Grammar
string
parameter(mixed $value)

Get the appropriate query parameter place-holder for a value.

from  Grammar
string
quoteString(string|array $value)

Quote the given string literal.

from  Grammar
bool
isExpression(mixed $value)

Determine if the given value is a raw expression.

from  Grammar
mixed
getValue(Expression $expression)

Get the value of a raw expression.

from  Grammar
string
getDateFormat()

Get the format for database stored dates.

from  Grammar
string
getTablePrefix()

Get the grammar's table prefix.

from  Grammar
$this
setTablePrefix(string $prefix)

Set the grammar's table prefix.

from  Grammar
string
compileSelect(Builder $query)

Compile a select query into SQL.

from  Grammar
array
compileComponents(Builder $query)

Compile the components necessary for a select clause.

from  Grammar
string
compileAggregate(Builder $query, array $aggregate)

Compile an aggregated select clause.

from  Grammar
string|null
compileColumns(Builder $query, array $columns)

Compile the "select *" portion of the query.

from  Grammar
string
compileFrom(Builder $query, string $table)

Compile the "from" portion of the query.

from  Grammar
string
compileJoins(Builder $query, array $joins)

Compile the "join" portions of the query.

from  Grammar
string
compileWheres(Builder $query)

Compile the "where" portions of the query.

from  Grammar
array
compileWheresToArray(Builder $query)

Get an array of all the where clauses for the query.

from  Grammar
string
concatenateWhereClauses(Builder $query, array $sql)

Format the where clause statements into one string.

from  Grammar
string
whereRaw(Builder $query, array $where)

Compile a raw where clause.

from  Grammar
string
whereBasic(Builder $query, array $where)

Compile a basic where clause.

from  Grammar
string
whereBitwise(Builder $query, array $where)

Compile a bitwise operator where clause.

from  Grammar
string
whereIn(Builder $query, array $where)

Compile a "where in" clause.

from  Grammar
string
whereNotIn(Builder $query, array $where)

Compile a "where not in" clause.

from  Grammar
string
whereNotInRaw(Builder $query, array $where)

Compile a "where not in raw" clause.

from  Grammar
string
whereInRaw(Builder $query, array $where)

Compile a "where in raw" clause.

from  Grammar
string
whereNull(Builder $query, array $where)

Add a "where null" clause to the query.

string
whereNotNull(Builder $query, array $where)

Add a "where not null" clause to the query.

string
whereBetween(Builder $query, array $where)

Compile a "between" where clause.

from  Grammar
string
whereBetweenColumns(Builder $query, array $where)

Compile a "between" where clause.

from  Grammar
string
whereDate(Builder $query, array $where)

Compile a "where date" clause.

from  Grammar
string
whereTime(Builder $query, array $where)

Compile a "where time" clause.

from  Grammar
string
whereDay(Builder $query, array $where)

Compile a "where day" clause.

from  Grammar
string
whereMonth(Builder $query, array $where)

Compile a "where month" clause.

from  Grammar
string
whereYear(Builder $query, array $where)

Compile a "where year" clause.

from  Grammar
string
dateBasedWhere(string $type, Builder $query, array $where)

Compile a date based where clause.

from  Grammar
string
whereColumn(Builder $query, array $where)

Compile a where clause comparing two columns.

from  Grammar
string
whereNested(Builder $query, array $where)

Compile a nested where clause.

from  Grammar
string
whereSub(Builder $query, array $where)

Compile a where condition with a sub-select.

from  Grammar
string
whereExists(Builder $query, array $where)

Compile a where exists clause.

from  Grammar
string
whereNotExists(Builder $query, array $where)

Compile a where exists clause.

from  Grammar
string
whereRowValues(Builder $query, array $where)

Compile a where row values condition.

from  Grammar
string
whereJsonBoolean(Builder $query, array $where)

Compile a "where JSON boolean" clause.

from  Grammar
string
whereJsonContains(Builder $query, array $where)

Compile a "where JSON contains" clause.

from  Grammar
string
compileJsonContains(string $column, string $value)

Compile a "JSON contains" statement into SQL.

string
prepareBindingForJsonContains(mixed $binding)

Prepare the binding for a "JSON contains" statement.

from  Grammar
string
whereJsonLength(Builder $query, array $where)

Compile a "where JSON length" clause.

from  Grammar
string
compileJsonLength(string $column, string $operator, string $value)

Compile a "JSON length" statement into SQL.

string
whereFullText(Builder $query, array $where)

Compile a "where fulltext" clause.

string
compileGroups(Builder $query, array $groups)

Compile the "group by" portions of the query.

from  Grammar
string
compileHavings(Builder $query, array $havings)

Compile the "having" portions of the query.

from  Grammar
string
compileHaving(array $having)

Compile a single having clause.

from  Grammar
string
compileBasicHaving(array $having)

Compile a basic having clause.

from  Grammar
string
compileHavingBetween(array $having)

Compile a "between" having clause.

from  Grammar
string
compileOrders(Builder $query, array $orders)

Compile the "order by" portions of the query.

from  Grammar
array
compileOrdersToArray(Builder $query, array $orders)

Compile the query orders to an array.

from  Grammar
string
compileRandom(string $seed)

Compile the random statement into SQL.

string
compileLimit(Builder $query, int $limit)

Compile the "limit" portions of the query.

from  Grammar
string
compileOffset(Builder $query, int $offset)

Compile the "offset" portions of the query.

from  Grammar
string
compileUnions(Builder $query)

Compile the "union" queries attached to the main query.

from  Grammar
string
compileUnion(array $union)

Compile a single union statement.

from  Grammar
string
wrapUnion(string $sql)

Wrap a union subquery in parentheses.

from  Grammar
string
compileUnionAggregate(Builder $query)

Compile a union aggregate query into SQL.

from  Grammar
string
compileExists(Builder $query)

Compile an exists statement into SQL.

from  Grammar
string
compileInsert(Builder $query, array $values)

Compile an insert statement into SQL.

string
compileInsertOrIgnore(Builder $query, array $values)

Compile an insert ignore statement into SQL.

string
compileInsertGetId(Builder $query, array $values, string $sequence)

Compile an insert and get ID statement into SQL.

from  Grammar
string
compileInsertUsing(Builder $query, array $columns, string $sql)

Compile an insert statement using a subquery into SQL.

from  Grammar
string
compileUpdate(Builder $query, array $values)

Compile an update statement into SQL.

from  Grammar
string
compileUpdateColumns(Builder $query, array $values)

Compile the columns for an update statement.

string
compileUpdateWithoutJoins(Builder $query, string $table, string $columns, string $where)

Compile an update statement without joins into SQL.

string
compileUpdateWithJoins(Builder $query, string $table, string $columns, string $where)

Compile an update statement with joins into SQL.

from  Grammar
string
compileUpsert(Builder $query, array $values, array $uniqueBy, array $update)

Compile an "upsert" statement into SQL.

array
prepareBindingsForUpdate(array $bindings, array $values)

Prepare the bindings for an update statement.

string
compileDelete(Builder $query)

Compile a delete statement into SQL.

from  Grammar
string
compileDeleteWithoutJoins(Builder $query, string $table, string $where)

Compile a delete query that does not use joins.

string
compileDeleteWithJoins(Builder $query, string $table, string $where)

Compile a delete statement with joins into SQL.

from  Grammar
array
prepareBindingsForDelete(array $bindings)

Prepare the bindings for a delete statement.

from  Grammar
array
compileTruncate(Builder $query)

Compile a truncate table statement into SQL.

from  Grammar
string
compileLock(Builder $query, bool|string $value)

Compile the lock into SQL.

bool
supportsSavepoints()

Determine if the grammar supports savepoints.

from  Grammar
string
compileSavepoint(string $name)

Compile the SQL statement to define a savepoint.

from  Grammar
string
compileSavepointRollBack(string $name)

Compile the SQL statement to execute a savepoint rollback.

from  Grammar
string
wrapJsonSelector(string $value)

Wrap the given JSON selector.

string
wrapJsonBooleanSelector(string $value)

Wrap the given JSON selector for boolean values.

string
wrapJsonBooleanValue(string $value)

Wrap the given JSON boolean value.

from  Grammar
array
wrapJsonFieldAndPath(string $column)

Split the given JSON selector into the field and the optional path and wrap them separately.

from  Grammar
string
wrapJsonPath(string $value, string $delimiter = '->')

Wrap the given JSON path.

from  Grammar
bool
isJsonSelector(string $value)

Determine if the given string is a JSON selector.

from  Grammar
string
concatenate(array $segments)

Concatenate an array of segments, removing empties.

from  Grammar
string
removeLeadingBoolean(string $value)

Remove the leading boolean from a statement.

from  Grammar
array
getOperators()

Get the grammar specific operators.

from  Grammar
array
getBitwiseOperators()

Get the grammar specific bitwise operators.

from  Grammar
string
compileJsonUpdateColumn(string $key, mixed $value)

Prepare a JSON column being updated using the JSON_SET function.

Details

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

array wrapArray(array $values)

Wrap an array of values.

Parameters

array $values

Return Value

array

string wrapTable(Expression|string $table)

Wrap a table in keyword identifiers.

Parameters

Expression|string $table

Return Value

string

string wrap(Expression|string $value, bool $prefixAlias = false)

Wrap a value in keyword identifiers.

Parameters

Expression|string $value
bool $prefixAlias

Return Value

string

protected string wrapAliasedValue(string $value, bool $prefixAlias = false)

Wrap a value that has an alias.

Parameters

string $value
bool $prefixAlias

Return Value

string

protected string wrapSegments(array $segments)

Wrap the given value segments.

Parameters

array $segments

Return Value

string

protected string wrapValue(string $value)

Wrap a single string in keyword identifiers.

Parameters

string $value

Return Value

string

string columnize(array $columns)

Convert an array of column names into a delimited string.

Parameters

array $columns

Return Value

string

string parameterize(array $values)

Create query parameter place-holders for an array.

Parameters

array $values

Return Value

string

string parameter(mixed $value)

Get the appropriate query parameter place-holder for a value.

Parameters

mixed $value

Return Value

string

string quoteString(string|array $value)

Quote the given string literal.

Parameters

string|array $value

Return Value

string

bool isExpression(mixed $value)

Determine if the given value is a raw expression.

Parameters

mixed $value

Return Value

bool

mixed getValue(Expression $expression)

Get the value of a raw expression.

Parameters

Expression $expression

Return Value

mixed

string getDateFormat()

Get the format for database stored dates.

Return Value

string

string getTablePrefix()

Get the grammar's table prefix.

Return Value

string

$this setTablePrefix(string $prefix)

Set the grammar's table prefix.

Parameters

string $prefix

Return Value

$this

string compileSelect(Builder $query)

Compile a select query into SQL.

Parameters

Builder $query

Return Value

string

protected array compileComponents(Builder $query)

Compile the components necessary for a select clause.

Parameters

Builder $query

Return Value

array

protected string compileAggregate(Builder $query, array $aggregate)

Compile an aggregated select clause.

Parameters

Builder $query
array $aggregate

Return Value

string

protected string|null compileColumns(Builder $query, array $columns)

Compile the "select *" portion of the query.

Parameters

Builder $query
array $columns

Return Value

string|null

protected string compileFrom(Builder $query, string $table)

Compile the "from" portion of the query.

Parameters

Builder $query
string $table

Return Value

string

protected string compileJoins(Builder $query, array $joins)

Compile the "join" portions of the query.

Parameters

Builder $query
array $joins

Return Value

string

string compileWheres(Builder $query)

Compile the "where" portions of the query.

Parameters

Builder $query

Return Value

string

protected array compileWheresToArray(Builder $query)

Get an array of all the where clauses for the query.

Parameters

Builder $query

Return Value

array

protected string concatenateWhereClauses(Builder $query, array $sql)

Format the where clause statements into one string.

Parameters

Builder $query
array $sql

Return Value

string

protected string whereRaw(Builder $query, array $where)

Compile a raw where clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereBasic(Builder $query, array $where)

Compile a basic where clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereBitwise(Builder $query, array $where)

Compile a bitwise operator where clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereIn(Builder $query, array $where)

Compile a "where in" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereNotIn(Builder $query, array $where)

Compile a "where not in" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereNotInRaw(Builder $query, array $where)

Compile a "where not in raw" clause.

For safety, whereIntegerInRaw ensures this method is only used with integer values.

Parameters

Builder $query
array $where

Return Value

string

protected string whereInRaw(Builder $query, array $where)

Compile a "where in raw" clause.

For safety, whereIntegerInRaw ensures this method is only used with integer values.

Parameters

Builder $query
array $where

Return Value

string

protected string whereNull(Builder $query, array $where)

Add a "where null" clause to the query.

Parameters

Builder $query
array $where

Return Value

string

protected string whereNotNull(Builder $query, array $where)

Add a "where not null" clause to the query.

Parameters

Builder $query
array $where

Return Value

string

protected string whereBetween(Builder $query, array $where)

Compile a "between" where clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereBetweenColumns(Builder $query, array $where)

Compile a "between" where clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereDate(Builder $query, array $where)

Compile a "where date" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereTime(Builder $query, array $where)

Compile a "where time" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereDay(Builder $query, array $where)

Compile a "where day" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereMonth(Builder $query, array $where)

Compile a "where month" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereYear(Builder $query, array $where)

Compile a "where year" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string dateBasedWhere(string $type, Builder $query, array $where)

Compile a date based where clause.

Parameters

string $type
Builder $query
array $where

Return Value

string

protected string whereColumn(Builder $query, array $where)

Compile a where clause comparing two columns.

Parameters

Builder $query
array $where

Return Value

string

protected string whereNested(Builder $query, array $where)

Compile a nested where clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereSub(Builder $query, array $where)

Compile a where condition with a sub-select.

Parameters

Builder $query
array $where

Return Value

string

protected string whereExists(Builder $query, array $where)

Compile a where exists clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereNotExists(Builder $query, array $where)

Compile a where exists clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereRowValues(Builder $query, array $where)

Compile a where row values condition.

Parameters

Builder $query
array $where

Return Value

string

protected string whereJsonBoolean(Builder $query, array $where)

Compile a "where JSON boolean" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string whereJsonContains(Builder $query, array $where)

Compile a "where JSON contains" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string compileJsonContains(string $column, string $value)

Compile a "JSON contains" statement into SQL.

Parameters

string $column
string $value

Return Value

string

string prepareBindingForJsonContains(mixed $binding)

Prepare the binding for a "JSON contains" statement.

Parameters

mixed $binding

Return Value

string

protected string whereJsonLength(Builder $query, array $where)

Compile a "where JSON length" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string compileJsonLength(string $column, string $operator, string $value)

Compile a "JSON length" statement into SQL.

Parameters

string $column
string $operator
string $value

Return Value

string

string whereFullText(Builder $query, array $where)

Compile a "where fulltext" clause.

Parameters

Builder $query
array $where

Return Value

string

protected string compileGroups(Builder $query, array $groups)

Compile the "group by" portions of the query.

Parameters

Builder $query
array $groups

Return Value

string

protected string compileHavings(Builder $query, array $havings)

Compile the "having" portions of the query.

Parameters

Builder $query
array $havings

Return Value

string

protected string compileHaving(array $having)

Compile a single having clause.

Parameters

array $having

Return Value

string

protected string compileBasicHaving(array $having)

Compile a basic having clause.

Parameters

array $having

Return Value

string

protected string compileHavingBetween(array $having)

Compile a "between" having clause.

Parameters

array $having

Return Value

string

protected string compileOrders(Builder $query, array $orders)

Compile the "order by" portions of the query.

Parameters

Builder $query
array $orders

Return Value

string

protected array compileOrdersToArray(Builder $query, array $orders)

Compile the query orders to an array.

Parameters

Builder $query
array $orders

Return Value

array

string compileRandom(string $seed)

Compile the random statement into SQL.

Parameters

string $seed

Return Value

string

protected string compileLimit(Builder $query, int $limit)

Compile the "limit" portions of the query.

Parameters

Builder $query
int $limit

Return Value

string

protected string compileOffset(Builder $query, int $offset)

Compile the "offset" portions of the query.

Parameters

Builder $query
int $offset

Return Value

string

protected string compileUnions(Builder $query)

Compile the "union" queries attached to the main query.

Parameters

Builder $query

Return Value

string

protected string compileUnion(array $union)

Compile a single union statement.

Parameters

array $union

Return Value

string

protected string wrapUnion(string $sql)

Wrap a union subquery in parentheses.

Parameters

string $sql

Return Value

string

protected string compileUnionAggregate(Builder $query)

Compile a union aggregate query into SQL.

Parameters

Builder $query

Return Value

string

string compileExists(Builder $query)

Compile an exists statement into SQL.

Parameters

Builder $query

Return Value

string

string compileInsert(Builder $query, array $values)

Compile an insert statement into SQL.

Parameters

Builder $query
array $values

Return Value

string

string compileInsertOrIgnore(Builder $query, array $values)

Compile an insert ignore statement into SQL.

Parameters

Builder $query
array $values

Return Value

string

string compileInsertGetId(Builder $query, array $values, string $sequence)

Compile an insert and get ID statement into SQL.

Parameters

Builder $query
array $values
string $sequence

Return Value

string

string compileInsertUsing(Builder $query, array $columns, string $sql)

Compile an insert statement using a subquery into SQL.

Parameters

Builder $query
array $columns
string $sql

Return Value

string

string compileUpdate(Builder $query, array $values)

Compile an update statement into SQL.

Parameters

Builder $query
array $values

Return Value

string

protected string compileUpdateColumns(Builder $query, array $values)

Compile the columns for an update statement.

Parameters

Builder $query
array $values

Return Value

string

protected string compileUpdateWithoutJoins(Builder $query, string $table, string $columns, string $where)

Compile an update statement without joins into SQL.

Parameters

Builder $query
string $table
string $columns
string $where

Return Value

string

protected string compileUpdateWithJoins(Builder $query, string $table, string $columns, string $where)

Compile an update statement with joins into SQL.

Parameters

Builder $query
string $table
string $columns
string $where

Return Value

string

string compileUpsert(Builder $query, array $values, array $uniqueBy, array $update)

Compile an "upsert" statement into SQL.

Parameters

Builder $query
array $values
array $uniqueBy
array $update

Return Value

string

array prepareBindingsForUpdate(array $bindings, array $values)

Prepare the bindings for an update statement.

Booleans, integers, and doubles are inserted into JSON updates as raw values.

Parameters

array $bindings
array $values

Return Value

array

string compileDelete(Builder $query)

Compile a delete statement into SQL.

Parameters

Builder $query

Return Value

string

protected string compileDeleteWithoutJoins(Builder $query, string $table, string $where)

Compile a delete query that does not use joins.

Parameters

Builder $query
string $table
string $where

Return Value

string

protected string compileDeleteWithJoins(Builder $query, string $table, string $where)

Compile a delete statement with joins into SQL.

Parameters

Builder $query
string $table
string $where

Return Value

string

array prepareBindingsForDelete(array $bindings)

Prepare the bindings for a delete statement.

Parameters

array $bindings

Return Value

array

array compileTruncate(Builder $query)

Compile a truncate table statement into SQL.

Parameters

Builder $query

Return Value

array

protected string compileLock(Builder $query, bool|string $value)

Compile the lock into SQL.

Parameters

Builder $query
bool|string $value

Return Value

string

bool supportsSavepoints()

Determine if the grammar supports savepoints.

Return Value

bool

string compileSavepoint(string $name)

Compile the SQL statement to define a savepoint.

Parameters

string $name

Return Value

string

string compileSavepointRollBack(string $name)

Compile the SQL statement to execute a savepoint rollback.

Parameters

string $name

Return Value

string

protected string wrapJsonSelector(string $value)

Wrap the given JSON selector.

Parameters

string $value

Return Value

string

protected string wrapJsonBooleanSelector(string $value)

Wrap the given JSON selector for boolean values.

Parameters

string $value

Return Value

string

protected string wrapJsonBooleanValue(string $value)

Wrap the given JSON boolean value.

Parameters

string $value

Return Value

string

protected array wrapJsonFieldAndPath(string $column)

Split the given JSON selector into the field and the optional path and wrap them separately.

Parameters

string $column

Return Value

array

protected string wrapJsonPath(string $value, string $delimiter = '->')

Wrap the given JSON path.

Parameters

string $value
string $delimiter

Return Value

string

protected bool isJsonSelector(string $value)

Determine if the given string is a JSON selector.

Parameters

string $value

Return Value

bool

protected string concatenate(array $segments)

Concatenate an array of segments, removing empties.

Parameters

array $segments

Return Value

string

protected string removeLeadingBoolean(string $value)

Remove the leading boolean from a statement.

Parameters

string $value

Return Value

string

array getOperators()

Get the grammar specific operators.

Return Value

array

array getBitwiseOperators()

Get the grammar specific bitwise operators.

Return Value

array

protected string compileJsonUpdateColumn(string $key, mixed $value)

Prepare a JSON column being updated using the JSON_SET function.

Parameters

string $key
mixed $value

Return Value

string