Skip to content

Commit 7027048

Browse files
committed
Merge branch 'QA'
Signed-off-by: William Desportes <[email protected]>
2 parents 969adef + 4601f68 commit 7027048

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
## [5.4.1] - 2020-10-10
4+
* Fix array_key_exists warning when parsing a "DEFAULT FALSE" token (#299)
5+
36
## [5.4.0] - 2020-10-08
47

58
* EXISTS is also a function. (#297)
@@ -54,6 +57,9 @@
5457
* Fix for error message with multiple CALL statements (#223)
5558
* Recognize the question mark character as a parameter (#242)
5659

60+
## [4.7.1] - 2020-10-10
61+
* Fix array_key_exists warning when parsing a "DEFAULT FALSE" token (#299)
62+
5763
## [4.7.0] - 2020-10-08
5864

5965
* EXISTS is also a function. (#297)

src/Components/AlterOperation.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use PhpMyAdmin\SqlParser\TokensList;
1414
use function array_key_exists;
1515
use function in_array;
16+
use function is_numeric;
17+
use function is_string;
1618

1719
/**
1820
* Parses an alter operation.
@@ -262,6 +264,12 @@ public static function parse(Parser $parser, TokensList $list, array $options =
262264

263265
$state = 2;
264266
} elseif ($state === 2) {
267+
$array_key = '';
268+
if (is_string($token->value) || is_numeric($token->value)) {
269+
$array_key = $token->value;
270+
} else {
271+
$array_key = $token->token;
272+
}
265273
if ($token->type === Token::TYPE_OPERATOR) {
266274
if ($token->value === '(') {
267275
++$brackets;
@@ -281,9 +289,9 @@ public static function parse(Parser $parser, TokensList $list, array $options =
281289
);
282290
break;
283291
}
284-
} elseif ((array_key_exists($token->value, self::$DB_OPTIONS)
285-
|| array_key_exists($token->value, self::$TABLE_OPTIONS))
286-
&& ! self::checkIfColumnDefinitionKeyword($token->value)
292+
} elseif ((array_key_exists($array_key, self::$DB_OPTIONS)
293+
|| array_key_exists($array_key, self::$TABLE_OPTIONS))
294+
&& ! self::checkIfColumnDefinitionKeyword($array_key)
287295
) {
288296
// This alter operation has finished, which means a comma
289297
// was missing before start of new alter operation

tests/Components/CreateDefinitionTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,38 @@ public function testBuild2()
101101
);
102102
}
103103

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

0 commit comments

Comments
 (0)