X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdba.php;h=b9e6c32d56acff766aeec3ffc91af5b09f5a023c;hb=44efdc3e1b01328a226c79e25834fe7adb2dbaf4;hp=3af8522516c64ca9f4306cdff9b836f02302bfac;hpb=8f253f6c1288534c50fac34f05afb1a2c07c9335;p=friendica.git diff --git a/include/dba.php b/include/dba.php index 3af8522516..b9e6c32d56 100644 --- a/include/dba.php +++ b/include/dba.php @@ -459,6 +459,27 @@ class dba { return $sql; } + /** + * @brief beautifies the query - useful for "SHOW PROCESSLIST" + * + * This is safe when we bind the parameters later. + * The parameter values aren't part of the SQL. + * + * @param string $sql An SQL string without the values + * @return string The input SQL string modified if necessary. + */ + public function clean_query($sql) { + $search = array("\t", "\n", "\r", " "); + $replace = array(' ', ' ', ' ', ' '); + do { + $oldsql = $sql; + $sql = str_replace($search, $replace, $sql); + } while ($oldsql != $sql); + + return $sql; + } + + /** * @brief Replaces the ? placeholders with the parameters in the $args array * @@ -521,6 +542,7 @@ class dba { logger('Parameter mismatch. Query "'.$sql.'" - Parameters '.print_r($args, true), LOGGER_DEBUG); } + $sql = self::$dbo->clean_query($sql); $sql = self::$dbo->any_value_fallback($sql); if (x($a->config,'system') && x($a->config['system'], 'db_callstack')) { @@ -708,6 +730,9 @@ class dba { * @return int Number of rows */ static public function num_rows($stmt) { + if (!is_object($stmt)) { + return 0; + } switch (self::$dbo->driver) { case 'pdo': return $stmt->rowCount(); @@ -1200,6 +1225,7 @@ function q($sql) { unset($args[0]); if ($db && $db->connected) { + $sql = $db->clean_query($sql); $sql = $db->any_value_fallback($sql); $stmt = @vsprintf($sql,$args); // Disabled warnings //logger("dba: q: $stmt", LOGGER_ALL); @@ -1237,6 +1263,7 @@ function qu($sql) { unset($args[0]); if ($db && $db->connected) { + $sql = $db->clean_query($sql); $sql = $db->any_value_fallback($sql); $stmt = @vsprintf($sql,$args); // Disabled warnings if ($stmt === false)