From adfeac8d1691a82333964ef2143140f952c12f0c Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Tue, 17 Dec 2013 12:27:00 +0200 Subject: [PATCH] parse a join b without inner --- Language/SQL/SimpleSQL/Parser.lhs | 18 ++++++++++-------- tools/Language/SQL/SimpleSQL/Postgres.lhs | 5 ++--- tools/Language/SQL/SimpleSQL/TableRefs.lhs | 4 ++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs index 2a1d7ec..a14d29e 100644 --- a/Language/SQL/SimpleSQL/Parser.lhs +++ b/Language/SQL/SimpleSQL/Parser.lhs @@ -518,14 +518,16 @@ tref > <*> nonJoinTref > <*> optionMaybe (joinCondition nat)) > >>= optionSuffix joinTrefSuffix -> joinType = choice -> [JCross <$ try (keyword_ "cross") -> ,JInner <$ try (keyword_ "inner") -> ,choice [JLeft <$ try (keyword_ "left") -> ,JRight <$ try (keyword_ "right") -> ,JFull <$ try (keyword_ "full")] -> <* optional (try $ keyword_ "outer")] -> <* keyword "join" +> joinType = +> choice [choice +> [JCross <$ try (keyword_ "cross") +> ,JInner <$ try (keyword_ "inner") +> ,choice [JLeft <$ try (keyword_ "left") +> ,JRight <$ try (keyword_ "right") +> ,JFull <$ try (keyword_ "full")] +> <* optional (try $ keyword_ "outer")] +> <* keyword "join" +> ,JInner <$ keyword_ "join"] > joinCondition nat = > choice [guard nat >> return JoinNatural > ,try (keyword_ "on") >> diff --git a/tools/Language/SQL/SimpleSQL/Postgres.lhs b/tools/Language/SQL/SimpleSQL/Postgres.lhs index d380dc2..2f2f4b3 100644 --- a/tools/Language/SQL/SimpleSQL/Postgres.lhs +++ b/tools/Language/SQL/SimpleSQL/Postgres.lhs @@ -47,9 +47,8 @@ queries section > ,"SELECT * FROM t1 LEFT JOIN t2 ON t1.num = t2.num AND t2.value = 'xxx';" > ,"SELECT * FROM t1 LEFT JOIN t2 ON t1.num = t2.num WHERE t2.value = 'xxx';" -> --,"SELECT * FROM some_very_long_table_name s JOIN another_fairly_long_name a ON s.id = a.num;" -> -- issue with join keyword on its own? -> --,"SELECT * FROM people AS mother JOIN people AS child ON mother.id = child.mother_id;" +> ,"SELECT * FROM some_very_long_table_name s JOIN another_fairly_long_name a ON s.id = a.num;" +> ,"SELECT * FROM people AS mother JOIN people AS child ON mother.id = child.mother_id;" > ,"SELECT * FROM my_table AS a CROSS JOIN my_table AS b;" > ,"SELECT * FROM (my_table AS a CROSS JOIN my_table) AS b;" > --,"SELECT * FROM getfoo(1) AS t1;" -- function tableref diff --git a/tools/Language/SQL/SimpleSQL/TableRefs.lhs b/tools/Language/SQL/SimpleSQL/TableRefs.lhs index 5feaf3c..feeb67f 100644 --- a/tools/Language/SQL/SimpleSQL/TableRefs.lhs +++ b/tools/Language/SQL/SimpleSQL/TableRefs.lhs @@ -20,6 +20,10 @@ expression > ,ms [TRJoin (TRSimple "t") JInner (TRSimple "u") > (Just $ JoinOn $ Iden "expr")]) +> ,("select a from t join u on expr" +> ,ms [TRJoin (TRSimple "t") JInner (TRSimple "u") +> (Just $ JoinOn $ Iden "expr")]) + > ,("select a from t left join u on expr" > ,ms [TRJoin (TRSimple "t") JLeft (TRSimple "u") > (Just $ JoinOn $ Iden "expr")])