Skip to content

RNaveen99/sql-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

sql parser

A simple parser for sql made using lex yacc / GNU's flex bison.

It currently supports only selected sql queries as stated below.

How to make

  • go to source folder cd src
  • make to build : this will generate the usual files and executes the executable file

Assumptions

  • queries are case-insensitive
  • each query ends with semicolon
  • keywords cant be identifiers

Syntax

UPDATE table_reference SET assignment_list [WHERE where_condition] [ORDER BY ...] [LIMIT row_count]

Cases Handled

  • update table_reference set assignment_list

    update customer set bonus = 1000;
    update customer set bonus = 1000, gst = 200;
    update customer set bonus = 1000, gst = 200, bonus_type = 'Diwali';
    update customer set bonus = 1000, gst = 200, bonus_type = 'Diwali', extra = bonus + 200;
    update customer set bonus = 1000, gst = 2 * 10 ;
    update customer set bonus = 1000, gst = 2 * 5 + 5 - 10 / 2;
    
  • update table_reference set assignment_list where condition_list

    update customer set bonus = 1000, gst = 20 where bonus_type = 'Diwali';
    update customer set bonus = 1000, gst = 20 where bonus_type = 'Diwali' and salary >= 40000;
    update customer set bonus = 1000, gst = 20 where bonus_type = 'Diwali' and salary >= 40000 or salary <= 20000;
    update customer set bonus = 1000, gst = 20 where bonus_type = 'Diwali' and salary between 40000 and 20000;
    
  • update table_reference set assignment_list order by column

    update customer set bonus = 1000, gst = 20 order by cid;
    update customer set bonus = 1000, gst = 20 order by cid asc, salary desc;
    
  • update table_reference set assignment_list Limit row_count

    update customer set bonus = 1000, gst = 20 limit 10;
    
  • update table_reference set assignment_list where condition_list order by column Limit row_count

    update customer set bonus = 1000, gst = 20 where bonus_type = 'Diwali' and salary >= 40000 or salary <= 20000 order by cid desc limit 5;
    

Cases Not Handled

  • multi-table updates

    update items,month set items.price=month.price where items.id = month.id;
    
  • Binary operator such as XOR, NOT, |(or), &(and)

Reference links

About

A simple parser for sql made using lex yacc

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published