Merge pull request #51 from Airsequel/non-comma-separated-constraints
Parse constraints not separated by comma
This commit is contained in:
commit
f51600e0b1
|
@ -92,6 +92,8 @@ Data types to represent different dialect options
|
||||||
> ,diConvertFunction :: Bool
|
> ,diConvertFunction :: Bool
|
||||||
> -- | allow creating autoincrement columns
|
> -- | allow creating autoincrement columns
|
||||||
> ,diAutoincrement :: Bool
|
> ,diAutoincrement :: Bool
|
||||||
|
> -- | allow omitting the comma between constraint clauses
|
||||||
|
> ,diNonCommaSeparatedConstraints :: Bool
|
||||||
> }
|
> }
|
||||||
> deriving (Eq,Show,Read,Data,Typeable)
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
@ -115,6 +117,7 @@ Data types to represent different dialect options
|
||||||
> ,diSqlServerSymbols = False
|
> ,diSqlServerSymbols = False
|
||||||
> ,diConvertFunction = False
|
> ,diConvertFunction = False
|
||||||
> ,diAutoincrement = False
|
> ,diAutoincrement = False
|
||||||
|
> ,diNonCommaSeparatedConstraints = False
|
||||||
> }
|
> }
|
||||||
|
|
||||||
> -- | mysql dialect
|
> -- | mysql dialect
|
||||||
|
|
|
@ -1509,12 +1509,21 @@ TODO: change style
|
||||||
> CreateSchema <$> names
|
> CreateSchema <$> names
|
||||||
|
|
||||||
> createTable :: Parser Statement
|
> createTable :: Parser Statement
|
||||||
> createTable = keyword_ "table" >>
|
> createTable = do
|
||||||
|
> d <- getState
|
||||||
|
> let
|
||||||
|
> parseColumnDef = TableColumnDef <$> columnDef
|
||||||
|
> parseConstraintDef = uncurry TableConstraintDef <$> tableConstraintDef
|
||||||
|
> separator = if diNonCommaSeparatedConstraints d
|
||||||
|
> then optional comma
|
||||||
|
> else void comma
|
||||||
|
> constraints = sepBy parseConstraintDef separator
|
||||||
|
> entries = ((:) <$> parseColumnDef <*> ((comma >> entries) <|> pure [])) <|> constraints
|
||||||
|
>
|
||||||
|
> keyword_ "table" >>
|
||||||
> CreateTable
|
> CreateTable
|
||||||
> <$> names
|
> <$> names
|
||||||
> -- todo: is this order mandatory or is it a perm?
|
> <*> parens entries
|
||||||
> <*> parens (commaSep1 (uncurry TableConstraintDef <$> tableConstraintDef
|
|
||||||
> <|> TableColumnDef <$> columnDef))
|
|
||||||
|
|
||||||
> createIndex :: Parser Statement
|
> createIndex :: Parser Statement
|
||||||
> createIndex =
|
> createIndex =
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
with import <nixpkgs> {};
|
with import <nixpkgs> { };
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation rec {
|
||||||
name = "env";
|
name = "env";
|
||||||
env = buildEnv { name = name; paths = buildInputs; };
|
env = buildEnv { name = name; paths = buildInputs; };
|
||||||
|
@ -6,6 +6,7 @@ stdenv.mkDerivation rec {
|
||||||
ghc
|
ghc
|
||||||
cabal-install
|
cabal-install
|
||||||
glibcLocales
|
glibcLocales
|
||||||
|
gnumake
|
||||||
];
|
];
|
||||||
shellHook = "export LANG=en_GB.UTF-8";
|
shellHook = "export LANG=en_GB.UTF-8";
|
||||||
}
|
}
|
||||||
|
|
|
@ -651,6 +651,28 @@ defintely skip
|
||||||
> DefaultReferentialAction DefaultReferentialAction
|
> DefaultReferentialAction DefaultReferentialAction
|
||||||
> ])
|
> ])
|
||||||
|
|
||||||
|
> ,(TestStatement ansi2011 { diNonCommaSeparatedConstraints = True }
|
||||||
|
> "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
|
||||||
|
> ])
|
||||||
|
|
||||||
|
|
||||||
<references specification> ::=
|
<references specification> ::=
|
||||||
|
|
Loading…
Reference in a new issue