PHP Class SqlParser\Utils\Query

Author: Dan Ungureanu ([email protected])
Show file Open project: phpmyadmin/sql-parser Class Usage Examples

Public Properties

Property Type Description
$FUNCTIONS array Functions that set the flag is_func.

Public Methods

Method Description
getAll ( string $query ) : array Parses a query and gets all information about it.
getClause ( Statement $statement, TokensList $list, string $clause, integer | string $type, boolean $skipFirst = true ) : string Gets a specific clause.
getClauseStartOffset ( Statement $statement, TokensList $list, string $clause ) : integer Gets a starting offset of a specific clause.
getFirstStatement ( string $query, string $delimiter = null ) : array Gets the first full statement in the query.
getFlags ( Statement | null $statement, boolean $all = false ) : array Gets an array with flags this statement has.
getTables ( Statement $statement ) : array Gets a list of all tables used in this statement.
replaceClause ( Statement $statement, TokensList $list, string $old, string $new = null, boolean $onlyType = false ) : string Builds a query by rebuilding the statement from the tokens list supplied and replaces a clause.
replaceClauses ( Statement $statement, TokensList $list, array $ops ) : string Builds a query by rebuilding the statement from the tokens list supplied and replaces multiple clauses.

Method Details

getAll() public static method

Parses a query and gets all information about it.
public static getAll ( string $query ) : array
$query string The query to be parsed.
return array The array returned is the one returned by `static::getFlags()`, with the following keys added: - parser - the parser used to analyze the query; - statement - the first statement resulted from parsing; - select_tables - the real name of the tables selected; if there are no table names in the `SELECT` expressions, the table names are fetched from the `FROM` expressions - select_expr - selected expressions

getClause() public static method

Gets a specific clause.
public static getClause ( Statement $statement, TokensList $list, string $clause, integer | string $type, boolean $skipFirst = true ) : string
$statement SqlParser\Statement The parsed query that has to be modified.
$list SqlParser\TokensList The list of tokens.
$clause string The clause to be returned.
$type integer | string The type of the search. If int, -1 for everything that was before 0 only for the clause 1 for everything after If string, the name of the first clause that should not be included.
$skipFirst boolean Whether to skip the first keyword in clause.
return string

getClauseStartOffset() public static method

Gets a starting offset of a specific clause.
public static getClauseStartOffset ( Statement $statement, TokensList $list, string $clause ) : integer
$statement SqlParser\Statement The parsed query that has to be modified.
$list SqlParser\TokensList The list of tokens.
$clause string The clause to be returned.
return integer

getFirstStatement() public static method

Gets the first full statement in the query.
public static getFirstStatement ( string $query, string $delimiter = null ) : array
$query string The query to be analyzed.
$delimiter string The delimiter to be used.
return array Array containing the first full query, the remaining part of the query and the last delimiter.

getFlags() public static method

Gets an array with flags this statement has.
public static getFlags ( Statement | null $statement, boolean $all = false ) : array
$statement SqlParser\Statement | null The statement to be processed.
$all boolean If `false`, false values will not be included.
return array

getTables() public static method

Gets a list of all tables used in this statement.
public static getTables ( Statement $statement ) : array
$statement SqlParser\Statement Statement to be scanned.
return array

replaceClause() public static method

It is a very basic version of a query builder.
public static replaceClause ( Statement $statement, TokensList $list, string $old, string $new = null, boolean $onlyType = false ) : string
$statement SqlParser\Statement The parsed query that has to be modified.
$list SqlParser\TokensList The list of tokens.
$old string The type of the clause that should be replaced. This can be an entire clause.
$new string The new clause. If this parameter is omitted it is considered to be equal with `$old`.
$onlyType boolean Whether only the type of the clause should be replaced or the entire clause.
return string

replaceClauses() public static method

Builds a query by rebuilding the statement from the tokens list supplied and replaces multiple clauses.
public static replaceClauses ( Statement $statement, TokensList $list, array $ops ) : string
$statement SqlParser\Statement The parsed query that has to be modified.
$list SqlParser\TokensList The list of tokens.
$ops array Clauses to be replaced. Contains multiple arrays having two values: array($old, $new). Clauses must be sorted.
return string

Property Details

$FUNCTIONS public static property

Functions that set the flag is_func.
public static array $FUNCTIONS
return array