Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/net/sf/jsqlparser/schema/Sequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Sequence addParameters(Collection<? extends Parameter> parameters) {
* The available parameters to a sequence
*/
public enum ParameterType {
INCREMENT_BY, START_WITH, RESTART_WITH, MAXVALUE, NOMAXVALUE, MINVALUE, NOMINVALUE, CYCLE, NOCYCLE, CACHE, NOCACHE, ORDER, NOORDER, KEEP, NOKEEP, SESSION, GLOBAL;
INCREMENT_BY, INCREMENT, START_WITH, START, RESTART_WITH, MAXVALUE, NOMAXVALUE, MINVALUE, NOMINVALUE, CYCLE, NOCYCLE, CACHE, NOCACHE, ORDER, NOORDER, KEEP, NOKEEP, SESSION, GLOBAL;

public static ParameterType from(String type) {
return Enum.valueOf(ParameterType.class, type.toUpperCase());
Expand Down Expand Up @@ -189,8 +189,12 @@ public String formatParameter() {
switch (option) {
case INCREMENT_BY:
return prefix("INCREMENT BY");
case INCREMENT:
return prefix("INCREMENT");
case START_WITH:
return prefix("START WITH");
case START:
return prefix("START");
case RESTART_WITH:
if (value != null) {
return prefix("RESTART WITH");
Expand Down
18 changes: 14 additions & 4 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -10209,23 +10209,33 @@ List<Sequence.Parameter> SequenceParameters():
List<Sequence.Parameter> sequenceParameters = new ArrayList<Sequence.Parameter>();
Sequence.Parameter parameter = null;
Token token = null;
Token byToken = null;
Token withToken = null;
}
{
(
LOOKAHEAD(2) (
(
<K_INCREMENT> <K_BY> token=<S_LONG>
<K_INCREMENT> [ byToken=<K_BY> ] token=<S_LONG>
{
parameter = new Sequence.Parameter(Sequence.ParameterType.INCREMENT_BY);
if (byToken != null) {
parameter = new Sequence.Parameter(Sequence.ParameterType.INCREMENT_BY);
} else {
parameter = new Sequence.Parameter(Sequence.ParameterType.INCREMENT);
}
parameter.setValue(Long.parseLong(token.image));
sequenceParameters.add(parameter);
}
)
|
(
<K_START> <K_WITH> token=<S_LONG>
<K_START> [ withToken=<K_WITH> ] token=<S_LONG>
{
parameter = new Sequence.Parameter(Sequence.ParameterType.START_WITH);
if (withToken != null) {
parameter = new Sequence.Parameter(Sequence.ParameterType.START_WITH);
} else {
parameter = new Sequence.Parameter(Sequence.ParameterType.START);
}
parameter.setValue(Long.parseLong(token.image));
sequenceParameters.add(parameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ public void testCreateSequence_withIncrement() throws JSQLParserException {
statement);
}

@Test
public void testCreateSequence_withIncrementPostres() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE db.schema.my_seq INCREMENT 1");
}

@Test
public void testCreateSequence_withStart() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq START WITH 10");
}

@Test
public void testCreateSequence_withStartPostgres() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq START 10");
}

@Test
public void testCreateSequence_withMaxValue() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq MAXVALUE 5");
Expand Down