Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array_key_exists warning when parsing a "DEFAULT FALSE" token #299

Closed
devnix opened this issue Apr 13, 2020 · 8 comments
Closed

array_key_exists warning when parsing a "DEFAULT FALSE" token #299

devnix opened this issue Apr 13, 2020 · 8 comments
Assignees
Labels
Milestone

Comments

@devnix
Copy link

devnix commented Apr 13, 2020

PHP Warning:  array_key_exists(): The first argument should be either a string or an integer in /var/www/html/vendor/phpmyadmin/sql-parser/src/Components/AlterOperation.php on line 286

A dump inside AlterOperation.php gives me the following result:
image

I don't have any idea if the value attribute should be a boolean in this case, so I'm not starting a PR right now. I don't know if the correct solution would be to cast to string on the array_key_exists itself, or to save the value attribute as a string instead of a boolean...

@onlime
Copy link

onlime commented Oct 10, 2020

This still happens in latest PMA 5.0.3:

Warning in ./vendor/phpmyadmin/sql-parser/src/Components/AlterOperation.php#284
array_key_exists(): The first argument should be either a string or an integer

Any idea how this could be fixed?

@williamdes williamdes added the bug label Oct 10, 2020
@williamdes williamdes added this to the 4.7.1 milestone Oct 10, 2020
@williamdes
Copy link
Member

I added this to a milestone to have a fix as quickly as possible.

@shucon
Copy link
Contributor

shucon commented Oct 12, 2020

Starting to work on this issue.

@shucon
Copy link
Contributor

shucon commented Oct 12, 2020

I'm not sure how to replicate the issue. Any steps to replicate would be appreciated. 😄

@onlime
Copy link

onlime commented Oct 12, 2020

Here you go, @shucon, you can reproduce it with the following simple .sql file, stripped down from some of my customer's schema:

DROP TABLE IF EXISTS `searches`;
CREATE TABLE `searches` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `public_name` varchar(120) COLLATE utf8_unicode_ci NOT NULL,
  `group_id` smallint(5) unsigned NOT NULL DEFAULT '0',
  `shortdesc` tinytext COLLATE utf8_unicode_ci,
  `show_separators` tinyint(1) NOT NULL DEFAULT '0',
  `deleted` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

ALTER TABLE `searches` ADD `admins_only` BOOLEAN NOT NULL DEFAULT FALSE AFTER `show_separators`;

The problem only seems to occur, if we add a DEFAULT FALSE field in an ALTER TABLE statement, not if it is set directly in CREATE TABLE.

On a PMA 5.0.3 / phpmyadmin/sql-parser 5.4.0 import we then get the following warning:

Warning in ./vendor/phpmyadmin/sql-parser/src/Components/AlterOperation.php#284
array_key_exists(): The first argument should be either a string or an integer

Please let me know if you can now reproduce it.

shucon added a commit to shucon/sql-parser that referenced this issue Oct 12, 2020
Signed-off-by: Saksham Gupta <[email protected]>
@shucon
Copy link
Contributor

shucon commented Oct 12, 2020

Hello @onlime thanks for a detailed explanation. I was able to reproduce the issue, but not consistently. Can you please verify that the above patch resolves the problem?

@onlime
Copy link

onlime commented Oct 12, 2020

Hi @shucon. Great, thanks! I have applied your patch and confirm it to be fully working (tried it with the stripped down .sql above and the full import of the customer with a bunch of such ALTER TABLE statements). Please push it into the next 5.4.x release.

for those who forgot how to download a patch based on a commit on Github, here's you go:

$ cd vendor/phpmyadmin/sql-parser/
$ wget https://github.com/shucon/sql-parser/commit/f6ac59ae87a1e548aa7e1dc39352fbb86b0f6da9.patch
$ patch -p1 < f6ac59ae87a1e548aa7e1dc39352fbb86b0f6da9.patch

@williamdes williamdes self-assigned this Oct 13, 2020
williamdes added a commit to shucon/sql-parser that referenced this issue Oct 13, 2020
Signed-off-by: William Desportes <[email protected]>
williamdes added a commit that referenced this issue Oct 13, 2020
…FAULT FALSE" token

Pull-request: #314
Fixes: #299

Signed-off-by: William Desportes <[email protected]>
williamdes added a commit that referenced this issue Oct 13, 2020
Signed-off-by: William Desportes <[email protected]>
@ibennetch
Copy link
Member

sql-parser 4.7.1 and 5.4.1 were released today, as were phpMyAdmin 4.9.7 and 5.0.4 which fix this.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants