Skip to content

Commit b245139

Browse files
committed
Add missing KEY options for MySQL and MariaDB
Signed-off-by: William Desportes <williamdes@wdes.fr>
1 parent 1eb7d53 commit b245139

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-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+
'INVISIBLE' => 1,
49+
'VISIBLE' => 1,
50+
'ENGINE_ATTRIBUTE' => array(
51+
3,
52+
'var=',
53+
),
54+
'SECONDARY_ENGINE_ATTRIBUTE' => array(
55+
4,
56+
'var=',
57+
),
58+
59+
// MariaDB options
60+
61+
'CLUSTERING' => array(
62+
4,
63+
'var=',
64+
),
65+
'IGNORED' => 1,
66+
'NOT IGNORED' => 1,
4867
);
4968

5069
/**

tests/Components/KeyTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,65 @@ public function testParseKeyWithLengthWithOptions()
8585
), $component->columns);
8686
}
8787

88+
public function testParseKeyWithLengthWithAllOptions()
89+
{
90+
$component = Key::parse(
91+
new Parser(),
92+
$this->getTokensList(
93+
// This is not a vary plausible example but it runs
94+
// Only ENGINE_ATTRIBUTE gives a not supported error but is still a valid syntax
95+
'KEY `alias_type_idx` (`alias_type`(10))'
96+
. ' COMMENT \'my comment\' VISIBLE KEY_BLOCK_SIZE=1'
97+
. ' INVISIBLE ENGINE_ATTRIBUTE \'foo\' SECONDARY_ENGINE_ATTRIBUTE=\'bar\' USING BTREE,'
98+
)
99+
);
100+
$this->assertEquals('KEY', $component->type);
101+
$this->assertEquals('alias_type_idx', $component->name);
102+
$this->assertEquals(new OptionsArray(
103+
array(
104+
1 => 'VISIBLE',
105+
2 => array(
106+
'name' => 'USING',
107+
'equals' => false,
108+
'expr' => 'BTREE',
109+
'value' => 'BTREE',
110+
),
111+
3 => array(
112+
'name' => 'ENGINE_ATTRIBUTE',
113+
'equals' => true,
114+
'expr' => '\'foo\'',
115+
'value' => 'foo',
116+
),
117+
4 => array(
118+
'name' => 'COMMENT',
119+
'equals' => false,
120+
'expr' => '\'my comment\'',
121+
'value' => 'my comment',
122+
),
123+
12 => array(
124+
'name' => 'KEY_BLOCK_SIZE',
125+
'equals' => true,
126+
'expr' => '1',
127+
'value' => '1',
128+
),
129+
13 => 'INVISIBLE',
130+
14 => array(
131+
'name' => 'SECONDARY_ENGINE_ATTRIBUTE',
132+
'equals' => true,
133+
'expr' => '\'bar\'',
134+
'value' => 'bar',
135+
),
136+
)
137+
), $component->options);
138+
$this->assertNull($component->expr);
139+
$this->assertSame(array(
140+
array(
141+
'name' => 'alias_type',
142+
'length' => 10,
143+
)
144+
), $component->columns);
145+
}
146+
88147
public function testParseKeyExpressionWithoutOptions()
89148
{
90149
$component = Key::parse(

0 commit comments

Comments
 (0)