DMLParser
class DMLParser extends Parser
This class allows you to store and retrieve data from files in JSON format using SQL standard.
- The data are described by a json schema in compliance with the spécifications of http://json-schema.org
This schema can be generated on this site: http://jsonschema.net
The API is very similar to PDO
The JSON schema is saved in a file whose name is in the form
.schema.json - The data is saved in a file whose name is in the form
.json
Constants
SQL_SELECT_KEYWORD |
|
SQL_FROM_KEYWORD |
|
SQL_WHERE_KEYWORD |
|
SQL_ORDER_BY_KEYWORD |
|
SQL_LIMIT_KEYWORD |
|
SQL_OFFSET_KEYWORD |
|
SQL_UPDATE_KEYWORD |
|
SQL_CREATE_KEYWORD |
|
SQL_DELETE_KEYWORD |
|
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
protected JsonSQL | $jsonsql | A pointer on the JsonSQL owner. | from Parser |
protected Engine | $engine | A pointer on JSON database engine. | from Parser |
protected string | $sql | The sql request. | from Parser |
private array | $synonyms | Conversion table of SQL functions in PHP functions | |
private array | $allowed | Allowed PHP functions in conditions |
Methods
Parses a sql select request according to this BNF syntax :
Parses a sql compound select request containing set operations according to this BNF syntax :
Parses a sql insert into statement according to this BNF syntax :
Parses a sql update statement according to this BNF syntax :
Parses a sql delete from statement according to this BNF syntax : DELETE FROM table_name [ WHERE condition ]
function parseCreate
function parseAlter
Parses a sql truncate table statement according to this BNF syntax :
function parseDropTable
Parses and converts a sql expression into a php one
Parses and converts sql conditions into a php one
Verifies that an php expression is sufficiently secured before being evaluated by the eval function
Checks if a string contains an expression.
Replaces into an expression, the SQL functions by their PHP equivalents
Details
at line 172
void
__construct(JsonSQL $jsonsql, string $sql)
Constructor of class DMLParser
in Parser at line 169
object
parse()
Parses the sql statement.
at line 201
protected 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 414
protected 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
at line 468
protected object
parseInsert(string $sql)
Parses a sql insert into statement according to this BNF syntax :
INSERT INTO table_name ( [ '(' column_name { ', ' column_name } ')' ] VALUES '(' ( expression | DEFAULT ) {', ' ( expression | DEFAULT ) } ')' {', ' '(' ( expression | DEFAULT ) {', ' ( expression | DEFAULT ) } ')' } | select_statement )
or eBNF syntax :
'INSERT INTO' table_name ( ( '(' column_name ( ', ' column_name ) * ')' ) ? 'VALUES' '(' ( expression | 'DEFAULT' ) ( ', ' ( expression | 'DEFAULT' ) ) * ')' ( ', ' '(' ( expression | 'DEFAULT' ) ( ', ' ( expression | 'DEFAULT' ) ) * ')' ) * | select_statement )
at line 564
protected object
parseUpdate(string $sql)
Parses a sql update statement according to this BNF syntax :
UPDATE table_name SET column_name = expression { ', ' column_name = expression } [ WHERE condition ]
or eBNF syntax :
'UPDATE' table_name 'SET' column_name '=' expression ( ', ' column_name '=' expression ) * ( 'WHERE' condition ) ?
at line 615
protected object
parseDelete(string $sql)
Parses a sql delete from statement according to this BNF syntax : DELETE FROM table_name [ WHERE condition ]
or eBNF syntax : 'DELETE FROM' table_name ( 'WHERE' condition ) ?
at line 843
protected object
parseCreate(string $sql)
function parseCreate
at line 856
protected object
parseAlter(string $sql)
function parseAlter
at line 649
protected object
parseTruncate(string $sql)
Parses a sql truncate table statement according to this BNF syntax :
TRUNCATE TABLE table_name { ', ' table_name }
or eBNF syntax :
'TRUNCATE TABLE' table_name ( ', ' table_name ) *
at line 869
protected object
parseDropTable(string $sql)
function parseDropTable
at line 671
protected string
parseExpression(string $expression, array $columns)
Parses and converts a sql expression into a php one
at line 712
protected string
parseConditions(string $conditions, array $columns, array $select = array())
Parses and converts sql conditions into a php one
at line 781
void
checkSafety(string $expression)
Verifies that an php expression is sufficiently secured before being evaluated by the eval function
at line 809
protected bool
isExpression(string $string)
Checks if a string contains an expression.
at line 823
private string
replaceSynonyms(string $expr)
Replaces into an expression, the SQL functions by their PHP equivalents