Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: greenlion/PHP-SQL-Parser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: manticoresoftware/PHP-SQL-Parser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Feb 24, 2024

  1. Source support

    djklim87 committed Feb 24, 2024
    Copy the full SHA
    fdf15f0 View commit details
  2. Source options support

    djklim87 committed Feb 24, 2024
    Copy the full SHA
    7a0612b View commit details
  3. Merge pull request #1 from manticoresoftware/feat/source-support

    Feat/source support
    djklim87 authored Feb 24, 2024
    Copy the full SHA
    a61ccec View commit details
  4. Change package name

    djklim87 committed Feb 24, 2024
    Copy the full SHA
    ce8d7be View commit details
  5. Merge remote-tracking branch 'origin/master'

    djklim87 committed Feb 24, 2024
    Copy the full SHA
    4afa83d View commit details
  6. Change package name

    djklim87 committed Feb 24, 2024
    Copy the full SHA
    e3526fe View commit details
  7. Revert sniffer's version

    djklim87 committed Feb 24, 2024
    Copy the full SHA
    3ecefaf View commit details

Commits on Mar 14, 2024

  1. Feat/show sources (#2)

    * Manticore's queries support
    
    ---------
    
    Co-authored-by: djklim87 <klim@manticoresearch.com>
    djklim87 and djklim87 authored Mar 14, 2024
    Copy the full SHA
    c928f6d View commit details

Commits on Mar 21, 2024

  1. Manticore's queries support

    djklim87 committed Mar 21, 2024
    Copy the full SHA
    8705a26 View commit details

Commits on Mar 28, 2024

  1. Replace Set with values field support

    djklim87 committed Mar 28, 2024
    Copy the full SHA
    b00d659 View commit details
  2. Replace Set with values field support

    djklim87 committed Mar 28, 2024
    Copy the full SHA
    0034db8 View commit details

Commits on Apr 4, 2024

  1. Feat/mv aliases (#3)

    * MV and MVS aliases
    
    * Batch option support
    
    ---------
    
    Co-authored-by: djklim87 <klim@manticoresearch.com>
    djklim87 and djklim87 authored Apr 4, 2024
    Copy the full SHA
    207ed7b View commit details

Commits on Apr 24, 2024

  1. Create like with data support (#4)

    * Create like with data support
    
    ---------
    
    Co-authored-by: djklim87 <klim@manticoresearch.com>
    djklim87 and djklim87 authored Apr 24, 2024
    Copy the full SHA
    62dcf91 View commit details
  2. Alter rename fixes (#5)

    Co-authored-by: djklim87 <klim@manticoresearch.com>
    djklim87 and djklim87 authored Apr 24, 2024
    Copy the full SHA
    4544fc6 View commit details

Commits on Apr 30, 2024

  1. Feat/profile (#6)

    * Improve lexer speed
    
    ---------
    
    Co-authored-by: djklim87 <klim@manticoresearch.com>
    djklim87 and djklim87 authored Apr 30, 2024
    Copy the full SHA
    2e0901f View commit details

Commits on May 9, 2024

  1. Alter table local option support (#7)

    * Alter table local option support
    
    ---------
    
    Co-authored-by: djklim87 <klim@manticoresearch.com>
    djklim87 and djklim87 authored May 9, 2024
    Copy the full SHA
    0cbe7e5 View commit details
  2. Alter table local option support

    djklim87 committed May 9, 2024
    Copy the full SHA
    3739fef View commit details

Commits on Dec 11, 2024

  1. Update tests for create source

    djklim87 committed Dec 11, 2024
    Copy the full SHA
    16c7843 View commit details

Commits on Jan 16, 2025

  1. Copy the full SHA
    47f2abf View commit details

Commits on Mar 13, 2025

  1. Copy the full SHA
    c8348fe View commit details
  2. Update CI actions version

    djklim87 committed Mar 13, 2025
    Copy the full SHA
    6a38754 View commit details
  3. Fix tests

    djklim87 committed Mar 13, 2025
    Copy the full SHA
    0552cfd View commit details
  4. Fix tests (#8)

    Co-authored-by: djklim87 <klim@manticoresearch.com>
    djklim87 and djklim87 authored Mar 13, 2025
    Copy the full SHA
    bb4b4bf View commit details
Showing with 1,653 additions and 800 deletions.
  1. +2 −8 .github/workflows/ci.yml
  2. +1 −1 composer.json
  3. +70 −66 src/PHPSQLParser/PHPSQLCreator.php
  4. +61 −0 src/PHPSQLParser/builders/AddBuilder.php
  5. +5 −19 src/PHPSQLParser/builders/AlterBuilder.php
  6. +23 −7 src/PHPSQLParser/builders/AlterStatementBuilder.php
  7. +100 −84 src/PHPSQLParser/lexer/PHPSQLLexer.php
  8. +2 −2 src/PHPSQLParser/positions/PositionCalculator.php
  9. +3 −3 src/PHPSQLParser/processors/AbstractProcessor.php
  10. +136 −0 src/PHPSQLParser/processors/AddProcessor.php
  11. +96 −0 src/PHPSQLParser/processors/AlterProcessor.php
  12. +7 −0 src/PHPSQLParser/processors/CreateProcessor.php
  13. +7 −1 src/PHPSQLParser/processors/DropProcessor.php
  14. +1 −1 src/PHPSQLParser/processors/RenameProcessor.php
  15. +23 −0 src/PHPSQLParser/processors/SQLChunkProcessor.php
  16. +418 −352 src/PHPSQLParser/processors/SQLProcessor.php
  17. +15 −0 src/PHPSQLParser/processors/ShowProcessor.php
  18. +230 −0 src/PHPSQLParser/processors/SourceProcessor.php
  19. +256 −232 src/PHPSQLParser/processors/TableProcessor.php
  20. +2 −0 src/PHPSQLParser/utils/ExpressionType.php
  21. +1 −1 src/PHPSQLParser/utils/PHPSQLParserConstants.php
  22. +2 −2 tests/cases/creator/AlterTest.php
  23. +0 −10 tests/cases/creator/issue33Test.php
  24. +1 −0 tests/cases/parser/issue233Test.php
  25. +0 −9 tests/cases/parser/issue33Test.php
  26. +142 −0 tests/cases/parser/manticoreCasesTest.php
  27. +1 −2 tests/expected/creator/alter2.sql
  28. +1 −0 tests/expected/parser/ms_alter_source_1.serialized
  29. +1 −0 tests/expected/parser/ms_alter_source_2.serialized
  30. +1 −0 tests/expected/parser/ms_alter_source_3.serialized
  31. +1 −0 tests/expected/parser/ms_alter_table_1.serialized
  32. +1 −0 tests/expected/parser/ms_alter_table_2.serialized
  33. +1 −0 tests/expected/parser/ms_alter_table_3.serialized
  34. +1 −0 tests/expected/parser/ms_alter_table_4.serialized
  35. +1 −0 tests/expected/parser/ms_alter_table_5.serialized
  36. +1 −0 tests/expected/parser/ms_alter_table_6.serialized
  37. +1 −0 tests/expected/parser/ms_alter_view_1.serialized
  38. +1 −0 tests/expected/parser/ms_alter_view_2.serialized
  39. +1 −0 tests/expected/parser/ms_alter_view_3.serialized
  40. +1 −0 tests/expected/parser/ms_alter_view_4.serialized
  41. +1 −0 tests/expected/parser/ms_create_source_1.serialized
  42. +1 −0 tests/expected/parser/ms_create_source_2.serialized
  43. +1 −0 tests/expected/parser/ms_create_source_3.serialized
  44. +1 −0 tests/expected/parser/ms_create_source_4.serialized
  45. +1 −0 tests/expected/parser/ms_create_table_1.serialized
  46. +1 −0 tests/expected/parser/ms_create_table_2.serialized
  47. +1 −0 tests/expected/parser/ms_create_table_3.serialized
  48. +1 −0 tests/expected/parser/ms_create_view_1.serialized
  49. +1 −0 tests/expected/parser/ms_create_view_2.serialized
  50. +1 −0 tests/expected/parser/ms_drop_source_1.serialized
  51. +1 −0 tests/expected/parser/ms_drop_source_2.serialized
  52. +1 −0 tests/expected/parser/ms_drop_source_3.serialized
  53. +1 −0 tests/expected/parser/ms_drop_table_1.serialized
  54. +1 −0 tests/expected/parser/ms_drop_table_2.serialized
  55. +1 −0 tests/expected/parser/ms_drop_table_3.serialized
  56. +1 −0 tests/expected/parser/ms_drop_view_1.serialized
  57. +1 −0 tests/expected/parser/ms_drop_view_2.serialized
  58. +1 −0 tests/expected/parser/ms_drop_view_3.serialized
  59. +1 −0 tests/expected/parser/ms_drop_view_4.serialized
  60. +1 −0 tests/expected/parser/ms_replace_1.serialized
  61. +1 −0 tests/expected/parser/ms_replace_2.serialized
  62. +1 −0 tests/expected/parser/ms_replace_3.serialized
  63. +1 −0 tests/expected/parser/ms_show_sources_1.serialized
  64. +1 −0 tests/expected/parser/ms_show_sources_2.serialized
  65. +1 −0 tests/expected/parser/ms_show_sources_3.serialized
  66. +1 −0 tests/expected/parser/ms_show_tables_1.serialized
  67. +1 −0 tests/expected/parser/ms_show_tables_2.serialized
  68. +1 −0 tests/expected/parser/ms_show_tables_3.serialized
  69. +1 −0 tests/expected/parser/ms_show_views_1.serialized
  70. +1 −0 tests/expected/parser/ms_show_views_2.serialized
  71. +1 −0 tests/expected/parser/ms_show_views_3.serialized
  72. +1 −0 tests/expected/parser/ms_show_views_4.serialized
  73. +1 −0 tests/expected/parser/ms_show_views_5.serialized
  74. +1 −0 tests/expected/parser/ms_show_views_6.serialized
  75. +1 −0 tests/expected/parser/ms_show_views_7.serialized
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -19,23 +19,17 @@ jobs:
- nightly

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: php-actions/composer@v6

- name: PHPUnit Tests
uses: php-actions/phpunit@master
env:
XDEBUG_MODE: coverage
with:
php_extensions: "xdebug"
coverage_html: "coverage/html/"
version: 9.5
bootstrap: tests/bootstrap.php
configuration: phpunit.xml

- name: Archive code coverage results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: coverage/html
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name" : "greenlion/php-sql-parser",
"name" : "manticoresoftware/php-sql-parser",
"type" : "library",
"description" : "A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL",
"keywords" : [
136 changes: 70 additions & 66 deletions src/PHPSQLParser/PHPSQLCreator.php
Original file line number Diff line number Diff line change
@@ -31,15 +31,16 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*
*/

namespace PHPSQLParser;

use PHPSQLParser\exceptions\UnsupportedFeatureException;
use PHPSQLParser\builders\SelectStatementBuilder;
use PHPSQLParser\builders\DeleteStatementBuilder;
@@ -57,85 +58,88 @@
use PHPSQLParser\builders\AlterStatementBuilder;

/**
* This class generates SQL from the output of the PHPSQLParser.
* This class generates SQL from the output of the PHPSQLParser.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*
*/
class PHPSQLCreator {
class PHPSQLCreator
{

public $created;

public function __construct($parsed = false) {
public function __construct($parsed = false)
{
if ($parsed) {
$this->create($parsed);
}
}

public function create($parsed) {
public function create($parsed)
{
$k = key($parsed);
switch ($k) {

case 'UNION':
$builder = new UnionStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'UNION ALL':
$builder = new UnionAllStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'SELECT':
$builder = new SelectStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'INSERT':
$builder = new InsertStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'REPLACE':
$builder = new ReplaceStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'DELETE':
$builder = new DeleteStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'TRUNCATE':
$builder = new TruncateStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'UPDATE':
$builder = new UpdateStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'RENAME':
$builder = new RenameStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'SHOW':
$builder = new ShowStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'CREATE':
$builder = new CreateStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'BRACKET':
$builder = new BracketStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'DROP':
$builder = new DropStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'ALTER':
$builder = new AlterStatementBuilder();
$this->created = $builder->build($parsed);
break;
default:
throw new UnsupportedFeatureException($k);
break;
case 'UNION':
$builder = new UnionStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'UNION ALL':
$builder = new UnionAllStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'SELECT':
$builder = new SelectStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'INSERT':
$builder = new InsertStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'REPLACE':
$builder = new ReplaceStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'DELETE':
$builder = new DeleteStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'TRUNCATE':
$builder = new TruncateStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'UPDATE':
$builder = new UpdateStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'RENAME':
$builder = new RenameStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'SHOW':
$builder = new ShowStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'CREATE':
$builder = new CreateStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'BRACKET':
$builder = new BracketStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'DROP':
$builder = new DropStatementBuilder();
$this->created = $builder->build($parsed);
break;
case 'ALTER':
$builder = new AlterStatementBuilder();
$this->created = $builder->build($parsed);
break;
default:
throw new UnsupportedFeatureException($k);
break;
}
return $this->created;
}
61 changes: 61 additions & 0 deletions src/PHPSQLParser/builders/AddBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* AliasBuilder.php
*
* Builds aliases.
*
* PHP version 5
*
* LICENSE:
* Copyright (c) 2010-2014 Justin Swanhart and André Rothe
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author André Rothe <andre.rothe@phosco.info>
* @copyright 2010-2014 Justin Swanhart and André Rothe
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version SVN: $Id$
*
*/

namespace PHPSQLParser\builders;

/**
* This class implements the builder for aliases.
* You can overwrite all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*/
class AddBuilder implements Builder
{

public function build(array $parsed)
{
return "ADD " . $parsed['base_expr'] . " " . $parsed['sub_tree'][0]['base_expr'];
}
}

?>
24 changes: 5 additions & 19 deletions src/PHPSQLParser/builders/AlterBuilder.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
<?php

namespace PHPSQLParser\builders;

use PHPSQLParser\utils\ExpressionType;

/**
* This class implements the builder for the [DELETE] part. You can overwrite
* all functions to achieve another handling.
*
* @author André Rothe <andre.rothe@phosco.info>
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
*
*
*/
class AlterBuilder implements Builder
{
public function build(array $parsed)
{
$sql = '';

foreach ($parsed as $term) {
if ($term === ' ') {
continue;
}

if (substr($term, 0, 1) === '(' ||
strpos($term, "\n") !== false) {
$sql = rtrim($sql);
}

$sql .= $term . ' ';
}

$sql = rtrim($sql);

return $sql;
return "ALTER " . $parsed['base_expr'];
}
}
30 changes: 23 additions & 7 deletions src/PHPSQLParser/builders/AlterStatementBuilder.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
<?php

namespace PHPSQLParser\builders;

class AlterStatementBuilder implements Builder
{
protected function buildSubTree($parsed) {
$builder = new SubTreeBuilder();
return $builder->build($parsed);
}


private function buildAlter($parsed)
{
$builder = new AlterBuilder();
return $builder->build($parsed);
}

private function buildTable($parsed)
{
$builder = new CreateTableBuilder();
return $builder->build($parsed);
}

private function buildAdd($parsed)
{
return (new AddBuilder())->build($parsed);
}

public function build(array $parsed)
{
$alter = $parsed['ALTER'];
$sql = $this->buildAlter($alter);
$sql[] = $this->buildAlter($parsed['ALTER']);

if (isset($parsed['TABLE'])) {
$sql[] = $this->buildTable($parsed['TABLE']);
}

if (isset($parsed['ADD'])) {
$sql[] = $this->buildAdd($parsed['ADD']);
}

return $sql;
return implode(" ", $sql);
}
}
Loading