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

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

    Details

    • Type: Improvement
    • Status: Unverified Fix
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.0-dev
    • Fix Version/s: 3.1.0-a1
    • Component/s: None
    • Labels:
      None

      Description

      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);

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: