diff --git a/Language/SQL/SimpleSQL/Parse.lhs b/Language/SQL/SimpleSQL/Parse.lhs index 13e0a0b..482afa0 100644 --- a/Language/SQL/SimpleSQL/Parse.lhs +++ b/Language/SQL/SimpleSQL/Parse.lhs @@ -1356,7 +1356,11 @@ aliases. > n <- names > choice [TRFunction n > <$> parens (commaSep valueExpr) -> ,pure $ TRSimple n]] aliasSuffix +> ,pure $ TRSimple n] +> -- todo: I think you can only have outer joins inside the oj, +> -- not sure. +> ,TROdbc <$> (symbol "{" *> keyword_ "oj" *> tref <* symbol "}") +> ] aliasSuffix > aliasSuffix = fromAlias <$$> TRAlias > joinTrefSuffix t = > (TRJoin t <$> option False (True <$ keyword_ "natural") diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index f82e1eb..e7270c3 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -390,6 +390,7 @@ which have been changed to try to improve the layout of the output. > ,if b then text "natural" else empty > ,joinText jt <+> tr t1 > ,joinCond jc] +> tr (TROdbc t) = text "{oj" <+> tr t <+> text "}" > joinText jt = > sep [case jt of > JInner -> text "inner" diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index 98dedf9..c6daae4 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -430,6 +430,8 @@ I'm not sure if this is valid syntax or not. > | TRFunction [Name] [ValueExpr] > -- | from lateral t > | TRLateral TableRef +> -- | ODBC {oj t1 left outer join t2 on expr} syntax +> | TROdbc TableRef > deriving (Eq,Show,Read,Data,Typeable) > -- | Represents an alias for a table valued expression, used in with diff --git a/tools/Language/SQL/SimpleSQL/Odbc.lhs b/tools/Language/SQL/SimpleSQL/Odbc.lhs index 187b8f3..f5d180d 100644 --- a/tools/Language/SQL/SimpleSQL/Odbc.lhs +++ b/tools/Language/SQL/SimpleSQL/Odbc.lhs @@ -28,21 +28,21 @@ > [OdbcFunc (ap "CURDATE" []) > ,iden "SQL_DATE"]) > ] -> {-,Group "outer join" [ -> ParseQueryExpr defaultParseFlags -> "select * from {oj t1 left outer join t2 on true}" +> ,Group "outer join" [ +> TestQueryExpr ansi2011 {allowOdbc=True} +> "select * from {oj t1 left outer join t2 on expr}" > $ makeSelect -> {selSelectList = sl [si $ Star ea] -> ,selTref = [OdbcTableRef ea (JoinTref ea (tref "t1") Unnatural LeftOuter Nothing -> (tref "t2") (Just $ JoinOn ea (BooleanLit ea True)))]}] +> {qeSelectList = [(Star,Nothing)] +> ,qeFrom = [TROdbc $ TRJoin (TRSimple [Name Nothing "t1"]) False JLeft (TRSimple [Name Nothing "t2"]) +> (Just $ JoinOn $ Iden [Name Nothing "expr"])]}] > ,Group "check parsing bugs" [ -> ParseQueryExpr defaultParseFlags +> TestQueryExpr ansi2011 {allowOdbc=True} > "select {fn CONVERT(cint,SQL_BIGINT)} from t;" > $ makeSelect -> {selSelectList = sl [si $ OdbcFunc ea (App ea (name "CONVERT") -> [ei "cint" -> ,ei "SQL_BIGINT"])] -> ,selTref = [tref "t"]}]-} +> {qeSelectList = [(OdbcFunc (ap "CONVERT" +> [iden "cint" +> ,iden "SQL_BIGINT"]), Nothing)] +> ,qeFrom = [TRSimple [Name Nothing "t"]]}] > ] > where > e = TestValueExpr ansi2011 {allowOdbc = True}