Skip to content

Commit 9b2d4ca

Browse files
committed
Merge #314 - Fixes #299 - array_key_exists warning when parsing a "DEFAULT FALSE" token
Pull-request: #314 Fixes: #299 Signed-off-by: William Desportes <[email protected]>
2 parents b2467ef + 512db63 commit 9b2d4ca

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/Components/AlterOperation.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ public static function parse(Parser $parser, TokensList $list, array $options =
263263
}
264264
$state = 2;
265265
} elseif ($state === 2) {
266+
$array_key = '';
267+
if (is_string($token->value) || is_numeric($token->value)) {
268+
$array_key = $token->value;
269+
} else {
270+
$array_key = $token->token;
271+
}
266272
if ($token->type === Token::TYPE_OPERATOR) {
267273
if ($token->value === '(') {
268274
++$brackets;
@@ -282,9 +288,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
282288
);
283289
break;
284290
}
285-
} elseif ((array_key_exists($token->value, self::$DB_OPTIONS)
286-
|| array_key_exists($token->value, self::$TABLE_OPTIONS))
287-
&& ! self::checkIfColumnDefinitionKeyword($token->value)
291+
} elseif ((array_key_exists($array_key, self::$DB_OPTIONS)
292+
|| array_key_exists($array_key, self::$TABLE_OPTIONS))
293+
&& ! self::checkIfColumnDefinitionKeyword($array_key)
288294
) {
289295
// This alter operation has finished, which means a comma was missing before start of new alter operation
290296
$parser->error(

tests/Components/CreateDefinitionTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,38 @@ public function testBuild2()
9292
);
9393
}
9494

95+
public function testBuild3()
96+
{
97+
$parser = new Parser(
98+
'DROP TABLE IF EXISTS `searches`;'
99+
. 'CREATE TABLE `searches` ('
100+
. ' `id` int(10) unsigned NOT NULL AUTO_INCREMENT,'
101+
. ' `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,'
102+
. ' `public_name` varchar(120) COLLATE utf8_unicode_ci NOT NULL,'
103+
. ' `group_id` smallint(5) unsigned NOT NULL DEFAULT \'0\','
104+
. ' `shortdesc` tinytext COLLATE utf8_unicode_ci,'
105+
. ' `show_separators` tinyint(1) NOT NULL DEFAULT \'0\','
106+
. ' `show_separators_two` tinyint(1) NOT NULL DEFAULT FALSE,'
107+
. ' `deleted` tinyint(1) NOT NULL DEFAULT \'0\','
108+
. ' PRIMARY KEY (`id`)'
109+
. ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;'
110+
. ''
111+
. 'ALTER TABLE `searches` ADD `admins_only` BOOLEAN NOT NULL DEFAULT FALSE AFTER `show_separators`;'
112+
);
113+
$this->assertEquals(
114+
'`public_name` varchar(120) COLLATE utf8_unicode_ci NOT NULL',
115+
CreateDefinition::build($parser->statements[1]->fields[2])
116+
);
117+
$this->assertEquals(
118+
'`show_separators` tinyint(1) NOT NULL DEFAULT \'0\'',
119+
CreateDefinition::build($parser->statements[1]->fields[5])
120+
);
121+
$this->assertEquals(
122+
'`show_separators_two` tinyint(1) NOT NULL DEFAULT FALSE',
123+
CreateDefinition::build($parser->statements[1]->fields[6])
124+
);
125+
}
126+
95127
public function testBuildWithInvisibleKeyword()
96128
{
97129
$parser = new Parser(

0 commit comments

Comments
 (0)