Merge pull request #36 from bartoszw/master
Two enhancements of sqlserver dialect
This commit is contained in:
commit
a937424514
|
@ -88,6 +88,8 @@ Data types to represent different dialect options
|
|||
> ,diPostgresSymbols :: Bool
|
||||
> -- | allow sql server style symbols
|
||||
> ,diSqlServerSymbols :: Bool
|
||||
> -- | allow sql server style for CONVERT function in format CONVERT(data_type(length), expression, style)
|
||||
> ,diConvertFunction :: Bool
|
||||
> }
|
||||
> deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
|
@ -109,6 +111,7 @@ Data types to represent different dialect options
|
|||
> ,diEString = False
|
||||
> ,diPostgresSymbols = False
|
||||
> ,diSqlServerSymbols = False
|
||||
> ,diConvertFunction = False
|
||||
> }
|
||||
|
||||
> -- | mysql dialect
|
||||
|
@ -133,7 +136,9 @@ Data types to represent different dialect options
|
|||
> sqlserver = ansi2011 {diSquareBracketQuotedIden = True
|
||||
> ,diAtIdentifier = True
|
||||
> ,diHashIdentifier = True
|
||||
> ,diSqlServerSymbols = True }
|
||||
> ,diOdbc = True
|
||||
> ,diSqlServerSymbols = True
|
||||
> ,diConvertFunction = True}
|
||||
|
||||
> addLimit :: Dialect -> Dialect
|
||||
> addLimit d = d {diKeywords = "limit": diKeywords d
|
||||
|
|
|
@ -597,6 +597,16 @@ cast: cast(expr as type)
|
|||
> parens (Cast <$> scalarExpr
|
||||
> <*> (keyword_ "as" *> typeName))
|
||||
|
||||
=== convert
|
||||
|
||||
convertSqlServer: SqlServer dialect CONVERT(data_type(length), expression, style)
|
||||
|
||||
> convertSqlServer :: Parser ScalarExpr
|
||||
> convertSqlServer = guardDialect diConvertFunction
|
||||
> *> keyword_ "convert" *>
|
||||
> parens (Convert <$> typeName <*> (comma *> scalarExpr)
|
||||
> <*> optionMaybe (comma *> unsignedInteger))
|
||||
|
||||
=== exists, unique
|
||||
|
||||
subquery expression:
|
||||
|
@ -1175,6 +1185,7 @@ documenting/fixing.
|
|||
> ,parensExpr
|
||||
> ,caseExpr
|
||||
> ,cast
|
||||
> ,convertSqlServer
|
||||
> ,arrayCtor
|
||||
> ,multisetCtor
|
||||
> ,nextValueFor
|
||||
|
|
|
@ -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) =
|
||||
|
|
|
@ -167,6 +167,9 @@
|
|||
> -- | cast(a as typename)
|
||||
> | Cast ScalarExpr TypeName
|
||||
|
||||
> -- | convert expression to given datatype @CONVERT(data_type(length), expression, style)@
|
||||
> | Convert TypeName ScalarExpr (Maybe Integer)
|
||||
|
||||
> -- | case expression. both flavours supported
|
||||
> | Case
|
||||
> {caseTest :: Maybe ScalarExpr -- ^ test value
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
0.6.1 added odbc handling to sqlsqerver dialect
|
||||
added sqlserver dialect case for convert function
|
||||
0.6.0
|
||||
tested with ghc 8.8.1 also
|
||||
change the dialect handling - now a dialect is a bunch of flags
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
cabal-version: 2.2
|
||||
|
||||
name: simple-sql-parser
|
||||
version: 0.6.0
|
||||
version: 0.6.1
|
||||
synopsis: A parser for SQL.
|
||||
|
||||
description:
|
||||
|
|
|
@ -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 = [[]]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue