diff --git a/Language/SQL/SimpleSQL/Fixity.lhs b/Language/SQL/SimpleSQL/Fixity.lhs index 2b7a7c2..58a38d5 100644 --- a/Language/SQL/SimpleSQL/Fixity.lhs +++ b/Language/SQL/SimpleSQL/Fixity.lhs @@ -121,8 +121,8 @@ the fixity code. > name n = case n of > QName q -> '"' : q > Name m -> m -> orderExps = map (toHaskell . (\(OrderField a _ _) -> a)) -> orderInf = map (\(OrderField _ b c) -> (b,c)) +> orderExps = map (toHaskell . (\(SortSpec a _ _) -> a)) +> orderInf = map (\(SortSpec _ b c) -> (b,c)) @@ -171,7 +171,7 @@ the fixity code. > in In b (toSql e0) sq > _ -> err e > where -> sord = zipWith (\(i0,i1) ce -> OrderField (toSql ce) i0 i1) +> sord = zipWith (\(i0,i1) ce -> SortSpec (toSql ce) i0 i1) > ltom (HSE.List []) = Nothing > ltom (HSE.List [ex]) = Just $ toSql ex > ltom ex = err ex diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs index 769ad9f..c8b9088 100644 --- a/Language/SQL/SimpleSQL/Parser.lhs +++ b/Language/SQL/SimpleSQL/Parser.lhs @@ -712,10 +712,10 @@ where, having, limit, offset). > having :: P ScalarExpr > having = keywordScalarExpr "having" -> orderBy :: P [OrderField] +> orderBy :: P [SortSpec] > orderBy = try (keyword_ "order") *> keyword_ "by" *> commaSep1 ob > where -> ob = OrderField +> ob = SortSpec > <$> scalarExpr > <*> option Asc (choice [Asc <$ keyword_ "asc" > ,Desc <$ keyword_ "desc"]) diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index fb02a91..b48e0b5 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -266,12 +266,12 @@ > ge (Rollup es) = text "rollup" <> parens (commaSep $ map ge es) > ge (GroupingSets es) = text "grouping sets" <> parens (commaSep $ map ge es) -> orderBy :: [OrderField] -> Doc +> orderBy :: [SortSpec] -> Doc > orderBy [] = empty > orderBy os = sep [text "order by" > ,nest 9 $ commaSep $ map f os] > where -> f (OrderField e d n) = +> f (SortSpec e d n) = > scalarExpr e > <+> (if d == Asc then empty else text "desc") > <+> (case n of diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index dfd3b4c..8cfeef2 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -6,10 +6,10 @@ > ,Name(..) > ,TypeName(..) > ,Duplicates(..) -> ,OrderField(..) +> ,SortSpec(..) > ,Direction(..) > ,NullsOrder(..) -> ,InThing(..) +> ,InPredValue(..) > ,SubQueryExprType(..) > ,Frame(..) > ,FrameRows(..) @@ -67,7 +67,7 @@ > {aggName :: Name -- ^ aggregate function name > ,aggDistinct :: Maybe Duplicates -- ^ distinct > ,aggArgs :: [ScalarExpr]-- ^ args -> ,aggOrderBy :: [OrderField] -- ^ order by +> ,aggOrderBy :: [SortSpec] -- ^ order by > } > -- | window application, which adds over (partition by a order > -- by b) to regular function application. Explicit frames are @@ -76,7 +76,7 @@ > {wnName :: Name -- ^ window function name > ,wnArgs :: [ScalarExpr] -- ^ args > ,wnPartition :: [ScalarExpr] -- ^ partition by -> ,wnOrderBy :: [OrderField] -- ^ order by +> ,wnOrderBy :: [SortSpec] -- ^ order by > ,wnFrame :: Maybe Frame -- ^ frame clause > } > -- | Infix binary operators. This is used for symbol operators @@ -114,7 +114,7 @@ > | SubQueryExpr SubQueryExprType QueryExpr > -- | in list literal and in subquery, if the bool is false it > -- means not in was used ('a not in (1,2)') -> | In Bool ScalarExpr InThing +> | In Bool ScalarExpr InPredValue > deriving (Eq,Show,Read) > -- | Represents an identifier name, which can be quoted or unquoted. @@ -131,9 +131,9 @@ > -- | Used for 'expr in (scalar expression list)', and 'expr in > -- (subquery)' syntax. -> data InThing = InList [ScalarExpr] -> | InQueryExpr QueryExpr -> deriving (Eq,Show,Read) +> data InPredValue = InList [ScalarExpr] +> | InQueryExpr QueryExpr +> deriving (Eq,Show,Read) > -- | A subquery in a scalar expression. > data SubQueryExprType @@ -150,8 +150,8 @@ > deriving (Eq,Show,Read) > -- | Represents one field in an order by list. -> data OrderField = OrderField ScalarExpr Direction NullsOrder -> deriving (Eq,Show,Read) +> data SortSpec = SortSpec ScalarExpr Direction NullsOrder +> deriving (Eq,Show,Read) > -- | Represents 'nulls first' or 'nulls last' in an order by clause. > data NullsOrder = NullsOrderDefault @@ -199,7 +199,7 @@ > ,qeWhere :: Maybe ScalarExpr > ,qeGroupBy :: [GroupingExpr] > ,qeHaving :: Maybe ScalarExpr -> ,qeOrderBy :: [OrderField] +> ,qeOrderBy :: [SortSpec] > ,qeOffset :: Maybe ScalarExpr > ,qeFetch :: Maybe ScalarExpr > } diff --git a/TODO b/TODO index c9570b9..6182eb1 100644 --- a/TODO +++ b/TODO @@ -11,7 +11,7 @@ add to website: pretty printed tpch, maybe other queries as add preamble to the rendered test page add links from the supported sql page to the rendered test page for - each section + each section -> have to section up the tests some more == testing @@ -35,7 +35,7 @@ have to do fixity for this to work all ansi string literal syntax? -check ansi standard for operators +check ansi standard for operators (keywords and symbols) == other diff --git a/tools/Language/SQL/SimpleSQL/FullQueries.lhs b/tools/Language/SQL/SimpleSQL/FullQueries.lhs index 81c88ff..5da99db 100644 --- a/tools/Language/SQL/SimpleSQL/FullQueries.lhs +++ b/tools/Language/SQL/SimpleSQL/FullQueries.lhs @@ -33,7 +33,7 @@ Some tests for parsing full queries. > ,qeGroupBy = [SimpleGroup $ Iden "a"] > ,qeHaving = Just $ BinOp (App "count" [NumLit "1"]) > ">" (NumLit "5") -> ,qeOrderBy = [OrderField (Iden "s") Asc NullsOrderDefault] +> ,qeOrderBy = [SortSpec (Iden "s") Asc NullsOrderDefault] > } > ) > ] diff --git a/tools/Language/SQL/SimpleSQL/QueryExprComponents.lhs b/tools/Language/SQL/SimpleSQL/QueryExprComponents.lhs index 1384ccc..1d8f42b 100644 --- a/tools/Language/SQL/SimpleSQL/QueryExprComponents.lhs +++ b/tools/Language/SQL/SimpleSQL/QueryExprComponents.lhs @@ -89,22 +89,22 @@ These are a few misc tests which don't fit anywhere else. > orderBy :: TestItem > orderBy = Group "orderBy" $ map (uncurry TestQueryExpr) > [("select a from t order by a" -> ,ms [OrderField (Iden "a") Asc NullsOrderDefault]) +> ,ms [SortSpec (Iden "a") Asc NullsOrderDefault]) > ,("select a from t order by a, b" -> ,ms [OrderField (Iden "a") Asc NullsOrderDefault -> ,OrderField (Iden "b") Asc NullsOrderDefault]) +> ,ms [SortSpec (Iden "a") Asc NullsOrderDefault +> ,SortSpec (Iden "b") Asc NullsOrderDefault]) > ,("select a from t order by a asc" -> ,ms [OrderField (Iden "a") Asc NullsOrderDefault]) +> ,ms [SortSpec (Iden "a") Asc NullsOrderDefault]) > ,("select a from t order by a desc, b desc" -> ,ms [OrderField (Iden "a") Desc NullsOrderDefault -> ,OrderField (Iden "b") Desc NullsOrderDefault]) +> ,ms [SortSpec (Iden "a") Desc NullsOrderDefault +> ,SortSpec (Iden "b") Desc NullsOrderDefault]) > ,("select a from t order by a desc nulls first, b desc nulls last" -> ,ms [OrderField (Iden "a") Desc NullsFirst -> ,OrderField (Iden "b") Desc NullsLast]) +> ,ms [SortSpec (Iden "a") Desc NullsFirst +> ,SortSpec (Iden "b") Desc NullsLast]) > ] > where diff --git a/tools/Language/SQL/SimpleSQL/ScalarExprs.lhs b/tools/Language/SQL/SimpleSQL/ScalarExprs.lhs index 3f6f7aa..0e13325 100644 --- a/tools/Language/SQL/SimpleSQL/ScalarExprs.lhs +++ b/tools/Language/SQL/SimpleSQL/ScalarExprs.lhs @@ -322,7 +322,7 @@ target_string > ,("sum(a order by a)" > ,AggregateApp "sum" Nothing [Iden "a"] -> [OrderField (Iden "a") Asc NullsOrderDefault]) +> [SortSpec (Iden "a") Asc NullsOrderDefault]) > ,("sum(all a)" > ,AggregateApp "sum" (Just All) [Iden "a"] []) @@ -344,46 +344,46 @@ target_string > ,("sum(a) over (order by b)" > ,WindowApp "sum" [Iden "a"] [] -> [OrderField (Iden "b") Asc NullsOrderDefault] Nothing) +> [SortSpec (Iden "b") Asc NullsOrderDefault] Nothing) > ,("sum(a) over (order by b desc,c)" > ,WindowApp "sum" [Iden "a"] [] -> [OrderField (Iden "b") Desc NullsOrderDefault -> ,OrderField (Iden "c") Asc NullsOrderDefault] Nothing) +> [SortSpec (Iden "b") Desc NullsOrderDefault +> ,SortSpec (Iden "c") Asc NullsOrderDefault] Nothing) > ,("sum(a) over (partition by b order by c)" > ,WindowApp "sum" [Iden "a"] [Iden "b"] -> [OrderField (Iden "c") Asc NullsOrderDefault] Nothing) +> [SortSpec (Iden "c") Asc NullsOrderDefault] Nothing) > ,("sum(a) over (partition by b order by c range unbounded preceding)" > ,WindowApp "sum" [Iden "a"] [Iden "b"] -> [OrderField (Iden "c") Asc NullsOrderDefault] +> [SortSpec (Iden "c") Asc NullsOrderDefault] > $ Just $ FrameFrom FrameRange UnboundedPreceding) > ,("sum(a) over (partition by b order by c range 5 preceding)" > ,WindowApp "sum" [Iden "a"] [Iden "b"] -> [OrderField (Iden "c") Asc NullsOrderDefault] +> [SortSpec (Iden "c") Asc NullsOrderDefault] > $ Just $ FrameFrom FrameRange $ Preceding (NumLit "5")) > ,("sum(a) over (partition by b order by c range current row)" > ,WindowApp "sum" [Iden "a"] [Iden "b"] -> [OrderField (Iden "c") Asc NullsOrderDefault] +> [SortSpec (Iden "c") Asc NullsOrderDefault] > $ Just $ FrameFrom FrameRange Current) > ,("sum(a) over (partition by b order by c rows 5 following)" > ,WindowApp "sum" [Iden "a"] [Iden "b"] -> [OrderField (Iden "c") Asc NullsOrderDefault] +> [SortSpec (Iden "c") Asc NullsOrderDefault] > $ Just $ FrameFrom FrameRows $ Following (NumLit "5")) > ,("sum(a) over (partition by b order by c range unbounded following)" > ,WindowApp "sum" [Iden "a"] [Iden "b"] -> [OrderField (Iden "c") Asc NullsOrderDefault] +> [SortSpec (Iden "c") Asc NullsOrderDefault] > $ Just $ FrameFrom FrameRange UnboundedFollowing) > ,("sum(a) over (partition by b order by c \n\ > \range between 5 preceding and 5 following)" > ,WindowApp "sum" [Iden "a"] [Iden "b"] -> [OrderField (Iden "c") Asc NullsOrderDefault] +> [SortSpec (Iden "c") Asc NullsOrderDefault] > $ Just $ FrameBetween FrameRange > (Preceding (NumLit "5")) > (Following (NumLit "5")))