Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-10484

Use variables for sql_build_query() calls, so mods/extensions can extend the arrays

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • 3.1.0-a1
    • 3.1.0-dev
    • None
    • None

      The function is nice and allows easier MOD injections, but currently the array is mostly added directly inside the function call, so it can not be easily modified.

      Example from viewtopic.php
      current:

      $sql = $db->sql_build_query('SELECT', array(
      	'SELECT'	=> 'u.*, z.friend, z.foe, p.*',
      	'FROM'		=> array(
      		USERS_TABLE		=> 'u',
      		POSTS_TABLE		=> 'p',
      	),
      	'LEFT_JOIN'	=> array(
      		array(
      			'FROM'	=> array(ZEBRA_TABLE => 'z'),
      			'ON'	=> 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id'
      		)
      	),
      	'WHERE'		=> $db->sql_in_set('p.post_id', $post_list) . '
      		AND u.user_id = p.poster_id'
      ));

      a MOD that wants to add its tables to the query needs to be inserted into the array by inline editing.

      When the code would be:

      $sql_ary = array(
      	'SELECT'	=> 'u.*, z.friend, z.foe, p.*',
      	'FROM'		=> array(
      		USERS_TABLE		=> 'u',
      		POSTS_TABLE		=> 'p',
      	),
      	'LEFT_JOIN'	=> array(
      		array(
      			'FROM'	=> array(ZEBRA_TABLE => 'z'),
      			'ON'	=> 'z.user_id = ' . $user->data['user_id'] . ' AND z.zebra_id = p.poster_id'
      		),
      	),
      	'WHERE'		=> $db->sql_in_set('p.post_id', $post_list) . '
      		AND u.user_id = p.poster_id',
      );
      $sql = $db->sql_build_query('SELECT', $sql_ary);

      The MOD can simply add a $sql_ary['LEFT_JOIN'][] = mod_extend_array(); before the $sql = $db->sql_build_query('SELECT', $sql_ary);

            nickvergessen Joas Schilling
            nickvergessen Joas Schilling
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: