diff --git a/libraries/joomla/database/driver/sqlsrv.php b/libraries/joomla/database/driver/sqlsrv.php index cadf3742bab59..a73f4b1da0a62 100644 --- a/libraries/joomla/database/driver/sqlsrv.php +++ b/libraries/joomla/database/driver/sqlsrv.php @@ -543,39 +543,6 @@ public function insertid() return (int) $this->loadResult(); } - /** - * Method to get the first field of the first row of the result set from the database query. - * - * @return mixed The return value or null if the query failed. - * - * @since 12.1 - * @throws RuntimeException - */ - public function loadResult() - { - $ret = null; - - // Execute the query and get the result set cursor. - if (!($cursor = $this->execute())) - { - return; - } - - // Get the first row from the result set as an array. - if ($row = sqlsrv_fetch_array($cursor, SQLSRV_FETCH_NUMERIC)) - { - $ret = $row[0]; - } - - // Free up system resources and return. - $this->freeResult($cursor); - - // For SQLServer - we need to strip slashes - $ret = stripslashes($ret); - - return $ret; - } - /** * Execute the SQL statement. * @@ -942,7 +909,21 @@ public function transactionStart($asSavepoint = false) */ protected function fetchArray($cursor = null) { - return sqlsrv_fetch_array($cursor ? $cursor : $this->cursor, SQLSRV_FETCH_NUMERIC); + $row = sqlsrv_fetch_array($cursor ? $cursor : $this->cursor, SQLSRV_FETCH_NUMERIC); + + if (is_array($row)) + { + // For SQLServer - we need to strip slashes + foreach ($row as &$value) + { + if ($value !== null) + { + $value = stripslashes($value); + } + } + } + + return $row; } /** @@ -956,7 +937,21 @@ protected function fetchArray($cursor = null) */ protected function fetchAssoc($cursor = null) { - return sqlsrv_fetch_array($cursor ? $cursor : $this->cursor, SQLSRV_FETCH_ASSOC); + $row = sqlsrv_fetch_array($cursor ? $cursor : $this->cursor, SQLSRV_FETCH_ASSOC); + + if (is_array($row)) + { + // For SQLServer - we need to strip slashes + foreach ($row as &$value) + { + if ($value !== null) + { + $value = stripslashes($value); + } + } + } + + return $row; } /** @@ -971,7 +966,21 @@ protected function fetchAssoc($cursor = null) */ protected function fetchObject($cursor = null, $class = 'stdClass') { - return sqlsrv_fetch_object($cursor ? $cursor : $this->cursor, $class); + $row = sqlsrv_fetch_object($cursor ? $cursor : $this->cursor, $class); + + if (is_object($row)) + { + // For SQLServer - we need to strip slashes + foreach (get_object_vars($row) as $key => $value) + { + if ($value !== null) + { + $row->$key = stripslashes($value); + } + } + } + + return $row; } /**