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

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

    XMLWordPrintable

Details

    • Improvement
    • Status: Unverified Fix (View Workflow)
    • Major
    • Resolution: Fixed
    • 3.1.0-dev
    • 3.1.0-a1
    • None
    • 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

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

              Dates

                Created:
                Updated:
                Resolved: