Skip to content

Commit 45a5c60

Browse files
committed
Merge #354 and #349 - Fix #348 - Fixing missing KEY options for MySQL and MariaDB
Ref: phpmyadmin/phpmyadmin#17097 Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents 81b118f + f67869e commit 45a5c60

File tree

5 files changed

+127
-2
lines changed

5 files changed

+127
-2
lines changed

src/Components/Key.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Key extends Component
3131
public static $KEY_OPTIONS = array(
3232
'KEY_BLOCK_SIZE' => array(
3333
1,
34-
'var',
34+
'var=',
3535
),
3636
'USING' => array(
3737
2,
@@ -44,7 +44,26 @@ class Key extends Component
4444
'COMMENT' => array(
4545
4,
4646
'var',
47-
)
47+
),
48+
// MariaDB options
49+
'CLUSTERING' => array(
50+
4,
51+
'var=',
52+
),
53+
'ENGINE_ATTRIBUTE' => array(
54+
5,
55+
'var=',
56+
),
57+
'SECONDARY_ENGINE_ATTRIBUTE' => array(
58+
5,
59+
'var=',
60+
),
61+
// MariaDB & MySQL options
62+
'VISIBLE' => 6,
63+
'INVISIBLE' => 6,
64+
// MariaDB options
65+
'IGNORED' => 10,
66+
'NOT IGNORED' => 10,
4867
);
4968

5069
/**

tests/Components/KeyTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,65 @@ public function testParseKeyWithLengthWithOptions()
170170
);
171171
}
172172

173+
public function testParseKeyWithLengthWithAllOptions()
174+
{
175+
$component = Key::parse(
176+
new Parser(),
177+
$this->getTokensList(
178+
// This is not a vary plausible example but it runs
179+
// Only ENGINE_ATTRIBUTE gives a not supported error but is still a valid syntax
180+
'KEY `alias_type_idx` (`alias_type`(10))'
181+
. ' COMMENT \'my comment\' VISIBLE KEY_BLOCK_SIZE=1'
182+
. ' INVISIBLE ENGINE_ATTRIBUTE \'foo\' SECONDARY_ENGINE_ATTRIBUTE=\'bar\' USING BTREE,'
183+
)
184+
);
185+
$this->assertEquals('KEY', $component->type);
186+
$this->assertEquals('alias_type_idx', $component->name);
187+
$this->assertEquals(new OptionsArray(
188+
array(
189+
1 => array(
190+
'name' => 'KEY_BLOCK_SIZE',
191+
'equals' => true,
192+
'expr' => '1',
193+
'value' => '1',
194+
),
195+
2 => array(
196+
'name' => 'USING',
197+
'equals' => false,
198+
'expr' => 'BTREE',
199+
'value' => 'BTREE',
200+
),
201+
4 => array(
202+
'name' => 'COMMENT',
203+
'equals' => false,
204+
'expr' => '\'my comment\'',
205+
'value' => 'my comment',
206+
),
207+
5 => array(
208+
'name' => 'ENGINE_ATTRIBUTE',
209+
'equals' => true,
210+
'expr' => '\'foo\'',
211+
'value' => 'foo',
212+
),
213+
6 => 'VISIBLE',
214+
12 => 'INVISIBLE',
215+
13 => array(
216+
'name' => 'SECONDARY_ENGINE_ATTRIBUTE',
217+
'equals' => true,
218+
'expr' => '\'bar\'',
219+
'value' => 'bar',
220+
),
221+
)
222+
), $component->options);
223+
$this->assertNull($component->expr);
224+
$this->assertSame(array(
225+
array(
226+
'name' => 'alias_type',
227+
'length' => 10,
228+
)
229+
), $component->columns);
230+
}
231+
173232
public function testParseKeyExpressionWithoutOptions()
174233
{
175234
$component = Key::parse(

tests/Parser/CreateStatementTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function createProvider()
4747
array('parser/parseCreateTableLike'),
4848
array('parser/parseCreateTableSpatial'),
4949
array('parser/parseCreateTableTimestampWithPrecision'),
50+
array('parser/parseCreateTableWithInvisibleKey'),
5051
array('parser/parseCreateTrigger'),
5152
array('parser/parseCreateUser'),
5253
array('parser/parseCreateView'),
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE TABLE `animes_comments` (
2+
`anime_comment_id` bigint unsigned NOT NULL AUTO_INCREMENT,
3+
`anime_id` bigint unsigned NOT NULL,
4+
`user_id` bigint unsigned NOT NULL,
5+
`comment_text` varchar(500) COLLATE utf8mb4_general_ci DEFAULT NULL,
6+
`comment_at` datetime DEFAULT NULL,
7+
PRIMARY KEY (`anime_comment_id`),
8+
KEY `animes_comments_animes_fk` (`anime_id`) invisible,
9+
KEY `animes_comments_users_fk` (`user_id`),
10+
KEY `comment_at_idx` (`comment_at`) ,
11+
CONSTRAINT `animes_comments_animes_fk` FOREIGN KEY (`anime_id`) REFERENCES `animes` (`anime_id`) ON DELETE CASCADE ON UPDATE RESTRICT,
12+
CONSTRAINT `animes_comments_users_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE RESTRICT)

0 commit comments

Comments
 (0)