From 4f80ec96d4a20e59cfb40cfe33d2de1f2e7a7be4 Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Sun, 2 Aug 2015 18:14:45 +0300 Subject: [PATCH] add generation clause support to create table --- Language/SQL/SimpleSQL/Parser.lhs | 3 +++ Language/SQL/SimpleSQL/Pretty.lhs | 2 ++ Language/SQL/SimpleSQL/Syntax.lhs | 2 +- tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs | 10 ++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs index 4eddec6..b68bc73 100644 --- a/Language/SQL/SimpleSQL/Parser.lhs +++ b/Language/SQL/SimpleSQL/Parser.lhs @@ -1472,6 +1472,9 @@ TODO: change style > defaultClause = choice [ > keyword_ "default" >> > DefaultClause <$> valueExpr +> -- todo: left factor +> ,try (keywords_ ["generated","always","as"] >> +> GenerationClause <$> parens valueExpr) > ,keyword_ "generated" >> > IdentityColumnSpec > <$> option GeneratedDefault diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index 6fdb1fd..39f2162 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -463,6 +463,8 @@ which have been changed to try to improve the layout of the output. > Nothing -> empty > Just (DefaultClause def) -> > text "default" <+> valueExpr d def +> Just (GenerationClause e) -> +> texts ["generated","always","as"] <+> parens (valueExpr d e) > Just (IdentityColumnSpec w o) -> > text "generated" > <+> (case w of diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index 73b518c..0cdf102 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -504,7 +504,7 @@ I'm not sure if this is valid syntax or not. > data DefaultClause = > DefaultClause ValueExpr > | IdentityColumnSpec IdentityWhen [SequenceGeneratorOption] -> -- | GenerationClause +> | GenerationClause ValueExpr > deriving (Eq,Show,Read,Data,Typeable) > data IdentityWhen = diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs index eddd330..6b1a060 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs @@ -356,6 +356,16 @@ generated always (valueexpr) ::= +> ,(TestStatement SQL2011 +> "create table t (a int, \ +> \ a2 int generated always as (a * 2));" +> $ CreateTable [Name "t"] +> [ColumnDef (Name "a") (TypeName [Name "int"]) Nothing +> ,ColumnDef (Name "a2") (TypeName [Name "int"]) +> (Just $ GenerationClause +> (BinOp (Iden [Name "a"]) [Name "*"] (NumLit "2")))]) + + 11.5