-
Bug
-
Resolution: Fixed
-
Major
-
3.2.2
-
PHP 7.0.27-0+deb9u1 (Debian-Linux)
Browser: Not relevant
Database MariaDB 10.1.26-MariaDB-0+deb9u1
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.