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

addBatch doesn't cleanup subquery parameters

    XMLWordPrintable

Details

    Description

          private static final String INSERT_COSMETICS = """
                  INSERT IGNORE INTO cosmetic(name, category)
                  VALUES(?, (SELECT id FROM cosmetic_category WHERE name = ?))
                  """;
       
          public boolean insertCosmetics() throws SQLException {
              try (Connection connection = dataSource.getConnection();
                   PreparedStatement statement = connection.prepareStatement(INSERT_COSMETICS)) {
       
                  for (CosmeticCategory category : CosmeticCategory.CATEGORIES) {
                      for (Cosmetic<?> cosmetic : cosmetics.getRegistrar().getCosmetics(category)) {
                          statement.setString(1, cosmetic.getName());
                          statement.setString(2, category.getName());
                          statement.addBatch();
                      }
                  }
       
                  statement.executeBatch();
                  return true;
              } catch (SQLException e) {
                  throw e;
              }
          }
      

      The following code worked perfectly in the past, but after upgrading to a newer version of the connector, the second variable is not cleaned up after running addBatch. So only the first addBatch correctly sets the second value (category.getName), while all other queries are executed without changing the second parameter, probably because it is inside a subquery? I tested the code without any batch and it worked perfectly.

      Attachments

        Issue Links

          Activity

            People

              diego dupin Diego Dupin
              ytnoos Alessandro
              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.