-
-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathRenameStatement.php
More file actions
53 lines (46 loc) · 1.41 KB
/
RenameStatement.php
File metadata and controls
53 lines (46 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace PhpMyAdmin\SqlParser\Statements;
use PhpMyAdmin\SqlParser\Components\RenameOperation;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Parsers\RenameOperations;
use PhpMyAdmin\SqlParser\Statement;
use PhpMyAdmin\SqlParser\Token;
use PhpMyAdmin\SqlParser\TokensList;
use PhpMyAdmin\SqlParser\TokenType;
/**
* `RENAME` statement.
*
* RENAME TABLE tbl_name TO new_tbl_name
* [, tbl_name2 TO new_tbl_name2] ...
*/
class RenameStatement extends Statement
{
/**
* The old and new names of the tables.
*
* @var RenameOperation[]|null
*/
public array|null $renames = null;
/**
* Function called before the token is processed.
*
* Skips the `TABLE` keyword after `RENAME`.
*
* @param Parser $parser the instance that requests parsing
* @param TokensList $list the list of tokens to be parsed
* @param Token $token the token that is being parsed
*/
public function before(Parser $parser, TokensList $list, Token $token): void
{
if (($token->type !== TokenType::Keyword) || ($token->keyword !== 'RENAME')) {
return;
}
// Checking if it is the beginning of the query.
$list->getNextOfTypeAndValue(TokenType::Keyword, 'TABLE');
}
public function build(): string
{
return 'RENAME TABLE ' . RenameOperations::buildAll($this->renames);
}
}