Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-1069

DatabaseMetaData#getProcedureColumns reports incorrect data after executing a stored procedure

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 2.7.2, 3.1.0
    • N/A
    • stored procedure
    • None
    • mac, mariadb server 10.6.9, java 8, used dbeaver to create/replace the stored procedures

    Description

      Noteworthy:

      1. This repro exhibits a problem found in mariadb jdbc driver 2.7 and 3.1.
      2. Interestingly, using the mysql driver did not exhibit this problem.
      3. The mariadb jdbc driver code pulls from information_schema.parameters to implement #getProcedureColumns. However, if you query this table via DBeaver (or other client), it does in fact show the correct number of parameters/columns.

      REPRO:

      1) Create a stored procedure with two parameters:

      delimiter //
      create or replace procedure test(p1 int, p2 int)
      BEGIN
      select p1 as 'p1';
      END
      //
      

      2. In the java code (found down below) replace the jdbcUrl, userName, password, and spName (e.g., value = test) variables and then run the application. The application will execute the stored procedure then call getProcedureColumns in a loop forever. Observe that it reports the correct number of stored procedure parameters parameters/columns (in this case, 2).

      3. Remove one of the parameters of the stored procedure and then replace the procedure of step 1.

      delimiter //
      create or replace procedure test(p1 int)
      BEGIN
      select p1 as 'p1';
      END
      //
      

      4.
      EXPECTATION: that as soon as you perform step 3, the app reports 1 parameter.
      ACTUAL: after performing step 3, the app continues to report 2 parameters.

      -----------

      Repro java application of step 2:

      import java.sql.*;
       
      public class GetProcedureColumnsRepro {
        public static void execute() throws SQLException {
          String jdbcUrl = "jdbc:mariadb://localhost:3306/YOURDB";
      //    String jdbcUrl = "jdbc:mysql://localhost:3306/YOURDB";
          String userName = "yourusername";
          String password = "yourpassword";
          String spName = "yourstoredprocedurename";
       
          try (Connection conn = DriverManager.getConnection(jdbcUrl, userName, password)) {
            System.out.println("---");
            DatabaseMetaData databaseMetaData = conn.getMetaData();
       
            // EXECUTE A STORED PROCEDURE
            try (CallableStatement call = conn.prepareCall("{call " + spName + "(?, ?)}")) {
              call.setQueryTimeout(0);
              call.setObject(1, 1);
              call.setObject(2, 2);
              call.execute();
            } catch (Exception e) {
              System.out.println("Should not have encountered error here. Make sure the procedure was created before starting the repro: " + e.getMessage());
              throw e;
            }
       
            // LOOP FOREVER, REPORTING THE PROCEDURE'S PARAMETERS
            while (true) {
              try (ResultSet rs = databaseMetaData.getProcedureColumns(null, null, spName, null)) {
                String columns = "";
                while (rs.next()) {
                  columns += rs.getString("COLUMN_NAME") + ",";
                }
                System.out.println("GetProcedureColumns found: " + columns);
              }
            }
          } catch (Exception e) {
            System.out.println("e: " + e.getMessage());
          }
        }
      }
      
      

      Attachments

        Issue Links

          Activity

            People

              diego dupin Diego Dupin
              julianbui Julian Bui
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.