SQLSelectTokenizer
class SQLSelectTokenizer
This class allows the tokenization of an SQL select request.
Constants
CROSS_JOIN |
Types of JOINS : CROSS_JOIN: Returns the Cartesian product of the sets of rows from the joined tables |
INNER_JOIN |
INNER_JOIN: Returns all rows when there is at least one match in BOTH tables |
LEFT_JOIN |
LEFT_JOIN: Return all rows from the left table, and the matched rows from the right table |
RIGHT_JOIN |
RIGHT_JOIN: Return all rows from the right table, and the matched rows from the left table |
Properties
private array | $allowed | Allowed PHP functions in conditions | |
private array|null | $tables |
Methods
Constructor of class SQLSelectTokenizer
Sets the list of tables of the SQL select
Verifies that an php expression is sufficiently secured before being evaluated by the eval function
Checks if a string contains an expression.
Parses and converts a sql expression into a php one
Parses and converts sql conditions into a php one
Inserts a condition into a condition array if it does not already exist and returns its position in the array.
Parses a where clause
Parses a sql select request according to this BNF syntax :
Parses a sql compound select request containing set operations according to this BNF syntax :
Details
at line 193
void
__construct(array $tables = null)
Constructor of class SQLSelectTokenizer
at line 205
void
setTables(array $tables)
Sets the list of tables of the SQL select
at line 218
void
checkSafety(string $expression)
Verifies that an php expression is sufficiently secured before being evaluated by the eval function
at line 246
protected bool
isExpression(string $string)
Checks if a string contains an expression.
at line 260
protected string
parseExpression(string $expression)
Parses and converts a sql expression into a php one
at line 279
protected string
parseConditions(string $conditions)
Parses and converts sql conditions into a php one
at line 299
protected void
addTokenInCondition(stdClass $condition, Token $token)
Inserts a token into a condition
at line 325
protected void
resetCondition(stdClass $condition)
Resets a condition
at line 343
protected int
insertCondition(array $conditions, stdClass $condition)
Inserts a condition into a condition array if it does not already exist and returns its position in the array.
at line 367
protected stdClass
parseWhere(string $where)
Parses a where clause
at line 463
object
parseSelect(string $sql)
Parses a sql select request according to this BNF syntax :
SELECT [ ALL | DISTINCT ] ( expression [ AS alias ] | * | table_name.* ) {',' ( expression [ AS alias ] | * | table_name.* ) } FROM table_name [ AS alias ] {',' table_name [ AS alias ]} { [ CROSS | INNER | LEFT [OUTER] | RIGHT [OUTER] ] JOIN table_name [ AS alias ] [ ON condition ] } [ WHERE condition ] [ GROUP BY expression {',' expression} ] [ HAVING condition ] [ ORDER BY expression [ ASC | DESC ] {',' expression [ ASC | DESC ]} ] [LIMIT {[offset,] row_count | row_count OFFSET offset}]
or eBNF syntax :
'SELECT' ( 'ALL' | 'DISTINCT' ) ? ( expression ( 'AS' ? alias ) ? | '' | table_name '.' ) ( ',' ( expression ( 'AS' ? alias ) ? | '' | table_name '.' ) ) * 'FROM' table_name ( 'AS' ? alias ) ? ( ',' table_name ( 'AS' ? alias ) ? ) * ( ( ( 'CROSS' | 'INNER' | 'LEFT' ( 'OUTER' ) ? | 'RIGHT' ( 'OUTER' ) ? ) ? 'JOIN' table_name ( 'AS' ? alias ) ? ( 'ON' condition ) ? ) ) * ( 'WHERE' condition ) ? ( 'GROUP BY' expression ( ',' expression ) * ( 'HAVING' condition ) ? ) ? ( 'ORDER BY' expression ( 'ASC' | 'DESC' ) ? ( ',' expression ( 'ASC' | 'DESC' ) ? ) * ) ? ( 'LIMIT' ( ( offset ',' ) ? row_count | row_count 'OFFSET' offset ) ) ?
at line 694
object
parseSetOperations(string $sql)
Parses a sql compound select request containing set operations according to this BNF syntax :
select_statement [ UNION | UNION ALL | INTERSECT | EXCEPT | MINUS ] select_statement { select_statement [ UNION | UNION ALL | INTERSECT | EXCEPT | MINUS ] select_statement }
or eBNF syntax :
select_statement (( 'UNION' | 'UNION ALL' | 'INTERSECT' | 'EXCEPT' | 'MINUS' ) select_statement) *
if the statement contains no set operator, just parses the select request