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

Error in stored procedure or SQL statement with allowMultiQueries does not raise Exception when there is a result returned prior to erroneous statement

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.3.0, 1.3.6
    • 1.3.7
    • Other
    • None
    • MariaDB 10.0.19

    Description

      Scenario 1:
      Stored procedure:

      DELIMITER $$
      CREATE PROCEDURE `TEST_SP1`()
      BEGIN

      SELECT @Something := 'Something'; – this statement triggers the issue

      SIGNAL SQLSTATE '70100'
      SET MESSAGE_TEXT = 'Test error from SP';
      END

      Java code:
      Connection conn = null;
      try{
      conn =
      DriverManager.getConnection("jdbc:mysql://<server>/<Database>?" +
      "user=<user>&password=<pwd>");
      CallableStatement cStmt = conn.prepareCall("

      {call TEST_SP1()}

      ");
      boolean success = cStmt.execute();
      System.out.println("Successful");
      } catch (Exception ex)

      { System.out.println("Exception caught: " + ex.toString()); throw ex; }

      finally

      { conn.close(); }

      Expected:
      Exception is raised

      Actual:
      Call returns successfully, execute() method returns true


      Scenario 2:
      Connection conn = null;
      try{ conn = DriverManager.getConnection("jdbc:mysql://<server>/<Database>?" + "user=<user>&password=<pwd>&allowMultiQueries=true"); PreparedStatement stmt = conn.prepareStatement("SELECT 1; INSERT INTO TEST_TBL ;"); stmt.execute(); System.out.println("Successful"); } catch (Exception ex) { System.out.println("Exception caught: " + ex.toString()); throw ex; } finally { conn.close(); }

      Expected:
      Syntax error in Insert statement.

      Actual:
      Successful. if I remove the "SELECT 1; " prior to Insert statement, it does throw java.sql.SQLSyntaxErrorException

      Attachments

        Activity

          snarra Sridevi Narra created issue -
          snarra Sridevi Narra made changes -
          Field Original Value New Value
          Description Stored procedure:

          DELIMITER $$
          CREATE PROCEDURE `TEST_SP1`()
          BEGIN

              SELECT @Something := 'Something'; -- this statement triggers the issue
              
             SIGNAL SQLSTATE '70100'
               SET MESSAGE_TEXT = 'Test error from SP';
          END

          Java code:
          Connection conn = null;
          try{
          conn =
          DriverManager.getConnection("jdbc:mysql://&lt;server&gt;/&lt;Database&gt;?" +
          "user=<user>&password=<pwd>");
          CallableStatement cStmt = conn.prepareCall("{call TEST_SP1()}");
          boolean success = cStmt.execute();
          System.out.println("Successful");
          } catch (Exception ex) {
          System.out.println("Exception caught: " + ex.toString());
          throw ex;
          } finally {
          conn.close();
          }

          Expected:
          Exception is raised

          Actual:
          Call returns successfully, execute() method returns true
          MariaDB Version:
          Stored procedure:

          DELIMITER $$
          CREATE PROCEDURE `TEST_SP1`()
          BEGIN

              SELECT @Something := 'Something'; -- this statement triggers the issue
              
             SIGNAL SQLSTATE '70100'
               SET MESSAGE_TEXT = 'Test error from SP';
          END

          Java code:
          Connection conn = null;
          try{
          conn =
          DriverManager.getConnection("jdbc:mysql://&lt;server&gt;/&lt;Database&gt;?" +
          "user=<user>&password=<pwd>");
          CallableStatement cStmt = conn.prepareCall("{call TEST_SP1()}");
          boolean success = cStmt.execute();
          System.out.println("Successful");
          } catch (Exception ex) {
          System.out.println("Exception caught: " + ex.toString());
          throw ex;
          } finally {
          conn.close();
          }

          Expected:
          Exception is raised

          Actual:
          Call returns successfully, execute() method returns true
          snarra Sridevi Narra made changes -
          Affects Version/s 1.3.6 [ 21700 ]
          Description MariaDB Version:
          Stored procedure:

          DELIMITER $$
          CREATE PROCEDURE `TEST_SP1`()
          BEGIN

              SELECT @Something := 'Something'; -- this statement triggers the issue
              
             SIGNAL SQLSTATE '70100'
               SET MESSAGE_TEXT = 'Test error from SP';
          END

          Java code:
          Connection conn = null;
          try{
          conn =
          DriverManager.getConnection("jdbc:mysql://&lt;server&gt;/&lt;Database&gt;?" +
          "user=<user>&password=<pwd>");
          CallableStatement cStmt = conn.prepareCall("{call TEST_SP1()}");
          boolean success = cStmt.execute();
          System.out.println("Successful");
          } catch (Exception ex) {
          System.out.println("Exception caught: " + ex.toString());
          throw ex;
          } finally {
          conn.close();
          }

          Expected:
          Exception is raised

          Actual:
          Call returns successfully, execute() method returns true
          Stored procedure:

          DELIMITER $$
          CREATE PROCEDURE `TEST_SP1`()
          BEGIN

              SELECT @Something := 'Something'; -- this statement triggers the issue
              
             SIGNAL SQLSTATE '70100'
               SET MESSAGE_TEXT = 'Test error from SP';
          END

          Java code:
          Connection conn = null;
          try{
          conn =
          DriverManager.getConnection("jdbc:mysql://&lt;server&gt;/&lt;Database&gt;?" +
          "user=<user>&password=<pwd>");
          CallableStatement cStmt = conn.prepareCall("{call TEST_SP1()}");
          boolean success = cStmt.execute();
          System.out.println("Successful");
          } catch (Exception ex) {
          System.out.println("Exception caught: " + ex.toString());
          throw ex;
          } finally {
          conn.close();
          }

          Expected:
          Exception is raised

          Actual:
          Call returns successfully, execute() method returns true
          Environment MariaDB 10.0.19
          snarra Sridevi Narra made changes -
          Description Stored procedure:

          DELIMITER $$
          CREATE PROCEDURE `TEST_SP1`()
          BEGIN

              SELECT @Something := 'Something'; -- this statement triggers the issue
              
             SIGNAL SQLSTATE '70100'
               SET MESSAGE_TEXT = 'Test error from SP';
          END

          Java code:
          Connection conn = null;
          try{
          conn =
          DriverManager.getConnection("jdbc:mysql://&lt;server&gt;/&lt;Database&gt;?" +
          "user=<user>&password=<pwd>");
          CallableStatement cStmt = conn.prepareCall("{call TEST_SP1()}");
          boolean success = cStmt.execute();
          System.out.println("Successful");
          } catch (Exception ex) {
          System.out.println("Exception caught: " + ex.toString());
          throw ex;
          } finally {
          conn.close();
          }

          Expected:
          Exception is raised

          Actual:
          Call returns successfully, execute() method returns true
          Scenario 1:
          Stored procedure:

          DELIMITER $$
          CREATE PROCEDURE `TEST_SP1`()
          BEGIN

              SELECT @Something := 'Something'; -- this statement triggers the issue
              
             SIGNAL SQLSTATE '70100'
               SET MESSAGE_TEXT = 'Test error from SP';
          END

          Java code:
          Connection conn = null;
          try{
          conn =
          DriverManager.getConnection("jdbc:mysql://&lt;server&gt;/&lt;Database&gt;?" +
          "user=<user>&password=<pwd>");
          CallableStatement cStmt = conn.prepareCall("{call TEST_SP1()}");
          boolean success = cStmt.execute();
          System.out.println("Successful");
          } catch (Exception ex) {
          System.out.println("Exception caught: " + ex.toString());
          throw ex;
          } finally {
          conn.close();
          }

          Expected:
          Exception is raised

          Actual:
          Call returns successfully, execute() method returns true


          Scenario 2:
          Connection conn = null;
          try{
          conn =
          DriverManager.getConnection("jdbc:mysql://&lt;server&gt;/&lt;Database&gt;?" +
          "user=<user>&password=<pwd>&allowMultiQueries=true");
          PreparedStatement stmt = conn.prepareStatement("SELECT 1; INSERT INTO TEST_TBL ;");
          stmt.execute();
          System.out.println("Successful");
          } catch (Exception ex) {
          System.out.println("Exception caught: " + ex.toString());
          throw ex;
          } finally {
          conn.close();
          }

          Expected:
          Syntax error in Insert statement.

          Actual:
          Successful. if I remove the "SELECT 1; " prior to Insert statement, it does throw java.sql.SQLSyntaxErrorException
          Summary Error in stored procedure does not raise Exception when there is a result returned Error in stored procedure or SQL statement with allowMultiQueries does not raise Exception when there is a result returned
          snarra Sridevi Narra made changes -
          Summary Error in stored procedure or SQL statement with allowMultiQueries does not raise Exception when there is a result returned Error in stored procedure or SQL statement with allowMultiQueries does not raise Exception when there is a result returned prior to errorneous statement
          snarra Sridevi Narra made changes -
          Summary Error in stored procedure or SQL statement with allowMultiQueries does not raise Exception when there is a result returned prior to errorneous statement Error in stored procedure or SQL statement with allowMultiQueries does not raise Exception when there is a result returned prior to erroneous statement
          snarra Sridevi Narra made changes -
          Affects Version/s 1.3.0 [ 19602 ]
          diego dupin Diego Dupin added a comment -

          Good remark.

          Exceptions must be thrown immediatly when there is exception in multiple queries.

          Commit : https://github.com/MariaDB/mariadb-connector-j/commit/c02b37914c4d15e43f24f2ce4af7064bc9e9da7d

          diego dupin Diego Dupin added a comment - Good remark. Exceptions must be thrown immediatly when there is exception in multiple queries. Commit : https://github.com/MariaDB/mariadb-connector-j/commit/c02b37914c4d15e43f24f2ce4af7064bc9e9da7d
          diego dupin Diego Dupin made changes -
          Component/s Other [ 12201 ]
          Fix Version/s 1.3.7 [ 21800 ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 74456 ] MariaDB v4 [ 134846 ]

          People

            diego dupin Diego Dupin
            snarra Sridevi Narra
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.