Skip to content
This repository

Fixed JDatabaseQueryPreparable to support binding output parameters #1163

Merged
merged 1 commit into from about 2 years ago

2 participants

Rob Schley Louis Landry
Rob Schley

When interacting with stored procedures that use output parameters, JDatabaseQueryPreparable would not update the original passed in parameter as expected with the values output from the stored procedure. To solve this, the value is passed by reference so that when it is bound to the query, it can be updated properly with the new value after query execution.

Louis Landry LouisLandry merged commit 4e9dbe3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
3  libraries/joomla/database/driver/sqlite.php
@@ -256,11 +256,12 @@ public function getTableList()
256 256 $query = $this->getQuery(true);
257 257
258 258 $tables = array();
  259 + $type = 'table';
259 260
260 261 $query->select('name');
261 262 $query->from('sqlite_master');
262 263 $query->where('type = :type');
263   - $query->bind(':type', 'table');
  264 + $query->bind(':type', $type);
264 265 $query->order('name');
265 266
266 267 $this->setQuery($query);
38 libraries/joomla/database/query/oracle.php
@@ -37,27 +37,22 @@ class JDatabaseQueryOracle extends JDatabaseQueryPdo implements JDatabaseQueryPr
37 37 protected $bounded = array();
38 38
39 39 /**
40   - * Method to add a variable to an internal $bounded array that
41   - * will later be bound to a prepared SQL statement at the time
42   - * of query execution. Also removes a variable that has been
43   - * bounded from the internal bounded array when the passed in value
44   - * is null.
45   - *
46   - * @param string|integer $key The key that will be used in your SQL
47   - * query to reference the value. Usually
48   - * of the form ':key', but can also be an
49   - * integer.
50   - * @param mixed $value The value that will be bound.
  40 + * Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. Also
  41 + * removes a variable that has been bounded from the internal bounded array when the passed in value is null.
  42 + *
  43 + * @param string|integer $key The key that will be used in your SQL query to reference the value. Usually of
  44 + * the form ':key', but can also be an integer.
  45 + * @param mixed &$value The value that will be bound. The value is passed by reference to support output
  46 + * parameters such as those possible with stored procedures.
51 47 * @param integer $dataType Constant corresponding to a SQL datatype.
52   - * @param integer $length The length of the variable. Usually required
53   - * for OUTPUT variables.
  48 + * @param integer $length The length of the variable. Usually required for OUTPUT parameters.
54 49 * @param array $driverOptions Optional driver options to be used.
55 50 *
56   - * @return JDatabaseQuery
  51 + * @return JDatabaseQuery
57 52 *
58   - * @since 12.1
  53 + * @since 12.1
59 54 */
60   - public function bind($key = null, $value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array())
  55 + public function bind($key = null, &$value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array())
61 56 {
62 57 // Case 1: Empty Key (reset $bounded array)
63 58 if (empty($key))
@@ -91,15 +86,14 @@ public function bind($key = null, $value = null, $dataType = PDO::PARAM_STR, $le
91 86 }
92 87
93 88 /**
94   - * Retrieves the internal $bounded array when key is null and
95   - * returns it by reference. If a key is provided then that
96   - * item is returned from the $bounded array if available.
  89 + * Retrieves the bound parameters array when key is null and returns it by reference. If a key is provided then that item is
  90 + * returned.
97 91 *
98   - * @param mixed $key The bounded variable key to retrieve
  92 + * @param mixed $key The bounded variable key to retrieve.
99 93 *
100   - * @return array|stdClass
  94 + * @return mixed
101 95 *
102   - * @since 12.1
  96 + * @since 12.1
103 97 */
104 98 public function &getBounded($key = null)
105 99 {
32 libraries/joomla/database/query/preparable.php
@@ -22,34 +22,28 @@
22 22 interface JDatabaseQueryPreparable
23 23 {
24 24 /**
25   - * Method to add a variable to an internal $bounded array that
26   - * will later be bound to a prepared SQL statement at the time
27   - * of query execution. Also removes a variable that has been
28   - * bounded from the internal bounded array when the passed in value
29   - * is null.
  25 + * Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. Also
  26 + * removes a variable that has been bounded from the internal bounded array when the passed in value is null.
30 27 *
31   - * @param string|integer $key The key that will be used in your SQL
32   - * query to reference the value. Usually
33   - * of the form ':key', but can also be an
34   - * integer.
35   - * @param mixed $value The value that will be bound.
  28 + * @param string|integer $key The key that will be used in your SQL query to reference the value. Usually of
  29 + * the form ':key', but can also be an integer.
  30 + * @param mixed &$value The value that will be bound. The value is passed by reference to support output
  31 + * parameters such as those possible with stored procedures.
36 32 * @param integer $dataType Constant corresponding to a SQL datatype.
37   - * @param integer $length The length of the variable. Usually required
38   - * for OUTPUT variables.
  33 + * @param integer $length The length of the variable. Usually required for OUTPUT parameters.
39 34 * @param array $driverOptions Optional driver options to be used.
40 35 *
41   - * @return JDatabaseQuery
  36 + * @return JDatabaseQuery
42 37 *
43   - * @since 12.1
  38 + * @since 12.1
44 39 */
45   - public function bind($key = null, $value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array());
  40 + public function bind($key = null, &$value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array());
46 41
47 42 /**
48   - * Retrieves the internal $bounded array when key is null and
49   - * returns it by reference. If a key is provided then that
50   - * item is returned from the $bounded array if available.
  43 + * Retrieves the bound parameters array when key is null and returns it by reference. If a key is provided then that item is
  44 + * returned.
51 45 *
52   - * @param mixed $key The bounded variable key to retrieve
  46 + * @param mixed $key The bounded variable key to retrieve.
53 47 *
54 48 * @return mixed
55 49 *
38 libraries/joomla/database/query/sqlite.php
@@ -37,27 +37,22 @@ class JDatabaseQuerySqlite extends JDatabaseQueryPdo implements JDatabaseQueryPr
37 37 protected $bounded = array();
38 38
39 39 /**
40   - * Method to add a variable to an internal $bounded array that
41   - * will later be bound to a prepared SQL statement at the time
42   - * of query execution. Also removes a variable that has been
43   - * bounded from the internal bounded array when the passed in value
44   - * is null.
45   - *
46   - * @param string|integer $key The key that will be used in your SQL
47   - * query to reference the value. Usually
48   - * of the form ':key', but can also be an
49   - * integer.
50   - * @param mixed $value The value that will be bound.
  40 + * Method to add a variable to an internal array that will be bound to a prepared SQL statement before query execution. Also
  41 + * removes a variable that has been bounded from the internal bounded array when the passed in value is null.
  42 + *
  43 + * @param string|integer $key The key that will be used in your SQL query to reference the value. Usually of
  44 + * the form ':key', but can also be an integer.
  45 + * @param mixed &$value The value that will be bound. The value is passed by reference to support output
  46 + * parameters such as those possible with stored procedures.
51 47 * @param integer $dataType Constant corresponding to a SQL datatype.
52   - * @param integer $length The length of the variable. Usually required
53   - * for OUTPUT variables.
  48 + * @param integer $length The length of the variable. Usually required for OUTPUT parameters.
54 49 * @param array $driverOptions Optional driver options to be used.
55 50 *
56   - * @return JDatabaseQuery
  51 + * @return JDatabaseQuery
57 52 *
58   - * @since 12.1
  53 + * @since 12.1
59 54 */
60   - public function bind($key = null, $value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array())
  55 + public function bind($key = null, &$value = null, $dataType = PDO::PARAM_STR, $length = 0, $driverOptions = array())
61 56 {
62 57 // Case 1: Empty Key (reset $bounded array)
63 58 if (empty($key))
@@ -91,15 +86,14 @@ public function bind($key = null, $value = null, $dataType = PDO::PARAM_STR, $le
91 86 }
92 87
93 88 /**
94   - * Retrieves the internal $bounded array when key is null and
95   - * returns it by reference. If a key is provided then that
96   - * item is returned from the $bounded array if available.
  89 + * Retrieves the bound parameters array when key is null and returns it by reference. If a key is provided then that item is
  90 + * returned.
97 91 *
98   - * @param mixed $key The bounded variable key to retrieve
  92 + * @param mixed $key The bounded variable key to retrieve.
99 93 *
100   - * @return array|stdClass
  94 + * @return mixed
101 95 *
102   - * @since 12.1
  96 + * @since 12.1
103 97 */
104 98 public function &getBounded($key = null)
105 99 {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.