add create,alter,drop sequence
This commit is contained in:
parent
9aab04b189
commit
a9d51d1ebb
|
@ -1444,13 +1444,16 @@ TODO: change style
|
||||||
> [keyword_ "create" *> choice [createSchema
|
> [keyword_ "create" *> choice [createSchema
|
||||||
> ,createTable
|
> ,createTable
|
||||||
> ,createView
|
> ,createView
|
||||||
> ,createDomain]
|
> ,createDomain
|
||||||
|
> ,createSequence]
|
||||||
> ,keyword_ "alter" *> choice [alterTable
|
> ,keyword_ "alter" *> choice [alterTable
|
||||||
> ,alterDomain]
|
> ,alterDomain
|
||||||
|
> ,alterSequence]
|
||||||
> ,keyword_ "drop" *> choice [dropSchema
|
> ,keyword_ "drop" *> choice [dropSchema
|
||||||
> ,dropTable
|
> ,dropTable
|
||||||
> ,dropView
|
> ,dropView
|
||||||
> ,dropDomain]
|
> ,dropDomain
|
||||||
|
> ,dropSequence]
|
||||||
> ,delete
|
> ,delete
|
||||||
> ,truncateSt
|
> ,truncateSt
|
||||||
> ,insert
|
> ,insert
|
||||||
|
@ -1488,31 +1491,6 @@ TODO: change style
|
||||||
> <*> (keywords_ ["as", "identity"] *>
|
> <*> (keywords_ ["as", "identity"] *>
|
||||||
> option [] (parens sequenceGeneratorOptions))
|
> option [] (parens sequenceGeneratorOptions))
|
||||||
> ]
|
> ]
|
||||||
> sequenceGeneratorOptions =
|
|
||||||
> -- todo: could try to combine exclusive options
|
|
||||||
> -- such as cycle and nocycle
|
|
||||||
> permute ((\a b c d e f g h -> catMaybes [a,b,c,d,e,f,g,h])
|
|
||||||
> <$?> (Nothing, Just <$> startWith)
|
|
||||||
> <|?> (Nothing, Just <$> incrementBy)
|
|
||||||
> <|?> (Nothing, Just <$> maxValue)
|
|
||||||
> <|?> (Nothing, Just <$> noMaxValue)
|
|
||||||
> <|?> (Nothing, Just <$> minValue)
|
|
||||||
> <|?> (Nothing, Just <$> noMinValue)
|
|
||||||
> <|?> (Nothing, Just <$> scycle)
|
|
||||||
> <|?> (Nothing, Just <$> noCycle)
|
|
||||||
> )
|
|
||||||
> startWith = keywords_ ["start", "with"] >>
|
|
||||||
> SGOStartWith <$> signedInteger
|
|
||||||
> incrementBy = keywords_ ["increment", "by"] >>
|
|
||||||
> SGOIncrementBy <$> signedInteger
|
|
||||||
> maxValue = keyword_ "maxvalue" >>
|
|
||||||
> SGOMaxValue <$> signedInteger
|
|
||||||
> noMaxValue = SGONoMaxValue <$ try (keywords_ ["no","maxvalue"])
|
|
||||||
> minValue = keyword_ "minvalue" >>
|
|
||||||
> SGOMinValue <$> signedInteger
|
|
||||||
> noMinValue = SGONoMinValue <$ try (keywords_ ["no","minvalue"])
|
|
||||||
> scycle = SGOCycle <$ keyword_ "cycle"
|
|
||||||
> noCycle = SGONoCycle <$ try (keywords_ ["no","cycle"])
|
|
||||||
|
|
||||||
> tableConstraintDef :: Parser (Maybe [Name], TableConstraint)
|
> tableConstraintDef :: Parser (Maybe [Name], TableConstraint)
|
||||||
> tableConstraintDef =
|
> tableConstraintDef =
|
||||||
|
@ -1578,6 +1556,44 @@ slightly hacky parser for signed integers
|
||||||
> (*) <$> option 1 (1 <$ symbol "+" <|> (-1) <$ symbol "-")
|
> (*) <$> option 1 (1 <$ symbol "+" <|> (-1) <$ symbol "-")
|
||||||
> <*> unsignedInteger
|
> <*> unsignedInteger
|
||||||
|
|
||||||
|
> sequenceGeneratorOptions :: Parser [SequenceGeneratorOption]
|
||||||
|
> sequenceGeneratorOptions =
|
||||||
|
> -- todo: could try to combine exclusive options
|
||||||
|
> -- such as cycle and nocycle
|
||||||
|
> -- sort out options which are sometimes not allowed
|
||||||
|
> -- as datatype, and restart with
|
||||||
|
> permute ((\a b c d e f g h j k -> catMaybes [a,b,c,d,e,f,g,h,j,k])
|
||||||
|
> <$?> nj startWith
|
||||||
|
> <|?> nj dataType
|
||||||
|
> <|?> nj restart
|
||||||
|
> <|?> nj incrementBy
|
||||||
|
> <|?> nj maxValue
|
||||||
|
> <|?> nj noMaxValue
|
||||||
|
> <|?> nj minValue
|
||||||
|
> <|?> nj noMinValue
|
||||||
|
> <|?> nj scycle
|
||||||
|
> <|?> nj noCycle
|
||||||
|
> )
|
||||||
|
> where
|
||||||
|
> nj p = (Nothing,Just <$> p)
|
||||||
|
> startWith = keywords_ ["start", "with"] >>
|
||||||
|
> SGOStartWith <$> signedInteger
|
||||||
|
> dataType = keyword_ "as" >>
|
||||||
|
> SGODataType <$> typeName
|
||||||
|
> restart = keyword_ "restart" >>
|
||||||
|
> SGORestart <$> optionMaybe (keyword_ "with" *> signedInteger)
|
||||||
|
> incrementBy = keywords_ ["increment", "by"] >>
|
||||||
|
> SGOIncrementBy <$> signedInteger
|
||||||
|
> maxValue = keyword_ "maxvalue" >>
|
||||||
|
> SGOMaxValue <$> signedInteger
|
||||||
|
> noMaxValue = SGONoMaxValue <$ try (keywords_ ["no","maxvalue"])
|
||||||
|
> minValue = keyword_ "minvalue" >>
|
||||||
|
> SGOMinValue <$> signedInteger
|
||||||
|
> noMinValue = SGONoMinValue <$ try (keywords_ ["no","minvalue"])
|
||||||
|
> scycle = SGOCycle <$ keyword_ "cycle"
|
||||||
|
> noCycle = SGONoCycle <$ try (keywords_ ["no","cycle"])
|
||||||
|
|
||||||
|
|
||||||
> alterTable :: Parser Statement
|
> alterTable :: Parser Statement
|
||||||
> alterTable = keyword_ "table" >>
|
> alterTable = keyword_ "table" >>
|
||||||
> -- the choices have been ordered so that it works
|
> -- the choices have been ordered so that it works
|
||||||
|
@ -1671,6 +1687,22 @@ slightly hacky parser for signed integers
|
||||||
> dropDomain = keyword_ "domain" >>
|
> dropDomain = keyword_ "domain" >>
|
||||||
> DropDomain <$> names <*> dropBehaviour
|
> DropDomain <$> names <*> dropBehaviour
|
||||||
|
|
||||||
|
> createSequence :: Parser Statement
|
||||||
|
> createSequence = keyword_ "sequence" >>
|
||||||
|
> CreateSequence
|
||||||
|
> <$> names
|
||||||
|
> <*> sequenceGeneratorOptions
|
||||||
|
|
||||||
|
> alterSequence :: Parser Statement
|
||||||
|
> alterSequence = keyword_ "sequence" >>
|
||||||
|
> AlterSequence
|
||||||
|
> <$> names
|
||||||
|
> <*> sequenceGeneratorOptions
|
||||||
|
|
||||||
|
> dropSequence :: Parser Statement
|
||||||
|
> dropSequence = keyword_ "sequence" >>
|
||||||
|
> DropSequence <$> names <*> dropBehaviour
|
||||||
|
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
= dml
|
= dml
|
||||||
|
|
|
@ -486,17 +486,28 @@ which have been changed to try to improve the layout of the output.
|
||||||
> where
|
> where
|
||||||
> a (ADSetDefault v) = texts ["set","default"] <+> valueExpr d v
|
> a (ADSetDefault v) = texts ["set","default"] <+> valueExpr d v
|
||||||
> a (ADDropDefault) = texts ["drop","default"]
|
> a (ADDropDefault) = texts ["drop","default"]
|
||||||
> a (ADAddConstraint nm e) =
|
> a (ADAddConstraint cnm e) =
|
||||||
> text "add"
|
> text "add"
|
||||||
> <+> maybe empty (\nm' -> text "constraint" <+> names nm') nm
|
> <+> maybe empty (\cnm' -> text "constraint" <+> names cnm') cnm
|
||||||
> <+> text "check" <> parens (valueExpr d e)
|
> <+> text "check" <> parens (valueExpr d e)
|
||||||
> a (ADDropConstraint nm) = texts ["drop", "constraint"]
|
> a (ADDropConstraint cnm) = texts ["drop", "constraint"]
|
||||||
> <+> names nm
|
> <+> names cnm
|
||||||
|
|
||||||
|
|
||||||
> statement _ (DropDomain nm db) =
|
> statement _ (DropDomain nm db) =
|
||||||
> text "drop" <+> text "domain" <+> names nm <+> dropBehav db
|
> text "drop" <+> text "domain" <+> names nm <+> dropBehav db
|
||||||
|
|
||||||
|
> statement _ (CreateSequence nm sgos) =
|
||||||
|
> texts ["create","sequence"] <+> names nm
|
||||||
|
> <+> sep (map sequenceGeneratorOption sgos)
|
||||||
|
|
||||||
|
> statement _ (AlterSequence nm sgos) =
|
||||||
|
> texts ["alter","sequence"] <+> names nm
|
||||||
|
> <+> sep (map sequenceGeneratorOption sgos)
|
||||||
|
|
||||||
|
> statement _ (DropSequence nm db) =
|
||||||
|
> text "drop" <+> text "sequence" <+> names nm <+> dropBehav db
|
||||||
|
|
||||||
== dml
|
== dml
|
||||||
|
|
||||||
> statement d (SelectStatement q) = queryExpr d q
|
> statement d (SelectStatement q) = queryExpr d q
|
||||||
|
@ -581,17 +592,9 @@ which have been changed to try to improve the layout of the output.
|
||||||
> <+> text "as" <+> text "identity"
|
> <+> text "as" <+> text "identity"
|
||||||
> <+> (case o of
|
> <+> (case o of
|
||||||
> [] -> empty
|
> [] -> empty
|
||||||
> os -> parens (sep $ map sgo os))
|
> os -> parens (sep $ map sequenceGeneratorOption os))
|
||||||
> <+> sep (map cdef cons)
|
> <+> sep (map cdef cons)
|
||||||
> where
|
> where
|
||||||
> sgo (SGOStartWith i) = texts ["start", "with", show i]
|
|
||||||
> sgo (SGOIncrementBy i) = texts ["increment", "by", show i]
|
|
||||||
> sgo (SGOMaxValue i) = texts ["maxvalue", show i]
|
|
||||||
> sgo SGONoMaxValue = texts ["no", "maxvalue"]
|
|
||||||
> sgo (SGOMinValue i) = texts ["minvalue", show i]
|
|
||||||
> sgo SGONoMinValue = texts ["no", "minvalue"]
|
|
||||||
> sgo SGOCycle = text "cycle"
|
|
||||||
> sgo SGONoCycle = text "no cycle"
|
|
||||||
> cdef (ColConstraintDef cnm con) =
|
> cdef (ColConstraintDef cnm con) =
|
||||||
> maybe empty (\s -> text "constraint" <+> names s) cnm
|
> maybe empty (\s -> text "constraint" <+> names s) cnm
|
||||||
> <+> pcon con
|
> <+> pcon con
|
||||||
|
@ -607,6 +610,20 @@ which have been changed to try to improve the layout of the output.
|
||||||
> <+> refAct "update" u
|
> <+> refAct "update" u
|
||||||
> <+> refAct "delete" del
|
> <+> refAct "delete" del
|
||||||
|
|
||||||
|
> sequenceGeneratorOption :: SequenceGeneratorOption -> Doc
|
||||||
|
> sequenceGeneratorOption (SGODataType t) =
|
||||||
|
> text "as" <+> typeName t
|
||||||
|
> sequenceGeneratorOption (SGORestart mi) =
|
||||||
|
> text "restart" <+> maybe empty (\mi' -> texts ["with", show mi']) mi
|
||||||
|
> sequenceGeneratorOption (SGOStartWith i) = texts ["start", "with", show i]
|
||||||
|
> sequenceGeneratorOption (SGOIncrementBy i) = texts ["increment", "by", show i]
|
||||||
|
> sequenceGeneratorOption (SGOMaxValue i) = texts ["maxvalue", show i]
|
||||||
|
> sequenceGeneratorOption SGONoMaxValue = texts ["no", "maxvalue"]
|
||||||
|
> sequenceGeneratorOption (SGOMinValue i) = texts ["minvalue", show i]
|
||||||
|
> sequenceGeneratorOption SGONoMinValue = texts ["no", "minvalue"]
|
||||||
|
> sequenceGeneratorOption SGOCycle = text "cycle"
|
||||||
|
> sequenceGeneratorOption SGONoCycle = text "no cycle"
|
||||||
|
|
||||||
> refMatch :: ReferenceMatch -> Doc
|
> refMatch :: ReferenceMatch -> Doc
|
||||||
> refMatch m = case m of
|
> refMatch m = case m of
|
||||||
> DefaultReferenceMatch -> empty
|
> DefaultReferenceMatch -> empty
|
||||||
|
|
|
@ -415,28 +415,32 @@ I'm not sure if this is valid syntax or not.
|
||||||
> [(Maybe [Name], ValueExpr)]
|
> [(Maybe [Name], ValueExpr)]
|
||||||
> | AlterDomain [Name] AlterDomainAction
|
> | AlterDomain [Name] AlterDomainAction
|
||||||
> | DropDomain [Name] DropBehaviour
|
> | DropDomain [Name] DropBehaviour
|
||||||
|
|
||||||
|
> -- probably won't do character sets, collations
|
||||||
|
> -- and translations because I think they are too far from
|
||||||
|
> -- reality
|
||||||
> {- | CreateCharacterSet
|
> {- | CreateCharacterSet
|
||||||
> | DropCharacterSet
|
> | DropCharacterSet
|
||||||
> | CreateCollation
|
> | CreateCollation
|
||||||
> | DropCollation
|
> | DropCollation
|
||||||
> | CreateTranslation
|
> | CreateTranslation
|
||||||
> | DropTranslation
|
> | DropTranslation -}
|
||||||
> | CreateAssertion
|
> {- | CreateAssertion
|
||||||
> | DropAssertion
|
> | DropAssertion
|
||||||
> | CreateTrigger
|
> | CreateTrigger
|
||||||
> | DropTrigger
|
> | DropTrigger
|
||||||
> | CreateType
|
> | CreateType
|
||||||
> | AlterType
|
> | AlterType
|
||||||
> | DropType
|
> | DropType
|
||||||
> -- routine stuff?
|
> -- routine stuff? TODO
|
||||||
> | CreateCast
|
> | CreateCast
|
||||||
> | DropCast
|
> | DropCast
|
||||||
> | CreateOrdering
|
> | CreateOrdering
|
||||||
> | DropOrdering
|
> | DropOrdering -}
|
||||||
> -- transforms
|
> -- transforms
|
||||||
> | CreateSequence
|
> | CreateSequence [Name] [SequenceGeneratorOption]
|
||||||
> | AlterSequence
|
> | AlterSequence [Name] [SequenceGeneratorOption]
|
||||||
> | DropSequence -}
|
> | DropSequence [Name] DropBehaviour
|
||||||
> -- dml
|
> -- dml
|
||||||
> | SelectStatement QueryExpr
|
> | SelectStatement QueryExpr
|
||||||
> {- | DeclareCursor
|
> {- | DeclareCursor
|
||||||
|
@ -611,7 +615,9 @@ I'm not sure if this is valid syntax or not.
|
||||||
> deriving (Eq,Show,Read,Data,Typeable)
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
> data SequenceGeneratorOption =
|
> data SequenceGeneratorOption =
|
||||||
> SGOStartWith Integer
|
> SGODataType TypeName
|
||||||
|
> | SGOStartWith Integer
|
||||||
|
> | SGORestart (Maybe Integer)
|
||||||
> | SGOIncrementBy Integer
|
> | SGOIncrementBy Integer
|
||||||
> | SGOMaxValue Integer
|
> | SGOMaxValue Integer
|
||||||
> | SGONoMaxValue
|
> | SGONoMaxValue
|
||||||
|
|
|
@ -890,6 +890,10 @@ is there no way to do this:
|
||||||
alter table t alter column c set generated as (a * 3)
|
alter table t alter column c set generated as (a * 3)
|
||||||
??
|
??
|
||||||
|
|
||||||
|
UPDATE: alter sequence uses same syntax as create sequence, which is
|
||||||
|
the same sytnax as identity in create table, so overrule the sql
|
||||||
|
standard and use the same syntax in alter identity.
|
||||||
|
|
||||||
PLAN: TODO
|
PLAN: TODO
|
||||||
|
|
||||||
don't implement alter table alter column generated now
|
don't implement alter table alter column generated now
|
||||||
|
@ -1965,6 +1969,23 @@ defintely skip
|
||||||
CYCLE
|
CYCLE
|
||||||
| NO CYCLE
|
| NO CYCLE
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create sequence seq"
|
||||||
|
> $ CreateSequence [Name "seq"] [])
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create sequence seq as bigint"
|
||||||
|
> $ CreateSequence [Name "seq"]
|
||||||
|
> [SGODataType $ TypeName [Name "bigint"]])
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "create sequence seq as bigint start with 5"
|
||||||
|
> $ CreateSequence [Name "seq"]
|
||||||
|
> [SGOStartWith 5
|
||||||
|
> ,SGODataType $ TypeName [Name "bigint"]
|
||||||
|
> ])
|
||||||
|
|
||||||
|
|
||||||
11.73 <alter sequence generator statement>
|
11.73 <alter sequence generator statement>
|
||||||
|
|
||||||
<alter sequence generator statement> ::=
|
<alter sequence generator statement> ::=
|
||||||
|
@ -1983,9 +2004,35 @@ defintely skip
|
||||||
<sequence generator restart value> ::=
|
<sequence generator restart value> ::=
|
||||||
<signed numeric literal>
|
<signed numeric literal>
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "alter sequence seq restart"
|
||||||
|
> $ AlterSequence [Name "seq"]
|
||||||
|
> [SGORestart Nothing])
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "alter sequence seq restart with 5"
|
||||||
|
> $ AlterSequence [Name "seq"]
|
||||||
|
> [SGORestart $ Just 5])
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "alter sequence seq restart with 5 increment by 5"
|
||||||
|
> $ AlterSequence [Name "seq"]
|
||||||
|
> [SGORestart $ Just 5
|
||||||
|
> ,SGOIncrementBy 5])
|
||||||
|
|
||||||
|
|
||||||
11.74 <drop sequence generator statement>
|
11.74 <drop sequence generator statement>
|
||||||
|
|
||||||
<drop sequence generator statement> ::=
|
<drop sequence generator statement> ::=
|
||||||
DROP SEQUENCE <sequence generator name> <drop behavior>
|
DROP SEQUENCE <sequence generator name> <drop behavior>
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "drop sequence seq"
|
||||||
|
> $ DropSequence [Name "seq"] DefaultDropBehaviour)
|
||||||
|
|
||||||
|
> ,(TestStatement SQL2011
|
||||||
|
> "drop sequence seq restrict"
|
||||||
|
> $ DropSequence [Name "seq"] Restrict)
|
||||||
|
|
||||||
|
|
||||||
> ]
|
> ]
|
||||||
|
|
Loading…
Reference in a new issue