2017 © Pedro Peláez
 

library sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

image

phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  • Tuesday, July 24, 2018
  • by phpmyadmin
  • Repository
  • 19 Watchers
  • 140 Stars
  • 202,761 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 47 Forks
  • 25 Open issues
  • 60 Versions
  • 19 % Grown

The README.md

SQL Parser

A validating SQL lexer and parser with a focus on MySQL dialect., (*1)

Code status

Tests Code Coverage codecov.io Scrutinizer Code Quality Translation status Packagist Open Source Helpers Type coverage Infection MSI, (*2)

Installation

Please use [Composer][1] to install:, (*3)

composer require phpmyadmin/sql-parser

Documentation

The API documentation is available at https://develdocs.phpmyadmin.net/sql-parser/., (*4)

Usage

Command line utilities

Command line utility to syntax highlight SQL query:, (*5)

./vendor/bin/sql-parser --highlight --query "SELECT 1"

Command line utility to lint SQL query:, (*6)

./vendor/bin/sql-parser --lint --query "SELECT 1"

Command line utility to tokenize SQL query:, (*7)

./vendor/bin/sql-parser --tokenize --query "SELECT 1"

All commands are able to parse input from stdin (standard in), such as:, (*8)

echo "SELECT 1" | ./vendor/bin/sql-parser --highlight
cat example.sql | ./vendor/bin/sql-parser --lint

Formatting SQL query

echo PhpMyAdmin\SqlParser\Utils\Formatter::format($query, ['type' => 'html']);

Discoverying query type

use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Utils\Query;

$query = 'OPTIMIZE TABLE tbl';
$parser = new Parser($query);
$flags = Query::getFlags($parser->statements[0]);

echo $flags->queryType?->value;

Parsing and building SQL query

require __DIR__ . '/vendor/autoload.php';

$query1 = 'select * from a';
$parser = new PhpMyAdmin\SqlParser\Parser($query1);

// inspect query
var_dump($parser->statements[0]); // outputs object(PhpMyAdmin\SqlParser\Statements\SelectStatement)

// modify query by replacing table a with table b
$table2 = new \PhpMyAdmin\SqlParser\Components\Expression('', 'b', '', '');
$parser->statements[0]->from[0] = $table2;

// build query again from an array of object(PhpMyAdmin\SqlParser\Statements\SelectStatement) to a string
$statement = $parser->statements[0];
$query2 = $statement->build();
var_dump($query2); // outputs string(19) 'SELECT  * FROM `b` '

// Change SQL mode
PhpMyAdmin\SqlParser\Context::setMode(PhpMyAdmin\SqlParser\Context::SQL_MODE_ANSI_QUOTES);

// build the query again using different quotes
$query2 = $statement->build();
var_dump($query2); // outputs string(19) 'SELECT  * FROM "b" '

Localization

You can localize error messages installing phpmyadmin/motranslator version 5.0 or newer:, (*9)

composer require phpmyadmin/motranslator:^5.0

The locale is automatically detected from your environment, you can also set a different locale, (*10)

From cli:, (*11)

LC_ALL=pl ./vendor/bin/sql-parser --lint --query "SELECT 1"

From php:, (*12)

require __DIR__ . '/vendor/autoload.php';

$GLOBALS['lang'] = 'pl';

$query1 = 'select * from a';
$parser = new PhpMyAdmin\SqlParser\Parser($query1);

More information

This library was originally created during the Google Summer of Code 2015 and has been used by phpMyAdmin since version 4.5., (*13)

The Versions

24/07 2018

dev-master

9999999-dev https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

 

The Development Requires

sql parser lexer analysis

06/12 2017

v4.2.4

4.2.4.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

sql parser lexer analysis

10/10 2017

v4.2.3

4.2.3.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

sql parser lexer analysis

28/09 2017

v4.2.2

4.2.2.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

08/09 2017

v4.2.1

4.2.1.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

30/08 2017

v4.2.0

4.2.0.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

21/08 2017

v4.1.10

4.1.10.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

12/07 2017

v4.1.9

4.1.9.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

09/07 2017

v4.1.8

4.1.8.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

06/06 2017

v4.1.7

4.1.7.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

01/06 2017

v4.1.6

4.1.6.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

15/05 2017

v4.1.5

4.1.5.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

05/05 2017

v4.1.4

4.1.4.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

06/04 2017

v4.1.3

4.1.3.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

20/02 2017

v4.1.2

4.1.2.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

07/02 2017

v4.1.1

4.1.1.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

23/01 2017

v4.1.0

4.1.0.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

sql parser lexer analysis

23/01 2017

dev-motranslator

dev-motranslator https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

sql parser lexer analysis

23/01 2017

v4.0.1

4.0.1.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

23/01 2017

v4.0.0

4.0.0.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

20/01 2017

v3.4.17

3.4.17.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

06/01 2017

v3.4.16

3.4.16.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

02/01 2017

v3.4.15

3.4.15.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

30/11 2016

v3.4.14

3.4.14.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

15/11 2016

v3.4.13

3.4.13.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

09/11 2016

v3.4.12

3.4.12.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

25/10 2016

v3.4.11

3.4.11.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

03/10 2016

v3.4.10

3.4.10.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

03/10 2016

v3.4.9

3.4.9.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

22/09 2016

v3.4.8

3.4.8.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

20/09 2016

v3.4.7

3.4.7.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

13/09 2016

v3.4.6

3.4.6.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

13/09 2016

v3.4.5

3.4.5.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0
  • ext-mbstring *

 

The Development Requires

sql parser lexer analysis

26/04 2016

v3.4.4

3.4.4.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

sql parser lexer analysis

19/04 2016

v3.4.3

3.4.3.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

sql parser lexer analysis

07/04 2016

v3.4.2

3.4.2.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

sql parser lexer analysis

06/04 2016

v3.4.1

3.4.1.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

sql parser lexer analysis

23/02 2016

v3.4.0

3.4.0.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

sql parser lexer analysis

12/02 2016

v3.3.1

3.3.1.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

sql parser lexer analysis

12/02 2016

v3.3.0

3.3.0.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

sql parser lexer analysis

11/02 2016

v3.2.0

3.2.0.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

sql parser lexer analysis

10/02 2016

v3.1.0

3.1.0.0 https://github.com/phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.4.0

 

The Development Requires

sql parser lexer analysis

18/12 2015

v3.0.8

3.0.8.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.5.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

17/11 2015

v3.0.7

3.0.7.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

12/11 2015

v3.0.6

3.0.6.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

08/11 2015

v3.0.5

3.0.5.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

21/10 2015

v3.0.4

3.0.4.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

10/10 2015

v3.0.3

3.0.3.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

10/10 2015

v3.0.2

3.0.2.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

06/10 2015

v3.0.1

3.0.1.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

03/10 2015

v3.0.0

3.0.0.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

02/10 2015

v2.1.3

2.1.3.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

02/10 2015

v2.1.2

2.1.2.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

01/10 2015

v2.1.1

2.1.1.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

30/09 2015

v2.1.0

2.1.0.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

30/09 2015

v2.0.3

2.0.3.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

30/09 2015

v2.0.2

2.0.2.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

30/09 2015

v2.0.1

2.0.1.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

25/09 2015

v2.0.0

2.0.0.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis

20/08 2015

v1.0.0

1.0.0.0 https://github.com/udan11/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

The Development Requires

by Dan Ungureanu

sql parser lexer analysis