diff --git a/Language/SQL/SimpleSQL/Parse.lhs b/Language/SQL/SimpleSQL/Parse.lhs index 7674c51..4fdceb8 100644 --- a/Language/SQL/SimpleSQL/Parse.lhs +++ b/Language/SQL/SimpleSQL/Parse.lhs @@ -1509,12 +1509,17 @@ TODO: change style > CreateSchema <$> names > createTable :: Parser Statement -> createTable = keyword_ "table" >> +> createTable = do +> let +> parseColumnDef = TableColumnDef <$> columnDef +> parseConstraintDef = uncurry TableConstraintDef <$> tableConstraintDef +> constraints = sepBy parseConstraintDef (optional comma) +> entries = ((:) <$> parseColumnDef <*> ((comma >> entries) <|> pure [])) <|> constraints +> +> keyword_ "table" >> > CreateTable -> <$> names -> -- todo: is this order mandatory or is it a perm? -> <*> parens (commaSep1 (uncurry TableConstraintDef <$> tableConstraintDef -> <|> TableColumnDef <$> columnDef)) +> <$> names +> <*> parens entries > createIndex :: Parser Statement > createIndex = diff --git a/shell.nix b/shell.nix index 2ea013d..0de9067 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,4 @@ -with import {}; +with import { }; stdenv.mkDerivation rec { name = "env"; env = buildEnv { name = name; paths = buildInputs; }; @@ -6,6 +6,7 @@ stdenv.mkDerivation rec { ghc cabal-install glibcLocales + gnumake ]; shellHook = "export LANG=en_GB.UTF-8"; } diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs index d60ae64..0e7acd6 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs @@ -651,6 +651,28 @@ defintely skip > DefaultReferentialAction DefaultReferentialAction > ]) +> ,(TestStatement ansi2011 +> "create table t (a int, b int,\n\ +> \ foreign key (a) references u(c)\n\ +> \ foreign key (b) references v(d));" +> $ CreateTable [Name Nothing "t"] +> [TableColumnDef $ ColumnDef (Name Nothing "a") (TypeName [Name Nothing "int"]) Nothing [] +> ,TableColumnDef $ ColumnDef (Name Nothing "b") (TypeName [Name Nothing "int"]) Nothing [] +> ,TableConstraintDef Nothing $ +> TableReferencesConstraint +> [Name Nothing "a"] +> [Name Nothing "u"] +> (Just [Name Nothing "c"]) +> DefaultReferenceMatch +> DefaultReferentialAction DefaultReferentialAction +> ,TableConstraintDef Nothing $ +> TableReferencesConstraint +> [Name Nothing "b"] +> [Name Nothing "v"] +> (Just [Name Nothing "d"]) +> DefaultReferenceMatch +> DefaultReferentialAction DefaultReferentialAction +> ]) ::=