4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace api\v
4\Traits
;
24 trait QueryCounterTrait
{
29 protected $startCount = 0;
32 * Start the query counter
34 protected function beginQueryCount() {
35 $this->startCount
= $this->getCurrentGlobalQueryCount();
40 * The number of queries since the counter was started
42 protected function getQueryCount() {
43 return $this->getCurrentGlobalQueryCount() - $this->startCount
;
50 private function getCurrentGlobalQueryCount() {
51 global $_DB_DATAOBJECT;
53 if (!$_DB_DATAOBJECT) {
54 throw new \
Exception('Database object not set so cannot count queries');
57 return $_DB_DATAOBJECT['RESULTSEQ'] ??
0;