DDLParser
class DDLParser 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_UPDATE_KEYWORD |
|
SQL_CREATE_KEYWORD |
|
SQL_DELETE_KEYWORD |
|
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 | $datatypes | Conversion table of SQL data types in JSON data types |
Methods
Parses a sql create table statement according to this two BNF syntax :
Copy the definitions of columns
Parses a sql alter table statement according to this two BNF syntax :
Parses a sql drop table statement according to this BNF syntax :
Encode text between quote with base64
Decode text encoded with base64
Details
at line 104
void
__construct(JsonSQL $jsonsql, string $sql)
Constructor of class DDLParser
at line 141
protected array
parseCreate(string $sql)
Parses a sql create table statement according to this two BNF syntax :
CREATE [ LOCAL | GLOBAL ] TABLE [ IF NOT EXISTS ] table_name ( column_name datatype [ CONSTRAINT constraint_name] [ NOT NULL|NULLABLE ] [ DEFAULT default ] [ PRIMARY KEY ] [ AUTOINCREMENT|AUTO_INCREMENT|SERIAL ] { ', ' column_name datatype [ CONSTRAINT constraint_name] [ NOT NULL|NULLABLE ] [ DEFAULT default ] [ PRIMARY KEY ] [ AUTOINCREMENT|AUTO_INCREMENT|SERIAL ] } { ', ' FOREIGN KEY (column_name { ', ' column_name} ) REFERENCES table_name (column_name { ', ' column_name} ) } [ ', ' PRIMARY KEY (column_name { ', ' column_name} ) ] )
or
CREATE [ LOCAL | GLOBAL ] TABLE [ IF NOT EXISTS ] table_name [ (column_name, { ', ' column_name }) ] AS select_statement [ WITH [ NO ] DATA ]
or eBNF syntax :
('CREATE' ( 'LOCAL' | 'GLOBAL' ) ? 'TABLE' ( 'IF NOT EXISTS' ) ? table_name '(' column_name datatype ( 'CONSTRAINT' constraint_name ) ? ( 'NOT NULL' | 'NULLABLE' ) ? ( 'DEFAULT' default ) ? ( 'PRIMARY KEY' ) ? ( 'AUTOINCREMENT' | 'AUTO_INCREMENT' | 'SERIAL' ) ? ( ', ' column_name datatype ( 'CONSTRAINT' constraint_name ) ? ( 'NOT NULL' | 'NULLABLE' ) ? ( 'DEFAULT' default ) ? ( 'PRIMARY KEY' ) ? ( 'AUTOINCREMENT' | 'AUTO_INCREMENT' | 'SERIAL' ) ? ) * ( ', ' 'FOREIGN KEY' '(' column_name ( ', ' column_name ) * ')' 'REFERENCES' table_name '(' column_name ( ', ' column_name ) * ')' ) * ( ', ' 'PRIMARY KEY' '(' column_name ( ', ' column_name ) * ')' ) ? ')' | 'CREATE' ( 'LOCAL' | 'GLOBAL' ) ? 'TABLE' ( 'IF NOT EXISTS' ) ? table_name ( '(' column_name ( ', ' column_name ) * ')' ) ? 'AS' select_statement ( 'WITH' ( 'NO' ) ? 'DATA' ) ? )
at line 352
private void
fillTableField(string $table, string $field, array $scolumns)
Copy the definitions of columns
at line 402
protected array
parseAlter(string $sql)
Parses a sql alter table statement according to this two BNF syntax :
ALTER TABLE table_name [ RENAME TO new_table_name | RENAME COLUMN column_name TO new_column_name | DROP [ COLUMN ] [IF EXISTS] column_name | DROP COMMENT | MODIFY COMMENT comment | MODIFY [ COLUMN ] column_name [ SET TYPE datatype | [ SET | REMOVE ] NOT NULL | [ SET DEFAULT default ] | REMOVE DEFAULT | [ SET | REMOVE ] PRIMARY KEY | [ SET | REMOVE ] [ AUTOINCREMENT|AUTO_INCREMENT|SERIAL ] | [ SET COMMENT comment ] | REMOVE COMMENT ] | [ SET TITLE title ] | REMOVE TITLE ] | ADD [ COLUMN ] column_name datatype [ NOT NULL|NULLABLE ] [ DEFAULT default ] [ PRIMARY KEY ] [ AUTOINCREMENT|AUTO_INCREMENT|SERIAL ] [ COMMENT comment ] ]
or eBNF syntax :
'ALTER' 'TABLE' table_name ( 'RENAME TO' new_table_name | 'RENAME COLUMN' column_name 'TO' new_column_name | 'DROP' 'COLUMN' ? 'IF EXISTS' ? column_name | 'DROP' 'COMMENT' | 'MODIFY' 'COMMENT' comment | 'MODIFY' 'COLUMN' ? column_name ( 'SET TYPE' datatype | ( ('SET' | 'REMOVE' ) 'NOT NULL' ) | ( 'SET DEFAULT' default ) | 'REMOVE DEFAULT' | ( 'SET' | 'REMOVE' ) 'PRIMARY KEY' | ( 'SET' | 'REMOVE' ) ('AUTOINCREMENT'|'AUTO_INCREMENT'|'SERIAL') | ( 'SET TITLE' title ) | 'REMOVE TITLE') | 'ADD' 'COLUMN' ? column_name datatype 'NOT NULL' ? ( 'DEFAULT' default ) ? ( 'PRIMARY KEY' ) ? ( 'AUTOINCREMENT' | 'AUTO_INCREMENT' | 'SERIAL' ) ? ( 'TITLE' title ) ? ( 'COMMENT' comment ) ? )
at line 679
protected array
parseDropTable(string $sql)
Parses a sql drop table statement according to this BNF syntax :
DROP TABLE [ IF EXISTS ] table_name { ', ' table_name }
or eBNF syntax :
'DROP TABLE' ( 'IF EXISTS' ) ? table_name ( ', ' table_name ) *
at line 702
private string
encodeLiteral(string $text)
Encode text between quote with base64
at line 728
private string
decodeLiteral($text, $withQuotes = false)
Decode text encoded with base64