add create, alter, drop domain
This commit is contained in:
parent
c2810cddd2
commit
9aab04b189
|
@ -189,7 +189,7 @@ fixing them in the syntax but leaving them till the semantic checking
|
||||||
> import Data.Char (toLower, isDigit)
|
> import Data.Char (toLower, isDigit)
|
||||||
> import Text.Parsec (setPosition,setSourceColumn,setSourceLine,getPosition
|
> import Text.Parsec (setPosition,setSourceColumn,setSourceLine,getPosition
|
||||||
> ,option,between,sepBy,sepBy1
|
> ,option,between,sepBy,sepBy1
|
||||||
> ,try,many1,(<|>),choice,eof
|
> ,try,many,many1,(<|>),choice,eof
|
||||||
> ,optionMaybe,optional,runParser
|
> ,optionMaybe,optional,runParser
|
||||||
> ,chainl1, chainr1,(<?>))
|
> ,chainl1, chainr1,(<?>))
|
||||||
> -- import Text.Parsec.String (Parser)
|
> -- import Text.Parsec.String (Parser)
|
||||||
|
@ -1443,11 +1443,14 @@ TODO: change style
|
||||||
> statement = choice
|
> statement = choice
|
||||||
> [keyword_ "create" *> choice [createSchema
|
> [keyword_ "create" *> choice [createSchema
|
||||||
> ,createTable
|
> ,createTable
|
||||||
> ,createView]
|
> ,createView
|
||||||
> ,keyword_ "alter" *> choice [alterTable]
|
> ,createDomain]
|
||||||
|
> ,keyword_ "alter" *> choice [alterTable
|
||||||
|
> ,alterDomain]
|
||||||
> ,keyword_ "drop" *> choice [dropSchema
|
> ,keyword_ "drop" *> choice [dropSchema
|
||||||
> ,dropTable
|
> ,dropTable
|
||||||
> ,dropView]
|
> ,dropView
|
||||||
|
> ,dropDomain]
|
||||||
> ,delete
|
> ,delete
|
||||||
> ,truncateSt
|
> ,truncateSt
|
||||||
> ,insert
|
> ,insert
|
||||||
|
@ -1638,6 +1641,35 @@ slightly hacky parser for signed integers
|
||||||
> dropView = keyword_ "view" >>
|
> dropView = keyword_ "view" >>
|
||||||
> DropView <$> names <*> dropBehaviour
|
> DropView <$> names <*> dropBehaviour
|
||||||
|
|
||||||
|
> createDomain :: Parser Statement
|
||||||
|
> createDomain = keyword_ "domain" >>
|
||||||
|
> CreateDomain
|
||||||
|
> <$> names
|
||||||
|
> <*> (optional (keyword_ "as") *> typeName)
|
||||||
|
> <*> optionMaybe (keyword_ "default" *> valueExpr)
|
||||||
|
> <*> many con
|
||||||
|
> where
|
||||||
|
> con = (,) <$> optionMaybe (keyword_ "constraint" *> names)
|
||||||
|
> <*> (keyword_ "check" *> parens valueExpr)
|
||||||
|
|
||||||
|
> alterDomain :: Parser Statement
|
||||||
|
> alterDomain = keyword_ "domain" >>
|
||||||
|
> AlterDomain
|
||||||
|
> <$> names
|
||||||
|
> <*> (setDefault <|> constraint
|
||||||
|
> <|> (keyword_ "drop" *> (dropDefault <|> dropConstraint)))
|
||||||
|
> where
|
||||||
|
> setDefault = keywords_ ["set", "default"] >> ADSetDefault <$> valueExpr
|
||||||
|
> constraint = keyword_ "add" >>
|
||||||
|
> ADAddConstraint
|
||||||
|
> <$> optionMaybe (keyword_ "constraint" *> names)
|
||||||
|
> <*> (keyword_ "check" *> parens valueExpr)
|
||||||
|
> dropDefault = ADDropDefault <$ keyword_ "default"
|
||||||
|
> dropConstraint = keyword_ "constraint" >> ADDropConstraint <$> names
|
||||||
|
|
||||||
|
> dropDomain :: Parser Statement
|
||||||
|
> dropDomain = keyword_ "domain" >>
|
||||||
|
> DropDomain <$> names <*> dropBehaviour
|
||||||
|
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
|
|
@ -469,6 +469,34 @@ which have been changed to try to improve the layout of the output.
|
||||||
> statement _ (DropSchema nm db) =
|
> statement _ (DropSchema nm db) =
|
||||||
> text "drop" <+> text "schema" <+> names nm <+> dropBehav db
|
> text "drop" <+> text "schema" <+> names nm <+> dropBehav db
|
||||||
|
|
||||||
|
> statement d (CreateDomain nm ty def cs) =
|
||||||
|
> text "create" <+> text "domain" <+> names nm
|
||||||
|
> <+> typeName ty
|
||||||
|
> <+> maybe empty (\def' -> text "default" <+> valueExpr d def') def
|
||||||
|
> <+> sep (map con cs)
|
||||||
|
> where
|
||||||
|
> con (cn, e) =
|
||||||
|
> maybe empty (\cn' -> text "constraint" <+> names cn') cn
|
||||||
|
> <+> text "check" <> parens (valueExpr d e)
|
||||||
|
|
||||||
|
> statement d (AlterDomain nm act) =
|
||||||
|
> texts ["alter","domain"]
|
||||||
|
> <+> names nm
|
||||||
|
> <+> a act
|
||||||
|
> where
|
||||||
|
> a (ADSetDefault v) = texts ["set","default"] <+> valueExpr d v
|
||||||
|
> a (ADDropDefault) = texts ["drop","default"]
|
||||||
|
> a (ADAddConstraint nm e) =
|
||||||
|
> text "add"
|
||||||
|
> <+> maybe empty (\nm' -> text "constraint" <+> names nm') nm
|
||||||
|
> <+> text "check" <> parens (valueExpr d e)
|
||||||
|
> a (ADDropConstraint nm) = texts ["drop", "constraint"]
|
||||||
|
> <+> names nm
|
||||||
|
|
||||||
|
|
||||||
|
> statement _ (DropDomain nm db) =
|
||||||
|
> text "drop" <+> text "domain" <+> names nm <+> dropBehav db
|
||||||
|
|
||||||
== dml
|
== dml
|
||||||
|
|
||||||
> statement d (SelectStatement q) = queryExpr d q
|
> statement d (SelectStatement q) = queryExpr d q
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
> ,ReferentialAction(..)
|
> ,ReferentialAction(..)
|
||||||
> ,AlterTableAction(..)
|
> ,AlterTableAction(..)
|
||||||
> ,CheckOption(..)
|
> ,CheckOption(..)
|
||||||
|
> ,AlterDomainAction(..)
|
||||||
> -- * Dialect
|
> -- * Dialect
|
||||||
> ,Dialect(..)
|
> ,Dialect(..)
|
||||||
> -- * Comment
|
> -- * Comment
|
||||||
|
@ -410,10 +411,11 @@ I'm not sure if this is valid syntax or not.
|
||||||
> | CreateView Bool [Name] (Maybe [Name])
|
> | CreateView Bool [Name] (Maybe [Name])
|
||||||
> QueryExpr (Maybe CheckOption)
|
> QueryExpr (Maybe CheckOption)
|
||||||
> | DropView [Name] DropBehaviour
|
> | DropView [Name] DropBehaviour
|
||||||
> {- | CreateDomain
|
> | CreateDomain [Name] TypeName (Maybe ValueExpr)
|
||||||
> | AlterDomain
|
> [(Maybe [Name], ValueExpr)]
|
||||||
> | DropDomain
|
> | AlterDomain [Name] AlterDomainAction
|
||||||
> | CreateCharacterSet
|
> | DropDomain [Name] DropBehaviour
|
||||||
|
> {- | CreateCharacterSet
|
||||||
> | DropCharacterSet
|
> | DropCharacterSet
|
||||||
> | CreateCollation
|
> | CreateCollation
|
||||||
> | DropCollation
|
> | DropCollation
|
||||||
|
@ -625,6 +627,13 @@ I'm not sure if this is valid syntax or not.
|
||||||
> | LocalCheckOption
|
> | LocalCheckOption
|
||||||
> deriving (Eq,Show,Read,Data,Typeable)
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
> data AlterDomainAction =
|
||||||
|
> ADSetDefault ValueExpr
|
||||||
|
> | ADDropDefault
|
||||||
|
> | ADAddConstraint (Maybe [Name]) ValueExpr
|
||||||
|
> | ADDropConstraint [Name]
|
||||||
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
|
|
|
@ -1152,6 +1152,40 @@ defintely skip
|
||||||
[ <constraint name definition> ] <check constraint definition> [
|
[ <constraint name definition> ] <check constraint definition> [
|
||||||
<constraint characteristics> ]
|
<constraint characteristics> ]
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create domain my_int int"
|
||||||
|
> $ CreateDomain [Name "my_int"]
|
||||||
|
> (TypeName [Name "int"])
|
||||||
|
> Nothing [])
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create domain my_int as int"
|
||||||
|
> $ CreateDomain [Name "my_int"]
|
||||||
|
> (TypeName [Name "int"])
|
||||||
|
> Nothing [])
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create domain my_int int default 0"
|
||||||
|
> $ CreateDomain [Name "my_int"]
|
||||||
|
> (TypeName [Name "int"])
|
||||||
|
> (Just (NumLit "0")) [])
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create domain my_int int check (value > 5)"
|
||||||
|
> $ CreateDomain [Name "my_int"]
|
||||||
|
> (TypeName [Name "int"])
|
||||||
|
> Nothing [(Nothing
|
||||||
|
> ,BinOp (Iden [Name "value"]) [Name ">"] (NumLit "5"))])
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create domain my_int int constraint gt5 check (value > 5)"
|
||||||
|
> $ CreateDomain [Name "my_int"]
|
||||||
|
> (TypeName [Name "int"])
|
||||||
|
> Nothing [(Just [Name "gt5"]
|
||||||
|
> ,BinOp (Iden [Name "value"]) [Name ">"] (NumLit "5"))])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
11.35 <alter domain statement>
|
11.35 <alter domain statement>
|
||||||
|
|
||||||
<alter domain statement> ::=
|
<alter domain statement> ::=
|
||||||
|
@ -1168,26 +1202,66 @@ defintely skip
|
||||||
<set domain default clause> ::=
|
<set domain default clause> ::=
|
||||||
SET <default clause>
|
SET <default clause>
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "alter domain my_int set default 0"
|
||||||
|
> $ AlterDomain [Name "my_int"]
|
||||||
|
> $ ADSetDefault $ NumLit "0")
|
||||||
|
|
||||||
|
|
||||||
11.37 <drop domain default clause>
|
11.37 <drop domain default clause>
|
||||||
|
|
||||||
<drop domain default clause> ::=
|
<drop domain default clause> ::=
|
||||||
DROP DEFAULT
|
DROP DEFAULT
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "alter domain my_int drop default"
|
||||||
|
> $ AlterDomain [Name "my_int"]
|
||||||
|
> $ ADDropDefault)
|
||||||
|
|
||||||
|
|
||||||
11.38 <add domain constraint definition>
|
11.38 <add domain constraint definition>
|
||||||
|
|
||||||
<add domain constraint definition> ::=
|
<add domain constraint definition> ::=
|
||||||
ADD <domain constraint>
|
ADD <domain constraint>
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "alter domain my_int add check (value > 6)"
|
||||||
|
> $ AlterDomain [Name "my_int"]
|
||||||
|
> $ ADAddConstraint Nothing
|
||||||
|
> $ BinOp (Iden [Name "value"]) [Name ">"] (NumLit "6"))
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "alter domain my_int add constraint gt6 check (value > 6)"
|
||||||
|
> $ AlterDomain [Name "my_int"]
|
||||||
|
> $ ADAddConstraint (Just [Name "gt6"])
|
||||||
|
> $ BinOp (Iden [Name "value"]) [Name ">"] (NumLit "6"))
|
||||||
|
|
||||||
|
|
||||||
11.39 <drop domain constraint definition>
|
11.39 <drop domain constraint definition>
|
||||||
|
|
||||||
<drop domain constraint definition> ::=
|
<drop domain constraint definition> ::=
|
||||||
DROP CONSTRAINT <constraint name>
|
DROP CONSTRAINT <constraint name>
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "alter domain my_int drop constraint gt6"
|
||||||
|
> $ AlterDomain [Name "my_int"]
|
||||||
|
> $ ADDropConstraint [Name "gt6"])
|
||||||
|
|
||||||
11.40 <drop domain statement>
|
11.40 <drop domain statement>
|
||||||
|
|
||||||
<drop domain statement> ::=
|
<drop domain statement> ::=
|
||||||
DROP DOMAIN <domain name> <drop behavior>
|
DROP DOMAIN <domain name> <drop behavior>
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "drop domain my_int"
|
||||||
|
> $ DropDomain [Name "my_int"] DefaultDropBehaviour)
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "drop domain my_int cascade"
|
||||||
|
> $ DropDomain [Name "my_int"] Cascade)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
11.41 <character set definition>
|
11.41 <character set definition>
|
||||||
|
|
||||||
<character set definition> ::=
|
<character set definition> ::=
|
||||||
|
|
Loading…
Reference in a new issue