From 8291fbaa44f277dafd38d45d6b2193f4eececb1c Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Sun, 2 Aug 2015 23:27:09 +0300 Subject: [PATCH] add drop table support --- Language/SQL/SimpleSQL/Parser.lhs | 11 +++++++--- Language/SQL/SimpleSQL/Pretty.lhs | 3 +++ Language/SQL/SimpleSQL/Syntax.lhs | 20 +++++++++---------- .../Language/SQL/SimpleSQL/SQL2011Schema.lhs | 11 +++++++--- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs index b321856..54367ec 100644 --- a/Language/SQL/SimpleSQL/Parser.lhs +++ b/Language/SQL/SimpleSQL/Parser.lhs @@ -1444,7 +1444,8 @@ TODO: change style > [keyword_ "create" *> choice [createSchema > ,createTable] > ,keyword_ "alter" *> choice [alterTable] -> ,keyword_ "drop" *> choice [dropSchema] +> ,keyword_ "drop" *> choice [dropSchema +> ,dropTable] > ,delete > ,truncateSt > ,insert @@ -1611,8 +1612,12 @@ slightly hacky parser for signed integers > dropSchema :: Parser Statement > dropSchema = keyword_ "schema" >> -> DropSchema <$> names -> <*> dropBehaviour +> DropSchema <$> names <*> dropBehaviour + +> dropTable :: Parser Statement +> dropTable = keyword_ "table" >> +> DropTable <$> names <*> dropBehaviour + > delete :: Parser Statement > delete = keywords_ ["delete","from"] >> diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index 918b3f8..5d0e8c0 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -502,6 +502,9 @@ which have been changed to try to improve the layout of the output. > sc (SetMultiple ts vs) = parens (commaSep $ map names ts) <+> text "=" > <+> parens (commaSep $ map (valueExpr d) vs) +> statement _ (DropTable n b) = +> text "drop" <+> text "table" <+> names n <+> dropBehav b + == access control == transactions diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index 662336f..44b2f36 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -401,16 +401,16 @@ I'm not sure if this is valid syntax or not. > data Statement = > -- ddl -> CreateSchema [Name] -- XXX -> | DropSchema [Name] DropBehaviour -- XXX +> CreateSchema [Name] +> | DropSchema [Name] DropBehaviour > | CreateTable [Name] [TableElement] > | AlterTable [Name] AlterTableAction -> {- | DropTable -- XXX -> | CreateView -- XXX -> | DropView -- XXX -> | CreateDomain -- XXX +> | DropTable [Name] DropBehaviour +> {- | CreateView +> | DropView +> | CreateDomain > | AlterDomain -> | DropDomain -- XXX +> | DropDomain > | CreateCharacterSet > | DropCharacterSet > | CreateCollation @@ -430,9 +430,9 @@ I'm not sure if this is valid syntax or not. > | CreateOrdering > | DropOrdering > -- transforms -> | CreateSequence -- XXX -> | AlterSequence -- XXX -> | DropSequence -- XXX -} +> | CreateSequence +> | AlterSequence +> | DropSequence -} > -- dml > | SelectStatement QueryExpr > {- | DeclareCursor diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs index 5614704..6727347 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs @@ -1032,9 +1032,14 @@ defintely skip ::= DROP TABLE -drop table t -drop table t cascade -drop table t restrict +> ,(TestStatement SQL2011 +> "drop table t" +> $ DropTable [Name "t"] DefaultDropBehaviour) + +> ,(TestStatement SQL2011 +> "drop table t restrict" +> $ DropTable [Name "t"] Restrict) + 11.32