diff --git a/sql.pegjs b/sql.pegjs index 9058f09..02d1c15 100644 --- a/sql.pegjs +++ b/sql.pegjs @@ -268,7 +268,8 @@ select_core = } ) ) f: ( j: ( ( FROM join_source )? ) { return j ? j[1] : [] } ) - w: ( ( WHERE expr )? ) + w: ( e: ( ( WHERE expr )? ) + { return e ? e[1] : [] } ) g: ( GROUP BY ( ordering_term comma )+ ( HAVING expr )? )? ) { c[1].unshift(c[0]); var res = { results: c[1] }; diff --git a/views/index.erb b/views/index.erb index 01ead63..84cd4ab 100644 --- a/views/index.erb +++ b/views/index.erb @@ -58,7 +58,7 @@ test("smoke", 2, function() { }]); }); -test("from-clause", 2, function() { +test("smoke-from", 2, function() { var parser = PEG.buildParser(sql_pegjs); ok(parser); var s = parser.parse( @@ -84,6 +84,33 @@ test("from-clause", 2, function() { ] }]); }); + +test("smoke-where", 2, function() { + var parser = PEG.buildParser(sql_pegjs); + ok(parser); + var s = parser.parse( + "SELECT * FROM a WHERE a = a;"); + deepEqual(s, [ + { + "stmt": "select", + "select_cores": [ { + "results": [ { "column": "*" } ], + "from": [ + { "table": "a" }, + { "join_constraint": null, + "join_op": "JOIN", + "table": "b" + }, + { "join_constraint": null, + "join_op": "JOIN", + "table": "x", + "alias": "b1" + } + ] + } + ] + }]); +});