GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix #221 - parse truncate statement · phpmyadmin/sql-parser@04da59b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • Statement.php
    • Statements
      • TruncateStatement.php
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Statement.php‎

Copy file name to clipboardExpand all lines: src/Statement.php
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,15 @@ public function parse(Parser $parser, TokensList $list)
320320
}
321321

322322
// Checking if this is the beginning of a clause.
323-
if (! empty(Parser::$KEYWORD_PARSERS[$token->value]) && $list->idx < $list->count) {
324-
$class = Parser::$KEYWORD_PARSERS[$token->value]['class'];
325-
$field = Parser::$KEYWORD_PARSERS[$token->value]['field'];
326-
if (! empty(Parser::$KEYWORD_PARSERS[$token->value]['options'])) {
327-
$options = Parser::$KEYWORD_PARSERS[$token->value]['options'];
323+
// Fix Issue #221: As `truncate` is not a keyword
324+
// but it might be the beginning of a statement of truncate,
325+
// so let the value use the keyword field for truncate type.
326+
$token_value = in_array($token->keyword, ['TRUNCATE']) ? $token->keyword : $token->value;
327+
if (! empty(Parser::$KEYWORD_PARSERS[$token_value]) && $list->idx < $list->count) {
328+
$class = Parser::$KEYWORD_PARSERS[$token_value]['class'];
329+
$field = Parser::$KEYWORD_PARSERS[$token_value]['field'];
330+
if (! empty(Parser::$KEYWORD_PARSERS[$token_value]['options'])) {
331+
$options = Parser::$KEYWORD_PARSERS[$token_value]['options'];
328332
}
329333
}
330334

Collapse file

‎src/Statements/TruncateStatement.php‎

Copy file name to clipboardExpand all lines: src/Statements/TruncateStatement.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,14 @@ class TruncateStatement extends Statement
3333
* @var Expression
3434
*/
3535
public $table;
36+
37+
/**
38+
* Special build method for truncate statement as Statement::build would return empty string.
39+
*
40+
* @return string
41+
*/
42+
public function build()
43+
{
44+
return 'TRUNCATE TABLE ' . $this->table . ';';
45+
}
3646
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.