The Parser doubles params for stored procedures in v.2.0.206

65 views
Skip to first unread message

Artem Bilan

unread,
Jan 12, 2022, 2:05:17 PM1/12/22
to H2 Database
Hi there!

Having issues with stored procedures in new H2 version.
This is the code to reproduce:

import java.math.BigInteger;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;

import org.h2.tools.SimpleResultSet;
import org.junit.Test;

public class H2StoredProcTests {


@Test
public void h2ParserProblem() throws SQLException {
try (Connection connection =
DriverManager.getConnection("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=true", "sa", "")) {
try (Statement statement = connection.createStatement()) {
statement.execute("CREATE ALIAS GET_PRIME_NUMBERS FOR \"H2StoredProcTests.getPrimes\"");
}
try (CallableStatement callableStatement = connection.prepareCall("{ CALL GET_PRIME_NUMBERS(?, ?) }")) {
callableStatement.setInt(1, 0);
callableStatement.setInt(2, 10);
callableStatement.execute();
}
}
}

public static ResultSet getPrimes(int beginRange, int endRange) {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("PRIME", Types.INTEGER, 10, 0);
for (int i = beginRange; i <= endRange; i++) {
if (new BigInteger(String.valueOf(i)).isProbablePrime(100)) {
rs.addRow(i);
}
}

return rs;
}

}

Works well in the previous 1.4.200 version.

Looks like something has been broken in the org.h2.command.Parser and now it parsers params twice:

Params_screenshot.PNG

The failure in the end looks like this:

org.h2.jdbc.JdbcSQLDataException:
Parameter "#3" is not set; SQL statement:
  CALL GET_PRIME_NUMBERS(?, ?)   [90012-206]

        at org.h2.message.DbException.getJdbcSQLException(DbException.java:665)
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:496)
        at org.h2.message.DbException.get(DbException.java:227)
        at org.h2.message.DbException.get(DbException.java:203)
        at org.h2.expression.Parameter.checkSet(Parameter.java:75)
        at org.h2.command.Prepared.checkParameters(Prepared.java:181)
        at org.h2.command.CommandContainer.query(CommandContainer.java:254)
        at org.h2.command.Command.executeQuery(Command.java:190)
        at org.h2.jdbc.JdbcPreparedStatement.execute(JdbcPreparedStatement.java:248)
        at H2StoredProcTests.h2ParserProblem(H2StoredProcTests.java:26)

Thank you!

Regards,
Artem Bilan

Andrei Tokar

unread,
Jan 12, 2022, 2:25:45 PM1/12/22
to H2 Database
This issue and possible workarounds are described  here and addressed by this  PR.
Fix will be included in the nex H2 release.
Reply all
Reply to author
Forward
0 new messages