Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import net.sf.jsqlparser.expression.ExpressionVisitor;
import net.sf.jsqlparser.expression.ExpressionVisitorAdapter;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.NextValExpression;
import net.sf.jsqlparser.expression.TranscodingFunction;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.alter.AlterExpression;
import net.sf.jsqlparser.statement.alter.AlterOperation;
Expand Down Expand Up @@ -1359,6 +1361,22 @@ public <S> Void visit(TranscodingFunction expression, S context) {
analyseFunction(expression.getKeyword());
return super.visit(expression, context);
}

/** NEXT VALUE FOR s advances the sequence, like nextval('s'). */
@Override
public <S> Void visit(NextValExpression nextVal, S context) {
analyseFunction("nextval");
return super.visit(nextVal, context);
}

/** So does Oracle's s.NEXTVAL, which the grammar keeps as a column. */
@Override
public <S> Void visit(Column column, S context) {
if (column.getTable() != null && "nextval".equalsIgnoreCase(column.getColumnName())) {
analyseFunction("nextval");
}
return super.visit(column, context);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,28 @@ void nestedWriteIsSeen(String sql) throws JSQLParserException {
assertThat(f.returnsResultSet()).isTrue();
}

@ParameterizedTest(name = "{0}")
@ValueSource(strings = {
"SELECT NEXT VALUE FOR s",
"SELECT NEXTVAL FOR s",
"SELECT NEXT VALUE FOR dbo.s FROM t",
"SELECT a FROM t WHERE a = NEXT VALUE FOR s",
"SELECT s.NEXTVAL FROM dual",
"SELECT a FROM t WHERE a = (SELECT s.nextval FROM dual)"})
void sequenceAdvanceIsChecked(String sql) throws JSQLParserException {
StatementFeatures f = analyse(sql);
assertThat(f.returnsResultSet()).isTrue();
assertThat(f.mayModifyData()).isTrue();
assertThat(f.getUnresolvedReferences()).containsExactly("nextval");
}

@Test
void columnOutsideTheSequenceSyntaxIsNotChecked() throws JSQLParserException {
StatementFeatures f = analyse("SELECT nextval, t.currval FROM t");
assertThat(f.mayModifyData()).isFalse();
assertThat(f.getUnresolvedReferences()).isEmpty();
}

@Test
void topLevelValuesReturnsRowsWithoutReading() throws JSQLParserException {
StatementFeatures f = analyse("VALUES (1, 2)");
Expand Down
Loading