GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - devenbansod/sql-parser: A validating SQL lexer and parser with a focus on MySQL dialect.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

271 Commits
271 Commits

Folders and files

NameName
Last commit message
Last commit date
bin
bin
 
 
src
src
 
 
tests
tests
 
 
tools
tools
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
codecov.yml
codecov.yml
 
 
composer.json
composer.json
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

SQL Parser

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

Code status

Build Status Code Coverage codecov.io Scrutinizer Code Quality

Installation

Please use Composer to install:

composer require phpmyadmin/sql-parser

Usage

Command line utility

Command line utility to syntax highlight SQL query:

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

Command line utility to lint SQL query:

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

Formatting SQL query

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

Parsing and building SQL query

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

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

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

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

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

More information

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

About

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

Resources

Readme
GPL-2.0 license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.