X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FDatabase%2FDatabase.php;h=28283b1c8175d8273d980c0ffe17b021b8074cdc;hb=f26226229a45af4053055b8a5ea7aa0f7aa33e0c;hp=9299b925a1f4c55fca85ee0ef0fb49786c599c7e;hpb=99a145f7cff984f19e8adbc018a8b631aaa58e0f;p=friendica.git diff --git a/src/Database/Database.php b/src/Database/Database.php index 9299b925a1..28283b1c81 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -1,6 +1,6 @@ profiler->startRecording('database'); $stamp1 = microtime(true); $params = DBA::getParam(func_get_args()); @@ -695,7 +696,7 @@ class Database $this->errorno = $errorno; } - $this->profiler->saveTimestamp($stamp1, 'database'); + $this->profiler->stopRecording(); if ($this->configCache->get('system', 'db_log')) { $stamp2 = microtime(true); @@ -727,7 +728,7 @@ class Database public function e($sql) { - $stamp = microtime(true); + $this->profiler->startRecording('database_write'); $params = DBA::getParam(func_get_args()); @@ -779,7 +780,7 @@ class Database $this->errorno = $errorno; } - $this->profiler->saveTimestamp($stamp, "database_write"); + $this->profiler->stopRecording(); return $retval; } @@ -914,7 +915,7 @@ class Database */ public function fetch($stmt) { - $stamp1 = microtime(true); + $this->profiler->startRecording('database'); $columns = []; @@ -962,7 +963,7 @@ class Database } } - $this->profiler->saveTimestamp($stamp1, 'database'); + $this->profiler->stopRecording(); return $columns; } @@ -1266,7 +1267,7 @@ class Database * @param string|array $table Table name or array [schema => table] * @param array $fields contains the fields that are updated * @param array $condition condition array with the key values - * @param array|boolean $old_fields array with the old field values that are about to be replaced (true = update on duplicate) + * @param array|boolean $old_fields array with the old field values that are about to be replaced (true = update on duplicate, false = don't update identical fields) * * @return boolean was the update successfull? * @throws \Exception @@ -1460,8 +1461,12 @@ class Database $row = $this->fetchFirst($sql, $condition); - // Ensure to always return either a "null" or a numeric value - return is_numeric($row['count']) ? (int)$row['count'] : $row['count']; + if (!isset($row['count'])) { + $this->logger->notice('Invalid count.', ['table' => $table, 'row' => $row, 'expression' => $expression, 'condition' => $condition_string, 'callstack' => System::callstack()]); + return 0; + } else { + return (int)$row['count']; + } } /** @@ -1589,7 +1594,7 @@ class Database public function close($stmt) { - $stamp1 = microtime(true); + $this->profiler->startRecording('database'); if (!is_object($stmt)) { return false; @@ -1615,7 +1620,7 @@ class Database break; } - $this->profiler->saveTimestamp($stamp1, 'database'); + $this->profiler->stopRecording(); return $ret; }