-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use WP coding styles for filenames, use file per class, improve direc…
…tory structure
- Loading branch information
Showing
14 changed files
with
564 additions
and
519 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
// throw exception if anything fails | ||
set_error_handler( | ||
function ( $severity, $message, $file, $line ) { | ||
throw new ErrorException( $message, 0, $severity, $file, $line ); | ||
} | ||
); | ||
|
||
require_once __DIR__ . '/../../wp-includes/mysql/class-mysql-lexer.php'; | ||
require_once __DIR__ . '/../../wp-includes/parser/class-parser.php'; | ||
|
||
$grammar_data = include __DIR__ . '/../../wp-includes/mysql/mysql-grammar.php'; | ||
$grammar = new Grammar( $grammar_data ); | ||
|
||
|
||
//$tokens = tokenizeQuery('SELECT x FROM t'); | ||
//$tokens = tokenizeQuery('ALTER TABLE t1 ORDER BY t1.id'); | ||
//$tokens = tokenizeQuery("SELECT CAST(1988 AS YEAR)"); | ||
//$tokens = tokenizeQuery("DROP FUNCTION x"); | ||
//$tokens = tokenizeQuery("SELECT ROW_NUMBER() OVER (PARTITION BY g)"); | ||
//$tokens = tokenizeQuery("GRANT ALL ON db.t1 TO 'testuser'@'localhost'"); | ||
//$tokens = tokenizeQuery("SELECT id max FROM t"); | ||
//$tokens = tokenizeQuery("CREATE TABLE t (tmst TIMESTAMP DEFAULT NOW())"); | ||
//$tokens = tokenizeQuery("SELECT CURRENT_TIMESTAMP"); | ||
//$tokens = tokenizeQuery("SELECT TIMESTAMP'2015-01-01 12:00:00'"); | ||
//$tokens = tokenizeQuery("create table `#mysql50#abc``def` ( id int )"); | ||
//$tokens = tokenizeQuery("INSERT INTO `±íÒ»` VALUES (' !\"\"#$%&\'()*+,-./');"); | ||
//$tokens = tokenizeQuery("SELECT ADDDATE(DATE'2021-01-01', INTERVAL 1 DAY)"); | ||
//$tokens = tokenizeQuery("select 1ea10.1a20,1e+ 1e+10 from 1ea10"); | ||
//$tokens = tokenizeQuery("ALTER TABLE t2 ALTER my_row_id SET VISIBLE"); | ||
//$tokens = tokenizeQuery("ANALYZE TABLE t UPDATE HISTOGRAM ON col1 USING DATA ''"); | ||
//$tokens = tokenizeQuery("((SELECT 1 UNION SELECT 1) UNION SELECT 2)"); | ||
//$tokens = tokenizeQuery("alter user mysqltest_7@"); | ||
//$tokens = tokenizeQuery("SELECT * FROM t0 WHERE a < ANY (VALUES ROW(1))"); | ||
//$tokens = tokenizeQuery("SELECT 1 /*!99999 /* */ */"); | ||
//$tokens = tokenizeQuery("SHOW GRANTS FOR u1 using r1"); | ||
//$tokens = tokenizeQuery("(SELECT 1) LIMIT 1 INTO @var"); | ||
//$tokens = tokenizeQuery("DO ST_AsText(@centroid_point)"); | ||
//$tokens = tokenizeQuery("ALTER SCHEMA s1 READ ONLY DEFAULT"); | ||
$tokens = tokenize_query( 'CREATE TABLE t1 (g MULTIPOINT)' ); | ||
|
||
foreach ( $tokens as $token ) { | ||
echo $token, PHP_EOL; | ||
} | ||
$parser = new Parser( $grammar, $tokens ); | ||
$parse_tree = $parser->parse(); | ||
var_dump( $parse_tree ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
class MySQL_Token { | ||
public $type; | ||
public $text; | ||
public $channel; | ||
|
||
public function __construct( $type, $text, $channel = null ) { | ||
$this->type = $type; | ||
$this->text = $text; | ||
$this->channel = $channel; | ||
} | ||
|
||
public function get_type() { | ||
return $this->type; | ||
} | ||
|
||
public function get_name() { | ||
return MySQL_Lexer::get_token_name( $this->type ); | ||
} | ||
|
||
public function get_text() { | ||
return $this->text; | ||
} | ||
|
||
public function get_channel() { | ||
return $this->channel; | ||
} | ||
|
||
public function __toString() { | ||
return $this->text . '<' . $this->type . ',' . $this->get_name() . '>'; | ||
} | ||
|
||
public function extract_value() { | ||
if ( MySQL_Lexer::BACK_TICK_QUOTED_ID === $this->type ) { | ||
return substr( $this->text, 1, -1 ); | ||
} elseif ( MySQL_Lexer::DOUBLE_QUOTED_TEXT === $this->type ) { | ||
return substr( $this->text, 1, -1 ); | ||
} elseif ( MySQL_Lexer::SINGLE_QUOTED_TEXT === $this->type ) { | ||
return substr( $this->text, 1, -1 ); | ||
} else { | ||
return $this->text; | ||
} | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.