Skip to content
a mysql sql parser
Branch: master
Clone or download
hoterran Merge pull request #6 from yorickdewid/master
Exit when no arguments are given
Latest commit 780980f May 21, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test date_sub / date_add interval and ? character deal Jun 3, 2013
.gitignore add test Mar 3, 2013
Makefile clear some code Jun 6, 2013
README.md add all sql function May 27, 2013
adlist.c
adlist.h init Mar 3, 2013
format.c Exit when no arguments are given Apr 30, 2015
format_str.c add format_str Feb 17, 2014
func.h add func.h Feb 11, 2014
index.c Exit when no arguments are given Apr 30, 2015
index_json.c Exit when no arguments are given Apr 30, 2015
sql.h BEGIN COMMIT ROLLBACK SET OPTION Jun 4, 2013
sql.l BEGIN COMMIT ROLLBACK SET OPTION Jun 4, 2013
sql.y index show column Jun 4, 2013
test.sh having and cmp , add some case Mar 3, 2013

README.md

sqlparser

This is a toy and simple sql parser, LALR(1) code generated by lex and bison.

Currently, partially DML semtanics covered, remnant (mostly DDL and administrator command) would fulfill in future.

code

Core structure is Stmt and Item in sql.h

compile

make

use

format sql

./format your_sql_file

create index for this sql

./index your_sql_file

example

hoterran@hoterran-laptop:~/Projects/sqlparser$ cat test/test_groupby_orderby.sql 
select a.id, b.id, c.name from a, b where id = name group by xxx, zzz, ddd 
having count(*) > 1 order by a desc,b asc ,c desc limit 1;

hoterran@hoterran-laptop:~/Projects/sqlparser$ ./format test/test_groupby_orderby.sql 
SQL parse worked
================
SELECT
	a.id,
	b.id,
	c.name
FROM
	a,
	b
WHERE
	id = name    
GROUPBY
	xxx,
	zzz,
	ddd
HAVING 
	func(*) > 1
ORDER BY
	a DESC,
	b,
	c DESC
LIMIT
	1


hoterran@hoterran-laptop:~/Projects/sqlparser$ cat test/test_in_query.sql 
select a.z,c.d from t1 a, t2 b where 
a.id = 111 and (b.id = 222 or z.id = 333) and b.id = kkk
and b.id in (select c.id from c);

hoterran@hoterran-laptop:~/Projects/sqlparser$ ./format test/test_in_query.sql 
SQL parse worked
================
SELECT
	a.z,
	c.d
FROM
	t1 AS a,
	t2 AS b
WHERE
	(
		(
			(
				a.id = 111
			)
			AND
			(
				(
					b.id = 222
				)
				OR
				(
					z.id = 333
				)
			)
		)
		AND
		(
			b.id = kkk
		)
	)
	AND
	(
		b.id
		IN (
			 SELECT
				c.id
			FROM
				c
		)
	)

hoterran@hoterran-laptop:~/Projects/sqlparser$ cat test/test_index.sql 
select * from aaa a, bbb b where a.id = 1 and a.name = "aaaa" and a.kkk = "zzz" and b.id = a.id;
hoterran@hoterran-laptop:~/Projects/sqlparser$ ./index test/test_index.sql 
create index index_aaa_id_name_kkk on aaa(id, name, kkk);
create index index_bbb_id on bbb(id);

TODO

* out,left,right join
* union
* 
You can’t perform that action at this time.