diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index b085e83..272e63e 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -254,6 +254,11 @@ Try to do this when this code is ported to a modern pretty printing lib. > scalarExpr d (OdbcFunc e) = > text "{fn" <+> scalarExpr d e <> text "}" +> scalarExpr d (Convert t e Nothing) = +> text "convert(" <> typeName t <> text "," <+> scalarExpr d e <> text ")" +> scalarExpr d (Convert t e (Just i)) = +> text "convert(" <> typeName t <> text "," <+> scalarExpr d e <> text "," <+> text (show i) <> text ")" + > unname :: Name -> String > unname (Name Nothing n) = n > unname (Name (Just (s,e)) n) = diff --git a/tools/Language/SQL/SimpleSQL/LexerTests.lhs b/tools/Language/SQL/SimpleSQL/LexerTests.lhs index fc0a46b..14246f5 100644 --- a/tools/Language/SQL/SimpleSQL/LexerTests.lhs +++ b/tools/Language/SQL/SimpleSQL/LexerTests.lhs @@ -318,8 +318,8 @@ the + or -. > [ LexTest sqlserver {diOdbc = True} s t | (s,t) <- > [("{}", [Symbol "{", Symbol "}"]) > ]] -> ++ [LexFails sqlserver "{" -> ,LexFails sqlserver "}"] +> ++ [LexFails sqlserver {diOdbc = False} "{" +> ,LexFails sqlserver {diOdbc = False} "}"] > combos :: [a] -> Int -> [[a]] > combos _ 0 = [[]] diff --git a/tools/Language/SQL/SimpleSQL/ScalarExprs.lhs b/tools/Language/SQL/SimpleSQL/ScalarExprs.lhs index f2397d3..80dad53 100644 --- a/tools/Language/SQL/SimpleSQL/ScalarExprs.lhs +++ b/tools/Language/SQL/SimpleSQL/ScalarExprs.lhs @@ -5,7 +5,7 @@ Tests for parsing scalar expressions > import Language.SQL.SimpleSQL.TestTypes > import Language.SQL.SimpleSQL.Syntax - + > scalarExprTests :: TestItem > scalarExprTests = Group "scalarExprTests" > [literals @@ -15,6 +15,7 @@ Tests for parsing scalar expressions > ,dots > ,app > ,caseexp +> ,convertfun > ,operators > ,parens > ,subqueries @@ -110,6 +111,16 @@ Tests for parsing scalar expressions > ] +> convertfun :: TestItem +> convertfun = Group "convert" $ map (uncurry (TestScalarExpr sqlserver)) +> [("CONVERT(varchar, 25.65)" +> ,Convert (TypeName [Name Nothing "varchar"]) (NumLit "25.65") Nothing) +> ,("CONVERT(datetime, '2017-08-25')" +> ,Convert (TypeName [Name Nothing "datetime"]) (StringLit "'" "'" "2017-08-25") Nothing) +> ,("CONVERT(varchar, '2017-08-25', 101)" +> ,Convert (TypeName [Name Nothing "varchar"]) (StringLit "'" "'" "2017-08-25") (Just 101)) +> ] + > operators :: TestItem > operators = Group "operators" > [binaryOperators