diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs index 13d219b..bd84430 100644 --- a/Language/SQL/SimpleSQL/Parser.lhs +++ b/Language/SQL/SimpleSQL/Parser.lhs @@ -232,7 +232,7 @@ fixing them in the syntax but leaving them till the semantic checking > -> String > -- ^ the SQL source to parse > -> Either ParseError Statement -> parseStatement = wrapParse statement +> parseStatement = wrapParse topLevelStatement > -- | Parses a list of statements, with semi colons between @@ -1432,6 +1432,9 @@ TODO: change style > topLevelQueryExpr :: Parser QueryExpr > topLevelQueryExpr = queryExpr (id <$ semi) +> topLevelStatement :: Parser Statement +> topLevelStatement = statement (id <$ semi) + ------------------------- = Statements @@ -1441,6 +1444,7 @@ TODO: change style > [keyword_ "create" > *> choice > [createSchema +> ,createTable > ] > ,keyword_ "drop" > *> choice @@ -1457,6 +1461,14 @@ TODO: change style > createSchema = keyword_ "schema" >> > CreateSchema <$> names +> createTable :: Parser Statement +> createTable = keyword_ "table" >> +> CreateTable +> <$> names +> <*> parens (commaSep1 columnDef) +> where +> columnDef = ColumnDef <$> name <*> typeName + > dropSchema :: Parser Statement > dropSchema = keyword_ "schema" >> > DropSchema <$> names diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index 039db76..689a27d 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -453,6 +453,13 @@ which have been changed to try to improve the layout of the output. > statement _ (CreateSchema 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) = > text "drop" <+> text "schema" <+> names nm <+> dropBehav db diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index b9d1adf..52bc5db 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -36,6 +36,7 @@ > ,IdentityRestart(..) > ,InsertSource(..) > ,SetClause(..) +> ,TableElement(..) > -- * Dialect > ,Dialect(..) > -- * Comment @@ -392,8 +393,8 @@ I'm not sure if this is valid syntax or not. > -- ddl > CreateSchema [Name] -- XXX > | DropSchema [Name] DropBehaviour -- XXX -> {- | CreateTable -- XXX -> | AlterTable -- XXX +> | CreateTable [Name] [TableElement] +> {- | AlterTable -- XXX > | DropTable -- XXX > | CreateView -- XXX > | DropView -- XXX @@ -486,6 +487,28 @@ I'm not sure if this is valid syntax or not. > | SetMultiple [[Name]] [ValueExpr] > 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, diff --git a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs index aa8e972..aba17dd 100644 --- a/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs +++ b/tools/Language/SQL/SimpleSQL/SQL2011Schema.lhs @@ -90,7 +90,10 @@ schema name can be quoted iden or unicode quoted iden [ WITH ] [ ON COMMIT 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"])])
::= @@ -251,6 +254,16 @@ schema name can be quoted iden or unicode quoted iden GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ] +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) + ::= AS