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

SET statement / SET type #168

Closed
nijel opened this issue Sep 4, 2017 · 6 comments
Closed

SET statement / SET type #168

nijel opened this issue Sep 4, 2017 · 6 comments
Assignees
Labels
Milestone

Comments

@nijel
Copy link
Contributor

nijel commented Sep 4, 2017

It seems that the parser seems to treat SET as statement even when it should not:

./bin/lint-query --query 'ALTER TABLE `table_name` ADD `new_column_name` SET ('value1','value2','value3') NOT NULL AFTER `another_column`'
#1: A new statement was found, but no delimiter between it and the previous one. (near "SET" at position 47)
#2: Unrecognized alter operation. (near "," at position 65)
#3: Unrecognized alter operation. (near "" at position 0)

See phpmyadmin/phpmyadmin#13636

@kapersoft
Copy link

I am also having troubles with the SET-expression in ALTER TABLE-queries:

$query = "ALTER TABLE `table_name` ADD `new_column_name` SET ('value1','value2','value3') NOT NULL AFTER `another_column`";
$parser = new \PhpMyAdmin\SqlParser\Parser($query);
var_dump($parser->statements);

In the var-dump the SET'-, (-expressions and the first value between parentheses 'value1' are missing.

I am willing to dig into this problem and submit a PR. Any ideas where to start?

array(1) {
  [0] =>
  class PhpMyAdmin\SqlParser\Statements\AlterStatement#31 (5) {
    public $table =>
    class PhpMyAdmin\SqlParser\Components\Expression#33 (7) {
      public $database =>
      NULL
      public $table =>
      string(10) "table_name"
      public $column =>
      NULL
      public $expr =>
      string(12) "`table_name`"
      public $alias =>
      NULL
      public $function =>
      NULL
      public $subquery =>
      NULL
    }
    public $altered =>
    array(3) {
      [0] =>
      class PhpMyAdmin\SqlParser\Components\AlterOperation#34 (3) {
        public $options =>
        class PhpMyAdmin\SqlParser\Components\OptionsArray#35 (1) {
          public $options =>
          array(1) {
            [1] =>
            string(3) "ADD"
          }
        }
        public $field =>
        class PhpMyAdmin\SqlParser\Components\Expression#36 (7) {
          public $database =>
          NULL
          public $table =>
          NULL
          public $column =>
          string(15) "new_column_name"
          public $expr =>
          string(17) "`new_column_name`"
          public $alias =>
          NULL
          public $function =>
          NULL
          public $subquery =>
          NULL
        }
        public $unknown =>
        array(0) {
        }
      }
      [1] =>
      class PhpMyAdmin\SqlParser\Components\AlterOperation#38 (3) {
        public $options =>
        class PhpMyAdmin\SqlParser\Components\OptionsArray#39 (1) {
          public $options =>
          array(0) {
          }
        }
        public $field =>
        class PhpMyAdmin\SqlParser\Components\Expression#40 (7) {
          public $database =>
          NULL
          public $table =>
          NULL
          public $column =>
          string(6) "value2"
          public $expr =>
          string(8) "'value2'"
          public $alias =>
          NULL
          public $function =>
          NULL
          public $subquery =>
          NULL
        }
        public $unknown =>
        array(0) {
        }
      }
      [2] =>
      class PhpMyAdmin\SqlParser\Components\AlterOperation#42 (3) {
        public $options =>
        class PhpMyAdmin\SqlParser\Components\OptionsArray#43 (1) {
          public $options =>
          array(0) {
          }
        }
        public $field =>
        class PhpMyAdmin\SqlParser\Components\Expression#44 (7) {
          public $database =>
          NULL
          public $table =>
          NULL
          public $column =>
          string(6) "value3"
          public $expr =>
          string(8) "'value3'"
          public $alias =>
          NULL
          public $function =>
          NULL
          public $subquery =>
          NULL
        }
        public $unknown =>
        array(7) {
          [0] =>
          class PhpMyAdmin\SqlParser\Token#23 (6) {
            public $token =>
            string(1) ")"
            public $value =>
            string(1) ")"
            public $keyword =>
            NULL
            public $type =>
            int(2)
            public $flags =>
            int(16)
            public $position =>
            int(78)
          }
          [1] =>
          class PhpMyAdmin\SqlParser\Token#24 (6) {
            public $token =>
            string(1) " "
            public $value =>
            string(1) " "
            public $keyword =>
            NULL
            public $type =>
            int(3)
            public $flags =>
            int(0)
            public $position =>
            int(79)
          }
          [2] =>
          class PhpMyAdmin\SqlParser\Token#26 (6) {
            public $token =>
            string(8) "NOT NULL"
            public $value =>
            string(8) "NOT NULL"
            public $keyword =>
            string(8) "NOT NULL"
            public $type =>
            int(1)
            public $flags =>
            int(7)
            public $position =>
            int(80)
          }
          [3] =>
          class PhpMyAdmin\SqlParser\Token#25 (6) {
            public $token =>
            string(1) " "
            public $value =>
            string(1) " "
            public $keyword =>
            NULL
            public $type =>
            int(3)
            public $flags =>
            int(0)
            public $position =>
            int(88)
          }
          [4] =>
          class PhpMyAdmin\SqlParser\Token#27 (6) {
            public $token =>
            string(5) "AFTER"
            public $value =>
            string(5) "AFTER"
            public $keyword =>
            string(5) "AFTER"
            public $type =>
            int(1)
            public $flags =>
            int(1)
            public $position =>
            int(89)
          }
          [5] =>
          class PhpMyAdmin\SqlParser\Token#28 (6) {
            public $token =>
            string(1) " "
            public $value =>
            string(1) " "
            public $keyword =>
            NULL
            public $type =>
            int(3)
            public $flags =>
            int(0)
            public $position =>
            int(94)
          }
          [6] =>
          class PhpMyAdmin\SqlParser\Token#30 (6) {
            public $token =>
            string(16) "`another_column`"
            public $value =>
            string(14) "another_column"
            public $keyword =>
            NULL
            public $type =>
            int(8)
            public $flags =>
            int(2)
            public $position =>
            int(95)
          }
        }
      }
    }
    public $options =>
    class PhpMyAdmin\SqlParser\Components\OptionsArray#32 (1) {
      public $options =>
      array(1) {
        [3] =>
        string(5) "TABLE"
      }
    }
    public $first =>
    int(0)
    public $last =>
    int(25)
  }
}

@MisterCoder
Copy link

Also hitting this issue

@williamdes
Copy link
Member

If someone can open a PR I will be glad to review and merge it :)

@Tomoms
Copy link

Tomoms commented Mar 18, 2020

I'm having the same problem.
ALTER TABLE test ALTER score SET DEFAULT 0;
fails to run because "A new statement was found, ..." etc.

@williamdes williamdes self-assigned this May 19, 2021
@williamdes williamdes added this to the 4.7.3 milestone May 19, 2021
williamdes added a commit that referenced this issue May 19, 2021
Signed-off-by: William Desportes <[email protected]>
@williamdes williamdes linked a pull request May 19, 2021 that will close this issue
@williamdes
Copy link
Member

I added test cases for this issue in ded1fea

williamdes added a commit that referenced this issue May 19, 2021
Signed-off-by: William Desportes <[email protected]>
williamdes added a commit that referenced this issue Aug 15, 2021
williamdes added a commit that referenced this issue Aug 16, 2021
Signed-off-by: William Desportes <[email protected]>
williamdes added a commit that referenced this issue Aug 16, 2021
Pull-request: #344

Signed-off-by: William Desportes <[email protected]>
williamdes added a commit that referenced this issue Aug 16, 2021
Pull-request: #344

Signed-off-by: William Desportes <[email protected]>
williamdes added a commit that referenced this issue Aug 16, 2021
Pull-request: #344

Signed-off-by: William Desportes <[email protected]>
williamdes added a commit that referenced this issue Aug 16, 2021
Signed-off-by: William Desportes <[email protected]>
@williamdes
Copy link
Member

Hi @kapersoft
Are you still up to test the latest dev version ?

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

Successfully merging a pull request may close this issue.

5 participants