Skip to content

Commit

Permalink
Add stripslashes to mssql result columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Narloch committed Jan 9, 2017
1 parent 5d08c45 commit f7d2d04
Showing 1 changed file with 45 additions and 36 deletions.
81 changes: 45 additions & 36 deletions libraries/joomla/database/driver/sqlsrv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit f7d2d04

Please sign in to comment.