Skip to content

Commit 9b4d299

Browse files
committed
Add test cases to show that ALTER TABLE … RENAME COLUMN is not OK.
1 parent 1ac927f commit 9b4d299

File tree

6 files changed

+908
-0
lines changed

6 files changed

+908
-0
lines changed

tests/Builder/AlterStatementTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,21 @@ public function testBuilderEventWithDefiner(): void
113113
$stmt = $parser->statements[0];
114114
$this->assertEquals($query, $stmt->build());
115115
}
116+
117+
118+
public function testBuilderRenameColumn(): void
119+
{
120+
$query = 'ALTER TABLE myTable RENAME COLUMN a TO b;';
121+
$parser = new Parser($query);
122+
$stmt = $parser->statements[0];
123+
$this->assertEquals($query, $stmt->build());
124+
}
125+
126+
public function testBuilderRenameColumns(): void
127+
{
128+
$query = 'ALTER TABLE myTable RENAME COLUMN a TO b, RENAME COLUMN b TO a;';
129+
$parser = new Parser($query);
130+
$stmt = $parser->statements[0];
131+
$this->assertEquals($query, $stmt->build());
132+
}
116133
}

tests/Parser/AlterStatementTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public function alterProvider(): array
7979
['parser/parseAlterEventOnScheduleEvery6'],
8080
['parser/parseAlterEventWithDefiner'],
8181
['parser/parseAlterEventWithOtherDefiners'],
82+
['parser/parseAlterRenameColumn'],
83+
['parser/parseAlterRenameColumns'],
8284
];
8385
}
8486
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE myTable RENAME COLUMN foo TO bar;
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
{
2+
"query": "ALTER TABLE myTable RENAME COLUMN foo TO bar;\n",
3+
"lexer": {
4+
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
5+
"str": "ALTER TABLE myTable RENAME COLUMN foo TO bar;\n",
6+
"len": 46,
7+
"last": 46,
8+
"list": {
9+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
10+
"tokens": [
11+
{
12+
"@type": "PhpMyAdmin\\SqlParser\\Token",
13+
"token": "ALTER",
14+
"value": "ALTER",
15+
"keyword": "ALTER",
16+
"type": 1,
17+
"flags": 3,
18+
"position": 0
19+
},
20+
{
21+
"@type": "PhpMyAdmin\\SqlParser\\Token",
22+
"token": " ",
23+
"value": " ",
24+
"keyword": null,
25+
"type": 3,
26+
"flags": 0,
27+
"position": 5
28+
},
29+
{
30+
"@type": "PhpMyAdmin\\SqlParser\\Token",
31+
"token": "TABLE",
32+
"value": "TABLE",
33+
"keyword": "TABLE",
34+
"type": 1,
35+
"flags": 3,
36+
"position": 6
37+
},
38+
{
39+
"@type": "PhpMyAdmin\\SqlParser\\Token",
40+
"token": " ",
41+
"value": " ",
42+
"keyword": null,
43+
"type": 3,
44+
"flags": 0,
45+
"position": 11
46+
},
47+
{
48+
"@type": "PhpMyAdmin\\SqlParser\\Token",
49+
"token": "myTable",
50+
"value": "myTable",
51+
"keyword": null,
52+
"type": 0,
53+
"flags": 0,
54+
"position": 12
55+
},
56+
{
57+
"@type": "PhpMyAdmin\\SqlParser\\Token",
58+
"token": " ",
59+
"value": " ",
60+
"keyword": null,
61+
"type": 3,
62+
"flags": 0,
63+
"position": 19
64+
},
65+
{
66+
"@type": "PhpMyAdmin\\SqlParser\\Token",
67+
"token": "RENAME",
68+
"value": "RENAME",
69+
"keyword": "RENAME",
70+
"type": 1,
71+
"flags": 3,
72+
"position": 20
73+
},
74+
{
75+
"@type": "PhpMyAdmin\\SqlParser\\Token",
76+
"token": " ",
77+
"value": " ",
78+
"keyword": null,
79+
"type": 3,
80+
"flags": 0,
81+
"position": 26
82+
},
83+
{
84+
"@type": "PhpMyAdmin\\SqlParser\\Token",
85+
"token": "COLUMN",
86+
"value": "COLUMN",
87+
"keyword": "COLUMN",
88+
"type": 1,
89+
"flags": 3,
90+
"position": 27
91+
},
92+
{
93+
"@type": "PhpMyAdmin\\SqlParser\\Token",
94+
"token": " ",
95+
"value": " ",
96+
"keyword": null,
97+
"type": 3,
98+
"flags": 0,
99+
"position": 33
100+
},
101+
{
102+
"@type": "PhpMyAdmin\\SqlParser\\Token",
103+
"token": "foo",
104+
"value": "foo",
105+
"keyword": null,
106+
"type": 0,
107+
"flags": 0,
108+
"position": 34
109+
},
110+
{
111+
"@type": "PhpMyAdmin\\SqlParser\\Token",
112+
"token": " ",
113+
"value": " ",
114+
"keyword": null,
115+
"type": 3,
116+
"flags": 0,
117+
"position": 37
118+
},
119+
{
120+
"@type": "PhpMyAdmin\\SqlParser\\Token",
121+
"token": "TO",
122+
"value": "TO",
123+
"keyword": "TO",
124+
"type": 1,
125+
"flags": 3,
126+
"position": 38
127+
},
128+
{
129+
"@type": "PhpMyAdmin\\SqlParser\\Token",
130+
"token": " ",
131+
"value": " ",
132+
"keyword": null,
133+
"type": 3,
134+
"flags": 0,
135+
"position": 40
136+
},
137+
{
138+
"@type": "PhpMyAdmin\\SqlParser\\Token",
139+
"token": "bar",
140+
"value": "bar",
141+
"keyword": null,
142+
"type": 0,
143+
"flags": 0,
144+
"position": 41
145+
},
146+
{
147+
"@type": "PhpMyAdmin\\SqlParser\\Token",
148+
"token": ";",
149+
"value": ";",
150+
"keyword": null,
151+
"type": 9,
152+
"flags": 0,
153+
"position": 44
154+
},
155+
{
156+
"@type": "PhpMyAdmin\\SqlParser\\Token",
157+
"token": "\n",
158+
"value": " ",
159+
"keyword": null,
160+
"type": 3,
161+
"flags": 0,
162+
"position": 45
163+
},
164+
{
165+
"@type": "PhpMyAdmin\\SqlParser\\Token",
166+
"token": null,
167+
"value": null,
168+
"keyword": null,
169+
"type": 9,
170+
"flags": 0,
171+
"position": null
172+
}
173+
],
174+
"count": 18,
175+
"idx": 18
176+
},
177+
"delimiter": ";",
178+
"delimiterLen": 1,
179+
"strict": false,
180+
"errors": []
181+
},
182+
"parser": {
183+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
184+
"list": {
185+
"@type": "@1"
186+
},
187+
"statements": [
188+
{
189+
"@type": "PhpMyAdmin\\SqlParser\\Statements\\AlterStatement",
190+
"table": {
191+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
192+
"database": null,
193+
"table": "myTable",
194+
"column": null,
195+
"expr": "myTable",
196+
"alias": null,
197+
"function": null,
198+
"subquery": null
199+
},
200+
"altered": [
201+
{
202+
"@type": "PhpMyAdmin\\SqlParser\\Components\\AlterOperation",
203+
"options": {
204+
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
205+
"options": {
206+
"1": "RENAME",
207+
"2": "COLUMN"
208+
}
209+
},
210+
"field": {
211+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
212+
"database": null,
213+
"table": null,
214+
"column": "foo",
215+
"expr": "foo",
216+
"alias": null,
217+
"function": null,
218+
"subquery": null
219+
},
220+
"partitions": null,
221+
"unknown": []
222+
}
223+
],
224+
"options": {
225+
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
226+
"options": {
227+
"3": "TABLE"
228+
}
229+
},
230+
"first": 0,
231+
"last": 15
232+
}
233+
],
234+
"brackets": 0,
235+
"strict": false,
236+
"errors": []
237+
},
238+
"errors": {
239+
"lexer": [],
240+
"parser": [
241+
[
242+
"Missing comma before start of a new alter operation.",
243+
{
244+
"@type": "@14"
245+
},
246+
0
247+
]
248+
]
249+
}
250+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE myTable RENAME COLUMN a TO b,
2+
RENAME COLUMN b TO c,
3+
RENAME COLUMN c TO d,
4+
RENAME COLUMN d TO a;

0 commit comments

Comments
 (0)