Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-15520

DbDriver->sql_build_query cant cope with sub-selects

    XMLWordPrintable

Details

    Description

      phpbb\db\driver\driver is not able to build subqueries. The following code

      $sql = $this->db->sql_build_query('SELECT', array(
           'SELECT'    => 'group_id,user_id',
           'FROM'        => array(USER_GROUP_TABLE => 'ug'),
           'WHERE'        => array('AND', array(
               array('user_id', 'NOT IN', '', 'SELECT', array(
                   'SELECT'    => 'user_id',
                   'FROM'        => array(USERS_TABLE => 'u'),
               )),
           )),
           'ORDER_BY'    => 'user_id,group_id',
       ));

      gives the following statement:

      SELECT group_id,user_id FROM (forum1_user_group ug) WHERE user_id NOT IN SELECT ( ) ORDER BY user_id,group_id

      The Sub-Select-Statement is missing.

      (The code above is just a simplified / changed exmaple for easier testing.)

       

      The reason for that is driver::_process_boolean_tree :

            $condition = $condition[self::LEFT_STMT] . ' ' . $condition[self::COMPARE_OP] . ' ' . $condition[self::SUBQUERY_OP] . ' ( ';
            $condition .= $this->sql_build_query($condition[self::SUBQUERY_SELECT_TYPE], $condition[self::SUBQUERY_BUILD]);
            $condition .= ' )';

       

      The first line modifies the condition-array to a string. When the second line tries to read array values, it instead access specific characters of the string that the first line wrote to $condition.

       

      Attachments

        Activity

          People

            Marc Marc
            Neoran Neoran [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: