Commit 3798c105 authored by Gary Leydon's avatar Gary Leydon Committed by Robert Lyon

Bug 1499572: Avoid array to string conversion in ADODB errors

behatnotneeded: error appears in error log

Change-Id: Ic816248ee56bcae7daa1f13c768afdab92c95b23
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent ef64adaa
......@@ -31,6 +31,8 @@ if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_H
function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)
{
if (error_reporting() == 0) return; // obey @ protocol
$p1 = is_array($p1) ? recursive_implode($p1) : $p1;
$p2 = is_array($p2) ? recursive_implode($p2) : $p2;
switch($fn) {
case 'EXECUTE':
$sql = $p1;
......
......@@ -44,6 +44,8 @@ function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
global $ADODB_Last_PEAR_Error;
if (error_reporting() == 0) return; // obey @ protocol
$p1 = is_array($p1) ? recursive_implode($p1) : $p1;
$p2 = is_array($p2) ? recursive_implode($p2) : $p2;
switch($fn) {
case 'EXECUTE':
$sql = $p1;
......
......@@ -27,6 +27,8 @@ var $database = '';
function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
{
$p1 = is_array($p1) ? recursive_implode($p1) : $p1;
$p2 = is_array($p2) ? recursive_implode($p2) : $p2;
switch($fn) {
case 'EXECUTE':
$this->sql = $p1;
......
......@@ -1610,7 +1610,7 @@ function db_quote($value) {
function create_sql_exception_message($e, $sql, $values) {
$message = 'Failed to get a recordset: ' . $e->getMessage() . "Command was: $sql";
if (is_array($values) && count($values) > 0) {
$message .= ' and values was (' . implode(',', $values) . ')';
$message .= ' and values was (' . recursive_implode($values, true) . ')';
}
return $message;
}
......
......@@ -4098,3 +4098,32 @@ function libxml_after() {
libxml_disable_entity_loader($xmlstate);
}
}
/**
* Recursively implode an multidemenional array with optional key inclusion
*
* Output will be a string like either: value, value, value
* or if keys included: key: value, key: value, key: value
* Based on: https://gist.github.com/jimmygle/2564610
*
* @param array $array multi-dimensional array to recursively implode
* @param bool $include_keys include keys before their values
* @param string $separator value that demarcates value elements
* @param string $keyseparator value that demarcates key/value elements
* @param bool $trim_all trim ALL whitespace from string
*
* @return string imploded array
*/
function recursive_implode(array $array, $include_keys = false, $separator = ',', $keyseparator = ': ', $trim_all = true) {
$glued_string = '';
// Recursively iterates array and adds key/value to glued string
array_walk_recursive($array, function($value, $key) use ($separator, $keyseparator, $include_keys, &$glued_string) {
$include_keys and $glued_string .= $key.$keyseparator;
$glued_string .= $value.$separator;
});
// Removes last $separator from string
strlen($separator) > 0 and $glued_string = substr($glued_string, 0, -strlen($separator));
// Trim all whitespace
$trim_all and $glued_string = preg_replace("/(\s)/ixsm", '', $glued_string);
return (string) $glued_string;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment