Giter VIP home page Giter VIP logo

sql-parser's Introduction

sql-parser

A simple version of SQL parser written in Python and C++, the results are saved in a tree. For now, only SELECT queries are implemented.

###Python Prerequisites:

  • PLY (Python Lex-Yacc) HELP

Usage

python yacc.py

-> SELECT a, b FROM c
 + QUERY
   + [SELECT]
   + [FIELDS]
     + [FIELD]
       + a
     + [FIELD]
       + b
   + [FROM]
   + [TABLE]
     + c

-> SELECT a . b , c . d FROM aaa AS a , ccc AS c               
 + QUERY
   + [SELECT]
   + [FIELDS]
     + [FIELD]
       + a.b
     + [FIELD]
       + c.d
   + [FROM]
   + [TABLES]
     + [TABLE]
       + aaa
       + AS
       + a
     + [TABLE]
       + ccc
       + AS
       + c

-> SELECT a FROM ( SELECT b FROM c WHERE d > 1 ) ORDER BY e
 + QUERY
   + [SELECT]
   + [FIELD]
     + a
   + [FROM]
   + [TABLE]
     + QUERY
       + [SELECT]
       + [FIELD]
         + b
       + [FROM]
       + [TABLE]
         + c
       + [WHERE]
       + [CONDITION]
         + [TERM]
           + d
           + >
           + 1
   + [ORDER BY]
   + [FIELD]
     + e

-> SELECT COUNT ( * ) FROM a WHERE b < 1 AND c > 2 ORDER BY d 
 + QUERY
   + [SELECT]
   + [FIELD]
     + COUNT(*)
   + [FROM]
   + [TABLE]
     + a
   + [WHERE]
   + [CONDITIONS]
     + [TERM]
       + b
       + <
       + 1
     + [AND]
     + [TERM]
       + c
       + >
       + 2
   + [ORDER BY]
   + [FIELD]
     + d

C++

Prerequisites:

  • Lex
  • Yacc

Usage

make
./sql_parser
//enter your select queries

sql-parser's People

Contributors

mastermay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sql-parser's Issues

could you help on the fail case

sql

SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName FROM ((Orders INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID) INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID)

yacc.parse(s) return None

could help on that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.