add support for create and drop view
This commit is contained in:
parent
8291fbaa44
commit
c2810cddd2
|
@ -1442,10 +1442,12 @@ TODO: change style
|
||||||
> statement :: Parser Statement
|
> statement :: Parser Statement
|
||||||
> statement = choice
|
> statement = choice
|
||||||
> [keyword_ "create" *> choice [createSchema
|
> [keyword_ "create" *> choice [createSchema
|
||||||
> ,createTable]
|
> ,createTable
|
||||||
|
> ,createView]
|
||||||
> ,keyword_ "alter" *> choice [alterTable]
|
> ,keyword_ "alter" *> choice [alterTable]
|
||||||
> ,keyword_ "drop" *> choice [dropSchema
|
> ,keyword_ "drop" *> choice [dropSchema
|
||||||
> ,dropTable]
|
> ,dropTable
|
||||||
|
> ,dropView]
|
||||||
> ,delete
|
> ,delete
|
||||||
> ,truncateSt
|
> ,truncateSt
|
||||||
> ,insert
|
> ,insert
|
||||||
|
@ -1618,6 +1620,28 @@ slightly hacky parser for signed integers
|
||||||
> dropTable = keyword_ "table" >>
|
> dropTable = keyword_ "table" >>
|
||||||
> DropTable <$> names <*> dropBehaviour
|
> DropTable <$> names <*> dropBehaviour
|
||||||
|
|
||||||
|
> createView :: Parser Statement
|
||||||
|
> createView =
|
||||||
|
> CreateView
|
||||||
|
> <$> (option False (True <$ keyword_ "recursive") <* keyword_ "view")
|
||||||
|
> <*> names
|
||||||
|
> <*> optionMaybe (parens (commaSep1 name))
|
||||||
|
> <*> (keyword_ "as" *> queryExpr)
|
||||||
|
> <*> optionMaybe (choice [
|
||||||
|
> -- todo: left factor
|
||||||
|
> DefaultCheckOption <$ try (keywords_ ["with", "check", "option"])
|
||||||
|
> ,CascadedCheckOption <$ try (keywords_ ["with", "cascaded", "check", "option"])
|
||||||
|
> ,LocalCheckOption <$ try (keywords_ ["with", "local", "check", "option"])
|
||||||
|
> ])
|
||||||
|
|
||||||
|
> dropView :: Parser Statement
|
||||||
|
> dropView = keyword_ "view" >>
|
||||||
|
> DropView <$> names <*> dropBehaviour
|
||||||
|
|
||||||
|
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
= dml
|
||||||
|
|
||||||
> delete :: Parser Statement
|
> delete :: Parser Statement
|
||||||
> delete = keywords_ ["delete","from"] >>
|
> delete = keywords_ ["delete","from"] >>
|
||||||
|
|
|
@ -505,6 +505,22 @@ which have been changed to try to improve the layout of the output.
|
||||||
> statement _ (DropTable n b) =
|
> statement _ (DropTable n b) =
|
||||||
> text "drop" <+> text "table" <+> names n <+> dropBehav b
|
> text "drop" <+> text "table" <+> names n <+> dropBehav b
|
||||||
|
|
||||||
|
> statement d (CreateView r nm al q co) =
|
||||||
|
> text "create" <+> (if r then text "recursive" else empty)
|
||||||
|
> <+> text "view" <+> names nm
|
||||||
|
> <+> (maybe empty (\al' -> parens $ commaSep $ map name al')) al
|
||||||
|
> <+> text "as"
|
||||||
|
> <+> queryExpr d q
|
||||||
|
> <+> case co of
|
||||||
|
> Nothing -> empty
|
||||||
|
> Just DefaultCheckOption -> texts ["with", "check", "option"]
|
||||||
|
> Just CascadedCheckOption -> texts ["with", "cascaded", "check", "option"]
|
||||||
|
> Just LocalCheckOption -> texts ["with", "local", "check", "option"]
|
||||||
|
|
||||||
|
> statement _ (DropView n b) =
|
||||||
|
> text "drop" <+> text "view" <+> names n <+> dropBehav b
|
||||||
|
|
||||||
|
|
||||||
== access control
|
== access control
|
||||||
|
|
||||||
== transactions
|
== transactions
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
> ,ReferenceMatch(..)
|
> ,ReferenceMatch(..)
|
||||||
> ,ReferentialAction(..)
|
> ,ReferentialAction(..)
|
||||||
> ,AlterTableAction(..)
|
> ,AlterTableAction(..)
|
||||||
|
> ,CheckOption(..)
|
||||||
> -- * Dialect
|
> -- * Dialect
|
||||||
> ,Dialect(..)
|
> ,Dialect(..)
|
||||||
> -- * Comment
|
> -- * Comment
|
||||||
|
@ -406,9 +407,10 @@ I'm not sure if this is valid syntax or not.
|
||||||
> | CreateTable [Name] [TableElement]
|
> | CreateTable [Name] [TableElement]
|
||||||
> | AlterTable [Name] AlterTableAction
|
> | AlterTable [Name] AlterTableAction
|
||||||
> | DropTable [Name] DropBehaviour
|
> | DropTable [Name] DropBehaviour
|
||||||
> {- | CreateView
|
> | CreateView Bool [Name] (Maybe [Name])
|
||||||
> | DropView
|
> QueryExpr (Maybe CheckOption)
|
||||||
> | CreateDomain
|
> | DropView [Name] DropBehaviour
|
||||||
|
> {- | CreateDomain
|
||||||
> | AlterDomain
|
> | AlterDomain
|
||||||
> | DropDomain
|
> | DropDomain
|
||||||
> | CreateCharacterSet
|
> | CreateCharacterSet
|
||||||
|
@ -617,11 +619,12 @@ I'm not sure if this is valid syntax or not.
|
||||||
> | SGONoCycle
|
> | SGONoCycle
|
||||||
> deriving (Eq,Show,Read,Data,Typeable)
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
> {-data ColumnConstraintDef =
|
> data CheckOption =
|
||||||
> | NotNullConstraint
|
> DefaultCheckOption
|
||||||
> | UniqueConstraint
|
> | CascadedCheckOption
|
||||||
> | ReferencesConstraint
|
> | LocalCheckOption
|
||||||
> | CheckConstraint-}
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
|
|
|
@ -1078,11 +1078,68 @@ defintely skip
|
||||||
<view column list> ::=
|
<view column list> ::=
|
||||||
<column name list>
|
<column name list>
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create view v as select * from t"
|
||||||
|
> $ CreateView False [Name "v"] Nothing (makeSelect
|
||||||
|
> {qeSelectList = [(Star, Nothing)]
|
||||||
|
> ,qeFrom = [TRSimple [Name "t"]]
|
||||||
|
> }) Nothing)
|
||||||
|
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create recursive view v as select * from t"
|
||||||
|
> $ CreateView True [Name "v"] Nothing (makeSelect
|
||||||
|
> {qeSelectList = [(Star, Nothing)]
|
||||||
|
> ,qeFrom = [TRSimple [Name "t"]]
|
||||||
|
> }) Nothing)
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create view v(a,b) as select * from t"
|
||||||
|
> $ CreateView False [Name "v"] (Just [Name "a", Name "b"])
|
||||||
|
> (makeSelect
|
||||||
|
> {qeSelectList = [(Star, Nothing)]
|
||||||
|
> ,qeFrom = [TRSimple [Name "t"]]
|
||||||
|
> }) Nothing)
|
||||||
|
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create view v as select * from t with check option"
|
||||||
|
> $ CreateView False [Name "v"] Nothing (makeSelect
|
||||||
|
> {qeSelectList = [(Star, Nothing)]
|
||||||
|
> ,qeFrom = [TRSimple [Name "t"]]
|
||||||
|
> }) (Just DefaultCheckOption))
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create view v as select * from t with cascaded check option"
|
||||||
|
> $ CreateView False [Name "v"] Nothing (makeSelect
|
||||||
|
> {qeSelectList = [(Star, Nothing)]
|
||||||
|
> ,qeFrom = [TRSimple [Name "t"]]
|
||||||
|
> }) (Just CascadedCheckOption))
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create view v as select * from t with local check option"
|
||||||
|
> $ CreateView False [Name "v"] Nothing
|
||||||
|
> (makeSelect
|
||||||
|
> {qeSelectList = [(Star, Nothing)]
|
||||||
|
> ,qeFrom = [TRSimple [Name "t"]]
|
||||||
|
> }) (Just LocalCheckOption))
|
||||||
|
|
||||||
|
|
||||||
11.33 <drop view statement>
|
11.33 <drop view statement>
|
||||||
|
|
||||||
<drop view statement> ::=
|
<drop view statement> ::=
|
||||||
DROP VIEW <table name> <drop behavior>
|
DROP VIEW <table name> <drop behavior>
|
||||||
|
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "drop view v"
|
||||||
|
> $ DropView [Name "v"] DefaultDropBehaviour)
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "drop view v cascade"
|
||||||
|
> $ DropView [Name "v"] Cascade)
|
||||||
|
|
||||||
|
|
||||||
11.34 <domain definition>
|
11.34 <domain definition>
|
||||||
|
|
||||||
<domain definition> ::=
|
<domain definition> ::=
|
||||||
|
|
Loading…
Reference in a new issue