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

result_metadata()->fetch_fields() returns incorrect orgname and orgtable for select statements with subquery in FROM clause

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Incomplete
    • 5.5.64, 10.3.22
    • N/A
    • Server
    • CentOS Linux release 7.7.1908
      PHP 7.3.16

    Description

      The statement metadata does not correctly identify the underlying table and column. This is a regression vs e.g. MySQL 5.1.73.

      This behavior has been reproduced in several server environments and also with the mariadb client for nodejs.

      Impact: Cannot determine application-level metadata and security attributes for the tables and columns queried.

      Repro (PHP):

      <?php
       
      /*
       * connect parameters
       */
      $host = 'localhost';
      $id = 'holson';
      $pwd = 'xxxxxxxx';
      $dbname = 'alias';
       
      /*
       * connect
       */
      $link = @mysqli_connect($host, $id, $pwd);
      if ($link === false) {
          echo 'unable to connect to database - incorrect connect parametsrs?' . PHP_EOL;
          exit(1);
      }
      mysqli_select_db($link, $dbname);
       
      /*
       * prepare database
       */
      $ddl = "drop table if exists Site";
      $r = mysqli_query($link, $ddl);
      $ddl = "create table Site (Name varchar(50))";
      $r = mysqli_query($link, $ddl);
       
      /*
       * execute test case
       */
      $sql="
          select
              SiteName
          from (select Name as SiteName from Site) as s
      ";
      echo 'DDL: ' . $ddl . PHP_EOL;
      echo 'SQL: ' . $sql . PHP_EOL;
      echo 'Expect: orgname => Name, orgtable => Site'. PHP_EOL;
      $stmt = mysqli_prepare($link, $sql);
      $fields = $stmt->result_metadata()->fetch_fields();
      echo 'Result ( $stmt->result_metadata()->fetch_fields() ): ';
      print_r($fields);
       
      ?>
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            Henry Olson Henry Olson
            Votes:
            0 Vote for this issue
            Watchers:
            4 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.