add simple create table support
This commit is contained in:
parent
2938f642d3
commit
6802aaef5a
|
@ -232,7 +232,7 @@ fixing them in the syntax but leaving them till the semantic checking
|
||||||
> -> String
|
> -> String
|
||||||
> -- ^ the SQL source to parse
|
> -- ^ the SQL source to parse
|
||||||
> -> Either ParseError Statement
|
> -> Either ParseError Statement
|
||||||
> parseStatement = wrapParse statement
|
> parseStatement = wrapParse topLevelStatement
|
||||||
|
|
||||||
|
|
||||||
> -- | Parses a list of statements, with semi colons between
|
> -- | Parses a list of statements, with semi colons between
|
||||||
|
@ -1432,6 +1432,9 @@ TODO: change style
|
||||||
> topLevelQueryExpr :: Parser QueryExpr
|
> topLevelQueryExpr :: Parser QueryExpr
|
||||||
> topLevelQueryExpr = queryExpr <??> (id <$ semi)
|
> topLevelQueryExpr = queryExpr <??> (id <$ semi)
|
||||||
|
|
||||||
|
> topLevelStatement :: Parser Statement
|
||||||
|
> topLevelStatement = statement <??> (id <$ semi)
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
= Statements
|
= Statements
|
||||||
|
@ -1441,6 +1444,7 @@ TODO: change style
|
||||||
> [keyword_ "create"
|
> [keyword_ "create"
|
||||||
> *> choice
|
> *> choice
|
||||||
> [createSchema
|
> [createSchema
|
||||||
|
> ,createTable
|
||||||
> ]
|
> ]
|
||||||
> ,keyword_ "drop"
|
> ,keyword_ "drop"
|
||||||
> *> choice
|
> *> choice
|
||||||
|
@ -1457,6 +1461,14 @@ TODO: change style
|
||||||
> createSchema = keyword_ "schema" >>
|
> createSchema = keyword_ "schema" >>
|
||||||
> CreateSchema <$> names
|
> CreateSchema <$> names
|
||||||
|
|
||||||
|
> createTable :: Parser Statement
|
||||||
|
> createTable = keyword_ "table" >>
|
||||||
|
> CreateTable
|
||||||
|
> <$> names
|
||||||
|
> <*> parens (commaSep1 columnDef)
|
||||||
|
> where
|
||||||
|
> columnDef = ColumnDef <$> name <*> typeName
|
||||||
|
|
||||||
> dropSchema :: Parser Statement
|
> dropSchema :: Parser Statement
|
||||||
> dropSchema = keyword_ "schema" >>
|
> dropSchema = keyword_ "schema" >>
|
||||||
> DropSchema <$> names
|
> DropSchema <$> names
|
||||||
|
|
|
@ -453,6 +453,13 @@ which have been changed to try to improve the layout of the output.
|
||||||
> statement _ (CreateSchema nm) =
|
> statement _ (CreateSchema nm) =
|
||||||
> text "create" <+> text "schema" <+> names nm
|
> text "create" <+> text "schema" <+> names nm
|
||||||
|
|
||||||
|
> statement _ (CreateTable nm cds) =
|
||||||
|
> text "create" <+> text "table" <+> names nm
|
||||||
|
> <+> parens (commaSep $ map cd cds)
|
||||||
|
> where
|
||||||
|
> cd (ColumnDef n t) = name n <+> typeName t
|
||||||
|
|
||||||
|
|
||||||
> statement _ (DropSchema nm db) =
|
> statement _ (DropSchema nm db) =
|
||||||
> text "drop" <+> text "schema" <+> names nm <+> dropBehav db
|
> text "drop" <+> text "schema" <+> names nm <+> dropBehav db
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
> ,IdentityRestart(..)
|
> ,IdentityRestart(..)
|
||||||
> ,InsertSource(..)
|
> ,InsertSource(..)
|
||||||
> ,SetClause(..)
|
> ,SetClause(..)
|
||||||
|
> ,TableElement(..)
|
||||||
> -- * Dialect
|
> -- * Dialect
|
||||||
> ,Dialect(..)
|
> ,Dialect(..)
|
||||||
> -- * Comment
|
> -- * Comment
|
||||||
|
@ -392,8 +393,8 @@ I'm not sure if this is valid syntax or not.
|
||||||
> -- ddl
|
> -- ddl
|
||||||
> CreateSchema [Name] -- XXX
|
> CreateSchema [Name] -- XXX
|
||||||
> | DropSchema [Name] DropBehaviour -- XXX
|
> | DropSchema [Name] DropBehaviour -- XXX
|
||||||
> {- | CreateTable -- XXX
|
> | CreateTable [Name] [TableElement]
|
||||||
> | AlterTable -- XXX
|
> {- | AlterTable -- XXX
|
||||||
> | DropTable -- XXX
|
> | DropTable -- XXX
|
||||||
> | CreateView -- XXX
|
> | CreateView -- XXX
|
||||||
> | DropView -- XXX
|
> | DropView -- XXX
|
||||||
|
@ -486,6 +487,28 @@ I'm not sure if this is valid syntax or not.
|
||||||
> | SetMultiple [[Name]] [ValueExpr]
|
> | SetMultiple [[Name]] [ValueExpr]
|
||||||
> deriving (Eq,Show,Read,Data,Typeable)
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
> data TableElement =
|
||||||
|
> ColumnDef Name TypeName
|
||||||
|
> (Maybe DefaultClause)
|
||||||
|
> -- (Maybe ColumnConstraintDef)
|
||||||
|
> -- (Maybe CollateClause)
|
||||||
|
> -- | TableConstraintDef
|
||||||
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
|
> {-data TableConstraintDef
|
||||||
|
> deriving (Eq,Show,Read,Data,Typeable) -}
|
||||||
|
|
||||||
|
> data DefaultClause =
|
||||||
|
> DefaultClause ValueExpr
|
||||||
|
> | IdentityColumnSpec
|
||||||
|
> | GenerationClause
|
||||||
|
|
||||||
|
> {-data ColumnConstraintDef =
|
||||||
|
> | NotNullConstraint
|
||||||
|
> | UniqueConstraint
|
||||||
|
> | ReferencesConstraint
|
||||||
|
> | CheckConstraint-}
|
||||||
|
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
> -- | Used to set the dialect used for parsing and pretty printing,
|
> -- | Used to set the dialect used for parsing and pretty printing,
|
||||||
|
|
|
@ -90,7 +90,10 @@ schema name can be quoted iden or unicode quoted iden
|
||||||
[ WITH <system versioning clause> ]
|
[ WITH <system versioning clause> ]
|
||||||
[ ON COMMIT <table commit action> ROWS ]
|
[ ON COMMIT <table commit action> ROWS ]
|
||||||
|
|
||||||
,(TestStatement SQL2011 "create table ( a int )"
|
> ,(TestStatement SQL2011 "create table t (a int, b int);"
|
||||||
|
> $ CreateTable [Name "t"]
|
||||||
|
> [ColumnDef (Name "a") (TypeName [Name "int"])
|
||||||
|
> ,ColumnDef (Name "b") (TypeName [Name "int"])])
|
||||||
|
|
||||||
|
|
||||||
<table contents source> ::=
|
<table contents source> ::=
|
||||||
|
@ -251,6 +254,16 @@ schema name can be quoted iden or unicode quoted iden
|
||||||
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY
|
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY
|
||||||
[ <left paren> <common sequence generator options> <right paren> ]
|
[ <left paren> <common sequence generator options> <right paren> ]
|
||||||
|
|
||||||
|
generated always as identity
|
||||||
|
generated by default as identity
|
||||||
|
|
||||||
|
generated always as identity (start with signed_numeric
|
||||||
|
increment by n
|
||||||
|
maxvalue n | no maxvalue
|
||||||
|
minvalue n | no minvalue)
|
||||||
|
|
||||||
|
generated always (valueexpr)
|
||||||
|
|
||||||
<generation clause> ::=
|
<generation clause> ::=
|
||||||
<generation rule> AS <generation expression>
|
<generation rule> AS <generation expression>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue