diff --git a/Language/SQL/SimpleSQL/Parse.hs b/Language/SQL/SimpleSQL/Parse.hs index 73500c5..ed19dc6 100644 --- a/Language/SQL/SimpleSQL/Parse.hs +++ b/Language/SQL/SimpleSQL/Parse.hs @@ -231,11 +231,10 @@ import Data.Maybe (catMaybes, isJust) import Data.Text (Text) import qualified Data.Text as T -import Language.SQL.SimpleSQL.Syntax +import Language.SQL.SimpleSQL.Syntax import Language.SQL.SimpleSQL.Dialect import qualified Language.SQL.SimpleSQL.Lex as L - ------------------------------------------------------------------------------ -- = Public API @@ -1522,7 +1521,7 @@ queryExpr = E.makeExprParser qeterm qeOpTable <*> selectList <*> (optional tableExpression) > "table expression" mkSelect d sl Nothing = - makeSelect{qeSetQuantifier = d, qeSelectList = sl} + toQueryExpr $ makeSelect {msSetQuantifier = d, msSelectList = sl} mkSelect d sl (Just (TableExpression f w g h od ofs fe)) = Select d sl f w g h od ofs fe values = keyword_ "values" diff --git a/Language/SQL/SimpleSQL/Syntax.hs b/Language/SQL/SimpleSQL/Syntax.hs index da624ad..e8f8cec 100644 --- a/Language/SQL/SimpleSQL/Syntax.hs +++ b/Language/SQL/SimpleSQL/Syntax.hs @@ -23,7 +23,6 @@ module Language.SQL.SimpleSQL.Syntax ,OdbcLiteralType(..) -- * Query expressions ,QueryExpr(..) - ,makeSelect ,SetOperatorName(..) ,Corresponding(..) ,Alias(..) @@ -60,6 +59,10 @@ module Language.SQL.SimpleSQL.Syntax ,GrantOptionFor(..) -- * Comment ,Comment(..) + + ,makeSelect + ,toQueryExpr + ,MakeSelect(..) ) where import Data.Text (Text) @@ -377,31 +380,6 @@ TODO: add queryexpr parens to deal with e.g. I'm not sure if this is valid syntax or not. -} --- | Helper/'default' value for query exprs to make creating query --- expr values a little easier. It is defined like this: --- --- > makeSelect :: QueryExpr --- > makeSelect = Select {qeSetQuantifier = SQDefault --- > ,qeSelectList = [] --- > ,qeFrom = [] --- > ,qeWhere = Nothing --- > ,qeGroupBy = [] --- > ,qeHaving = Nothing --- > ,qeOrderBy = [] --- > ,qeOffset = Nothing --- > ,qeFetchFirst = Nothing} - -makeSelect :: QueryExpr -makeSelect = Select {qeSetQuantifier = SQDefault - ,qeSelectList = [] - ,qeFrom = [] - ,qeWhere = Nothing - ,qeGroupBy = [] - ,qeHaving = Nothing - ,qeOrderBy = [] - ,qeOffset = Nothing - ,qeFetchFirst = Nothing} - -- | Represents the Distinct or All keywords, which can be used -- before a select list, in an aggregate/window function -- application, or in a query expression set operator. @@ -744,3 +722,50 @@ data PrivilegeAction = newtype Comment = BlockComment Text deriving (Eq,Show,Read,Data,Typeable) +data MakeSelect + = MakeSelect + {msSetQuantifier :: SetQuantifier + ,msSelectList :: [(ScalarExpr,Maybe Name)] + ,msFrom :: [TableRef] + ,msWhere :: Maybe ScalarExpr + ,msGroupBy :: [GroupingExpr] + ,msHaving :: Maybe ScalarExpr + ,msOrderBy :: [SortSpec] + ,msOffset :: Maybe ScalarExpr + ,msFetchFirst :: Maybe ScalarExpr + } + +-- | Helper/'default' value for query exprs to make creating query +-- expr values a little easier. It is defined like this: +-- +-- > makeSelect :: MakeSelect +-- > makeSelect +-- > = MakeSelect +-- > {msSetQuantifier = SQDefault +-- > ,msSelectList = [] +-- > ,msFrom = [] +-- > ,msWhere = Nothing +-- > ,msGroupBy = [] +-- > ,msHaving = Nothing +-- > ,msOrderBy = [] +-- > ,msOffset = Nothing +-- > ,msFetchFirst = Nothing} +-- > +-- > Example, to create a select query expression with a select list 'sl': +-- > toQueryExpr $ makeSelect {msSelectList = sl} + +makeSelect :: MakeSelect +makeSelect + = MakeSelect + {msSetQuantifier = SQDefault + ,msSelectList = [] + ,msFrom = [] + ,msWhere = Nothing + ,msGroupBy = [] + ,msHaving = Nothing + ,msOrderBy = [] + ,msOffset = Nothing + ,msFetchFirst = Nothing} + +toQueryExpr :: MakeSelect -> QueryExpr +toQueryExpr (MakeSelect q sl f w g h o ff fetch) = Select q sl f w g h o ff fetch diff --git a/changelog b/changelog index 0cd1314..21e9973 100644 --- a/changelog +++ b/changelog @@ -9,6 +9,8 @@ parses from and pretty prints to strict Text use strict Text instead of String everywhere tested with latest three main ghc releases (9.8.1, 9.6.4, and 9.4.8) and stack lts 22.5 + the makeSelect helper is now a distinct type, code using it will need some trivial + tweaks, this is change so that code using makeSelect doesn't emit warnings 0.6.1 added odbc handling to sqlsqerver dialect added sqlserver dialect case for convert function 0.6.0 diff --git a/tools/Language/SQL/SimpleSQL/FullQueries.hs b/tools/Language/SQL/SimpleSQL/FullQueries.hs index 1950ee4..19b9bf2 100644 --- a/tools/Language/SQL/SimpleSQL/FullQueries.hs +++ b/tools/Language/SQL/SimpleSQL/FullQueries.hs @@ -11,9 +11,9 @@ import Language.SQL.SimpleSQL.Syntax fullQueriesTests :: TestItem fullQueriesTests = Group "queries" $ map (uncurry (TestQueryExpr ansi2011)) [("select count(*) from t" - ,makeSelect - {qeSelectList = [(App [Name Nothing "count"] [Star], Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] + ,toQueryExpr $ makeSelect + {msSelectList = [(App [Name Nothing "count"] [Star], Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]] } ) @@ -23,18 +23,18 @@ fullQueriesTests = Group "queries" $ map (uncurry (TestQueryExpr ansi2011)) \ group by a\n\ \ having count(1) > 5\n\ \ order by s" - ,makeSelect - {qeSelectList = [(Iden [Name Nothing "a"], Nothing) + ,toQueryExpr $ makeSelect + {msSelectList = [(Iden [Name Nothing "a"], Nothing) ,(App [Name Nothing "sum"] [BinOp (Iden [Name Nothing "c"]) [Name Nothing "+"] (Iden [Name Nothing "d"])] ,Just $ Name Nothing "s")] - ,qeFrom = [TRSimple [Name Nothing "t"], TRSimple [Name Nothing "u"]] - ,qeWhere = Just $ BinOp (Iden [Name Nothing "a"]) [Name Nothing ">"] (NumLit "5") - ,qeGroupBy = [SimpleGroup $ Iden [Name Nothing "a"]] - ,qeHaving = Just $ BinOp (App [Name Nothing "count"] [NumLit "1"]) + ,msFrom = [TRSimple [Name Nothing "t"], TRSimple [Name Nothing "u"]] + ,msWhere = Just $ BinOp (Iden [Name Nothing "a"]) [Name Nothing ">"] (NumLit "5") + ,msGroupBy = [SimpleGroup $ Iden [Name Nothing "a"]] + ,msHaving = Just $ BinOp (App [Name Nothing "count"] [NumLit "1"]) [Name Nothing ">"] (NumLit "5") - ,qeOrderBy = [SortSpec (Iden [Name Nothing "s"]) DirDefault NullsOrderDefault] + ,msOrderBy = [SortSpec (Iden [Name Nothing "s"]) DirDefault NullsOrderDefault] } ) ] diff --git a/tools/Language/SQL/SimpleSQL/GroupBy.hs b/tools/Language/SQL/SimpleSQL/GroupBy.hs index e91ad43..e77c91a 100644 --- a/tools/Language/SQL/SimpleSQL/GroupBy.hs +++ b/tools/Language/SQL/SimpleSQL/GroupBy.hs @@ -18,18 +18,18 @@ groupByTests = Group "groupByTests" simpleGroupBy :: TestItem simpleGroupBy = Group "simpleGroupBy" $ map (uncurry (TestQueryExpr ansi2011)) [("select a,sum(b) from t group by a" - ,makeSelect {qeSelectList = [(Iden [Name Nothing "a"],Nothing) + ,toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"],Nothing) ,(App [Name Nothing "sum"] [Iden [Name Nothing "b"]],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] - ,qeGroupBy = [SimpleGroup $ Iden [Name Nothing "a"]] + ,msFrom = [TRSimple [Name Nothing "t"]] + ,msGroupBy = [SimpleGroup $ Iden [Name Nothing "a"]] }) ,("select a,b,sum(c) from t group by a,b" - ,makeSelect {qeSelectList = [(Iden [Name Nothing "a"],Nothing) + ,toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"],Nothing) ,(Iden [Name Nothing "b"],Nothing) ,(App [Name Nothing "sum"] [Iden [Name Nothing "c"]],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] - ,qeGroupBy = [SimpleGroup $ Iden [Name Nothing "a"] + ,msFrom = [TRSimple [Name Nothing "t"]] + ,msGroupBy = [SimpleGroup $ Iden [Name Nothing "a"] ,SimpleGroup $ Iden [Name Nothing "b"]] }) ] @@ -51,9 +51,9 @@ newGroupBy = Group "newGroupBy" $ map (uncurry (TestQueryExpr ansi2011)) ,ms [Rollup [SimpleGroup $ Iden [Name Nothing "a"], SimpleGroup $ Iden [Name Nothing "b"]]]) ] where - ms g = makeSelect {qeSelectList = [(Star,Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] - ,qeGroupBy = g} + ms g = toQueryExpr $ makeSelect {msSelectList = [(Star,Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]] + ,msGroupBy = g} randomGroupBy :: TestItem randomGroupBy = Group "randomGroupBy" $ map (ParseQueryExpr ansi2011) diff --git a/tools/Language/SQL/SimpleSQL/MySQL.hs b/tools/Language/SQL/SimpleSQL/MySQL.hs index 5777092..28581c9 100644 --- a/tools/Language/SQL/SimpleSQL/MySQL.hs +++ b/tools/Language/SQL/SimpleSQL/MySQL.hs @@ -30,7 +30,7 @@ backtickQuotes = Group "backtickQuotes" (map (uncurry (TestScalarExpr mysql)) limit :: TestItem limit = Group "queries" ( map (uncurry (TestQueryExpr mysql)) [("select * from t limit 5" - ,sel {qeFetchFirst = Just (NumLit "5")} + ,toQueryExpr $ sel {msFetchFirst = Just (NumLit "5")} ) ] ++ [ParseQueryExprFails mysql "select a from t fetch next 10 rows only;" @@ -38,6 +38,6 @@ limit = Group "queries" ( map (uncurry (TestQueryExpr mysql)) ) where sel = makeSelect - {qeSelectList = [(Star, Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] + {msSelectList = [(Star, Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]] } diff --git a/tools/Language/SQL/SimpleSQL/Odbc.hs b/tools/Language/SQL/SimpleSQL/Odbc.hs index 3d26eab..3d3f4b5 100644 --- a/tools/Language/SQL/SimpleSQL/Odbc.hs +++ b/tools/Language/SQL/SimpleSQL/Odbc.hs @@ -32,18 +32,18 @@ odbcTests = Group "odbc" [ ,Group "outer join" [ TestQueryExpr ansi2011 {diOdbc=True} "select * from {oj t1 left outer join t2 on expr}" - $ makeSelect - {qeSelectList = [(Star,Nothing)] - ,qeFrom = [TROdbc $ TRJoin (TRSimple [Name Nothing "t1"]) False JLeft (TRSimple [Name Nothing "t2"]) + $ toQueryExpr $ makeSelect + {msSelectList = [(Star,Nothing)] + ,msFrom = [TROdbc $ TRJoin (TRSimple [Name Nothing "t1"]) False JLeft (TRSimple [Name Nothing "t2"]) (Just $ JoinOn $ Iden [Name Nothing "expr"])]}] ,Group "check parsing bugs" [ TestQueryExpr ansi2011 {diOdbc=True} "select {fn CONVERT(cint,SQL_BIGINT)} from t;" - $ makeSelect - {qeSelectList = [(OdbcFunc (ap "CONVERT" + $ toQueryExpr $ makeSelect + {msSelectList = [(OdbcFunc (ap "CONVERT" [iden "cint" ,iden "SQL_BIGINT"]), Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]]}] + ,msFrom = [TRSimple [Name Nothing "t"]]}] ] where e = TestScalarExpr ansi2011 {diOdbc = True} diff --git a/tools/Language/SQL/SimpleSQL/QueryExprComponents.hs b/tools/Language/SQL/SimpleSQL/QueryExprComponents.hs index 7930fc7..31e1648 100644 --- a/tools/Language/SQL/SimpleSQL/QueryExprComponents.hs +++ b/tools/Language/SQL/SimpleSQL/QueryExprComponents.hs @@ -37,38 +37,38 @@ duplicates = Group "duplicates" $ map (uncurry (TestQueryExpr ansi2011)) ,("select distinct a from t", ms Distinct) ] where - ms d = makeSelect - {qeSetQuantifier = d - ,qeSelectList = [(Iden [Name Nothing "a"],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]]} + ms d = toQueryExpr $ makeSelect + {msSetQuantifier = d + ,msSelectList = [(Iden [Name Nothing "a"],Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]]} selectLists :: TestItem selectLists = Group "selectLists" $ map (uncurry (TestQueryExpr ansi2011)) [("select 1", - makeSelect {qeSelectList = [(NumLit "1",Nothing)]}) + toQueryExpr $ makeSelect {msSelectList = [(NumLit "1",Nothing)]}) ,("select a" - ,makeSelect {qeSelectList = [(Iden [Name Nothing "a"],Nothing)]}) + ,toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"],Nothing)]}) ,("select a,b" - ,makeSelect {qeSelectList = [(Iden [Name Nothing "a"],Nothing) + ,toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"],Nothing) ,(Iden [Name Nothing "b"],Nothing)]}) ,("select 1+2,3+4" - ,makeSelect {qeSelectList = + ,toQueryExpr $ makeSelect {msSelectList = [(BinOp (NumLit "1") [Name Nothing "+"] (NumLit "2"),Nothing) ,(BinOp (NumLit "3") [Name Nothing "+"] (NumLit "4"),Nothing)]}) ,("select a as a, /*comment*/ b as b" - ,makeSelect {qeSelectList = [(Iden [Name Nothing "a"], Just $ Name Nothing "a") + ,toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"], Just $ Name Nothing "a") ,(Iden [Name Nothing "b"], Just $ Name Nothing "b")]}) ,("select a a, b b" - ,makeSelect {qeSelectList = [(Iden [Name Nothing "a"], Just $ Name Nothing "a") + ,toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"], Just $ Name Nothing "a") ,(Iden [Name Nothing "b"], Just $ Name Nothing "b")]}) ,("select a + b * c" - ,makeSelect {qeSelectList = + ,toQueryExpr $ makeSelect {msSelectList = [(BinOp (Iden [Name Nothing "a"]) [Name Nothing "+"] (BinOp (Iden [Name Nothing "b"]) [Name Nothing "*"] (Iden [Name Nothing "c"])) ,Nothing)]}) @@ -78,19 +78,19 @@ selectLists = Group "selectLists" $ map (uncurry (TestQueryExpr ansi2011)) whereClause :: TestItem whereClause = Group "whereClause" $ map (uncurry (TestQueryExpr ansi2011)) [("select a from t where a = 5" - ,makeSelect {qeSelectList = [(Iden [Name Nothing "a"],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] - ,qeWhere = Just $ BinOp (Iden [Name Nothing "a"]) [Name Nothing "="] (NumLit "5")}) + ,toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"],Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]] + ,msWhere = Just $ BinOp (Iden [Name Nothing "a"]) [Name Nothing "="] (NumLit "5")}) ] having :: TestItem having = Group "having" $ map (uncurry (TestQueryExpr ansi2011)) [("select a,sum(b) from t group by a having sum(b) > 5" - ,makeSelect {qeSelectList = [(Iden [Name Nothing "a"],Nothing) + ,toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"],Nothing) ,(App [Name Nothing "sum"] [Iden [Name Nothing "b"]],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] - ,qeGroupBy = [SimpleGroup $ Iden [Name Nothing "a"]] - ,qeHaving = Just $ BinOp (App [Name Nothing "sum"] [Iden [Name Nothing "b"]]) + ,msFrom = [TRSimple [Name Nothing "t"]] + ,msGroupBy = [SimpleGroup $ Iden [Name Nothing "a"]] + ,msHaving = Just $ BinOp (App [Name Nothing "sum"] [Iden [Name Nothing "b"]]) [Name Nothing ">"] (NumLit "5") }) ] @@ -117,9 +117,9 @@ orderBy = Group "orderBy" $ map (uncurry (TestQueryExpr ansi2011)) ] where - ms o = makeSelect {qeSelectList = [(Iden [Name Nothing "a"],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] - ,qeOrderBy = o} + ms o = toQueryExpr $ makeSelect {msSelectList = [(Iden [Name Nothing "a"],Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]] + ,msOrderBy = o} offsetFetch :: TestItem offsetFetch = Group "offsetFetch" $ map (uncurry (TestQueryExpr ansi2011)) @@ -138,11 +138,11 @@ offsetFetch = Group "offsetFetch" $ map (uncurry (TestQueryExpr ansi2011)) -- ,ms (Just $ NumLit "5") (Just $ NumLit "10")) ] where - ms o l = makeSelect - {qeSelectList = [(Iden [Name Nothing "a"],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] - ,qeOffset = o - ,qeFetchFirst = l} + ms o l = toQueryExpr $ makeSelect + {msSelectList = [(Iden [Name Nothing "a"],Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]] + ,msOffset = o + ,msFetchFirst = l} combos :: TestItem combos = Group "combos" $ map (uncurry (TestQueryExpr ansi2011)) @@ -164,12 +164,12 @@ combos = Group "combos" $ map (uncurry (TestQueryExpr ansi2011)) Union SQDefault Respectively mst) ] where - mst = makeSelect - {qeSelectList = [(Iden [Name Nothing "a"],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]]} - msu = makeSelect - {qeSelectList = [(Iden [Name Nothing "b"],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "u"]]} + mst = toQueryExpr $ makeSelect + {msSelectList = [(Iden [Name Nothing "a"],Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]]} + msu = toQueryExpr $ makeSelect + {msSelectList = [(Iden [Name Nothing "b"],Nothing)] + ,msFrom = [TRSimple [Name Nothing "u"]]} withQueries :: TestItem @@ -189,9 +189,9 @@ withQueries = Group "with queries" $ map (uncurry (TestQueryExpr ansi2011)) ,With True [(Alias (Name Nothing "u") Nothing, ms1)] ms2) ] where - ms c t = makeSelect - {qeSelectList = [(Iden [Name Nothing c],Nothing)] - ,qeFrom = [TRSimple [Name Nothing t]]} + ms c t = toQueryExpr $ makeSelect + {msSelectList = [(Iden [Name Nothing c],Nothing)] + ,msFrom = [TRSimple [Name Nothing t]]} ms1 = ms "a" "t" ms2 = ms "a" "u" ms3 = ms "a" "x" diff --git a/tools/Language/SQL/SimpleSQL/QueryExprs.hs b/tools/Language/SQL/SimpleSQL/QueryExprs.hs index 6628619..d1ff7b3 100644 --- a/tools/Language/SQL/SimpleSQL/QueryExprs.hs +++ b/tools/Language/SQL/SimpleSQL/QueryExprs.hs @@ -17,11 +17,11 @@ queryExprsTests = Group "query exprs" $ map (uncurry (TestStatements ansi2011)) ,("select 1;select 1",[ms,ms]) ,(" select 1;select 1; ",[ms,ms]) ,("SELECT CURRENT_TIMESTAMP;" - ,[SelectStatement $ makeSelect - {qeSelectList = [(Iden [Name Nothing "CURRENT_TIMESTAMP"],Nothing)]}]) + ,[SelectStatement $ toQueryExpr $ makeSelect + {msSelectList = [(Iden [Name Nothing "CURRENT_TIMESTAMP"],Nothing)]}]) ,("SELECT \"CURRENT_TIMESTAMP\";" - ,[SelectStatement $ makeSelect - {qeSelectList = [(Iden [Name (Just ("\"","\"")) "CURRENT_TIMESTAMP"],Nothing)]}]) + ,[SelectStatement $ toQueryExpr $ makeSelect + {msSelectList = [(Iden [Name (Just ("\"","\"")) "CURRENT_TIMESTAMP"],Nothing)]}]) ] where - ms = SelectStatement $ makeSelect {qeSelectList = [(NumLit "1",Nothing)]} + ms = SelectStatement $ toQueryExpr $ makeSelect {msSelectList = [(NumLit "1",Nothing)]} diff --git a/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.hs b/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.hs index eab9348..89b15ba 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.hs +++ b/tools/Language/SQL/SimpleSQL/SQL2011DataManipulation.hs @@ -184,15 +184,15 @@ sql2011DataManipulationTests = Group "sql 2011 data manipulation tests" ,(TestStatement ansi2011 "insert into t select * from u" $ Insert [Name Nothing "t"] Nothing - $ InsertQuery makeSelect - {qeSelectList = [(Star, Nothing)] - ,qeFrom = [TRSimple [Name Nothing "u"]]}) + $ InsertQuery $ toQueryExpr $ makeSelect + {msSelectList = [(Star, Nothing)] + ,msFrom = [TRSimple [Name Nothing "u"]]}) ,(TestStatement ansi2011 "insert into t(a,b,c) select * from u" $ Insert [Name Nothing "t"] (Just [Name Nothing "a", Name Nothing "b", Name Nothing "c"]) - $ InsertQuery makeSelect - {qeSelectList = [(Star, Nothing)] - ,qeFrom = [TRSimple [Name Nothing "u"]]}) + $ InsertQuery $ toQueryExpr $ makeSelect + {msSelectList = [(Star, Nothing)] + ,msFrom = [TRSimple [Name Nothing "u"]]}) ,(TestStatement ansi2011 "insert into t default values" $ Insert [Name Nothing "t"] Nothing DefaultInsertValues) diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Queries.hs b/tools/Language/SQL/SimpleSQL/SQL2011Queries.hs index 5962f5d..a00f775 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011Queries.hs +++ b/tools/Language/SQL/SimpleSQL/SQL2011Queries.hs @@ -1528,14 +1528,14 @@ setFunctionSpecification = Group "set function specification" \ GROUPING(SalesQuota) AS Grouping\n\ \FROM Sales.SalesPerson\n\ \GROUP BY ROLLUP(SalesQuota);" - ,makeSelect - {qeSelectList = [(Iden [Name Nothing "SalesQuota"],Nothing) + ,toQueryExpr $ makeSelect + {msSelectList = [(Iden [Name Nothing "SalesQuota"],Nothing) ,(App [Name Nothing "SUM"] [Iden [Name Nothing "SalesYTD"]] ,Just (Name Nothing "TotalSalesYTD")) ,(App [Name Nothing "GROUPING"] [Iden [Name Nothing "SalesQuota"]] ,Just (Name Nothing "Grouping"))] - ,qeFrom = [TRSimple [Name Nothing "Sales",Name Nothing "SalesPerson"]] - ,qeGroupBy = [Rollup [SimpleGroup (Iden [Name Nothing "SalesQuota"])]]}) + ,msFrom = [TRSimple [Name Nothing "Sales",Name Nothing "SalesPerson"]] + ,msGroupBy = [Rollup [SimpleGroup (Iden [Name Nothing "SalesQuota"])]]}) ] {- @@ -2528,14 +2528,14 @@ arrayValueConstructor = Group "array value constructor" ,Array (Iden [Name Nothing "array"]) [Iden [Name Nothing "a"], Iden [Name Nothing "b"], Iden [Name Nothing "c"]]) ,("array(select * from t)" - ,ArrayCtor (makeSelect - {qeSelectList = [(Star,Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]]})) + ,ArrayCtor (toQueryExpr $ makeSelect + {msSelectList = [(Star,Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]]})) ,("array(select * from t order by a)" - ,ArrayCtor (makeSelect - {qeSelectList = [(Star,Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]] - ,qeOrderBy = [SortSpec (Iden [Name Nothing "a"]) + ,ArrayCtor (toQueryExpr $ makeSelect + {msSelectList = [(Star,Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]] + ,msOrderBy = [SortSpec (Iden [Name Nothing "a"]) DirDefault NullsOrderDefault]})) ] @@ -2625,12 +2625,12 @@ multisetValueConstructor = Group "multiset value constructor" $ map (uncurry (TestScalarExpr ansi2011)) [("multiset[a,b,c]", MultisetCtor[Iden [Name Nothing "a"] ,Iden [Name Nothing "b"], Iden [Name Nothing "c"]]) - ,("multiset(select * from t)", MultisetQueryCtor qe) - ,("table(select * from t)", MultisetQueryCtor qe) + ,("multiset(select * from t)", MultisetQueryCtor ms) + ,("table(select * from t)", MultisetQueryCtor ms) ] where - qe = makeSelect {qeSelectList = [(Star,Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]]} + ms = toQueryExpr $ makeSelect {msSelectList = [(Star,Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]]} -- = 7 Query expressions @@ -2761,9 +2761,9 @@ tableValueConstructor = Group "table value constructor" ,[BinOp (Iden [Name Nothing "a"]) [Name Nothing "+"] (Iden [Name Nothing "b"]) ,SubQueryExpr SqSq - (makeSelect - {qeSelectList = [(App [Name Nothing "count"] [Star],Nothing)] - ,qeFrom = [TRSimple [Name Nothing "t"]]})]]) + (toQueryExpr $ makeSelect + {msSelectList = [(App [Name Nothing "count"] [Star],Nothing)] + ,msFrom = [TRSimple [Name Nothing "t"]]})]]) ] {- @@ -2794,9 +2794,9 @@ fromClause :: TestItem fromClause = Group "fromClause" $ map (uncurry (TestQueryExpr ansi2011)) [("select * from tbl1,tbl2" - ,makeSelect - {qeSelectList = [(Star, Nothing)] - ,qeFrom = [TRSimple [Name Nothing "tbl1"], TRSimple [Name Nothing "tbl2"]] + ,toQueryExpr $ makeSelect + {msSelectList = [(Star, Nothing)] + ,msFrom = [TRSimple [Name Nothing "tbl1"], TRSimple [Name Nothing "tbl2"]] })] @@ -2810,7 +2810,7 @@ Reference a table. tableReference :: TestItem tableReference = Group "table reference" $ map (uncurry (TestQueryExpr ansi2011)) - [("select * from t", sel) + [("select * from t", toQueryExpr sel) {-