Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-23341

shadowed field wrong column name metadata

    XMLWordPrintable

Details

    Description

      Some shadowed field return alias name in place of column name. (This is only since 10.4)
      Connector then return an exception when using column name to retrieve data.

      To reproduced :

       
          try (Connection con = DriverManager.getConnection("jdbc:mariadb://localhost:3306/testj?user=root&log")) {
            Statement stmt = con.createStatement();
            stmt.execute("CREATE TABLE IF NOT EXISTS foo_outer (original_id varchar(100), key_p2 DATETIME, some_value text, PRIMARY KEY (original_id, key_p2))");
            stmt.execute("INSERT IGNORE INTO foo_outer (original_id, key_p2, some_value) VALUES ('oid_a', '2020-06-01 00:00', 'some_value_a')");
            stmt.execute("CREATE TABLE IF NOT EXISTS foo_inner (original_id varchar(100), other_id varchar(100), PRIMARY KEY (original_id, other_id))");
            stmt.execute("INSERT IGNORE INTO foo_inner (original_id, other_id) VALUES ('oid_a', 'otherid_1')");
            stmt.execute("INSERT IGNORE INTO foo_inner (original_id, other_id) VALUES ('oid_b', 'otherid_1')");
       
            ResultSet r = stmt.executeQuery("SELECT original_id AS alt_id, key_p2 as p2, some_value "
                + "FROM foo_outer "
                + "WHERE original_id IN ("
                + "SELECT DISTINCT(inner1.original_id) "
                + "FROM foo_inner AS inner1 "
                + "RIGHT JOIN foo_inner AS inner2 ON inner1.other_id = inner2.other_id "
                + "WHERE inner1.original_id = 'oid_a'"
                + ") ORDER BY key_p2");
            while (r.next()) {
              // will throw an error, since column name meta return alt_id
              ResultSetMetaData meta = r.getMetaData();
              System.out.println(meta.getColumnLabel(1)); // return alt_id, as expected
              System.out.println(meta.getColumnName(1)); // return alt_id, not original_id
       
              r.getString("original_id"); // will throw an exception
            }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
      

      same code without order by work without issue.

      metadata is wrong :

      +--------------------------------------------------+
      |  0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f |
      +--------------------------------------------------+------------------+
      | 39 00 00 02 03 64 65 66  05 74 65 73 74 6A 09 66 | 9....def.testj.f |
      | 6F 6F 5F 6F 75 74 65 72  09 66 6F 6F 5F 6F 75 74 | oo_outer.foo_out |
      | 65 72 06 61 6C 74 5F 69  64 06 61 6C 74 5F 69 64 | er.alt_id.alt_id |
      | 0C E0 00 90 01 00 00 FD  01 10 00 00 00          | .............    |
      +--------------------------------------------------+------------------+
      

      with 10.3, no problem, original_id is returned as column name :

      +--------------------------------------------------+
      |  0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f |
      +--------------------------------------------------+------------------+
      | 3E 00 00 02 03 64 65 66  05 74 65 73 74 6A 09 66 | >....def.testj.f |
      | 6F 6F 5F 6F 75 74 65 72  09 66 6F 6F 5F 6F 75 74 | oo_outer.foo_out |
      | 65 72 06 61 6C 74 5F 69  64 0B 6F 72 69 67 69 6E | er.alt_id.origin |
      | 61 6C 5F 69 64 0C 2D 00  90 01 00 00 FD 01 10 00 | al_id.-......... |
      | 00 00                                            | ..               |
      +--------------------------------------------------+------------------+
      
      

      Attachments

        1. version.c
          2 kB
        2. MDEV-23519.patch
          3 kB
        3. MDEV-23341.patch
          3 kB

        Issue Links

          Activity

            People

              diego dupin Diego Dupin
              diego dupin Diego Dupin
              Votes:
              4 Vote for this issue
              Watchers:
              10 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.