Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

Commit

Permalink
Fix for doubled queries in profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarvardt committed Mar 22, 2013
1 parent 34c3b2d commit 09a9627
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 68 deletions.
47 changes: 0 additions & 47 deletions src/BjyProfiler/Db/Adapter/Driver/Pdo/ProfilingStatement.php

This file was deleted.

11 changes: 4 additions & 7 deletions src/BjyProfiler/Db/Adapter/ProfilingAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BjyProfiler\Db\Profiler\Profiler;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Adapter\Driver as ZdbDriver;
use Zend\Db\Adapter\Profiler\ProfilerInterface;

class ProfilingAdapter extends Adapter
Expand All @@ -21,7 +22,6 @@ public function getProfiler()
return $this->profiler;
}


public function injectProfilingStatementPrototype(array $options = array())
{
$profiler = $this->getProfiler();
Expand Down Expand Up @@ -50,14 +50,11 @@ public function injectProfilingStatementPrototype(array $options = array())
break;
case 'Zend\Db\Adapter\Driver\Pdo\Pdo':
default:
$statementPrototype = new Driver\Pdo\ProfilingStatement();
}

if(isset($statementPrototype)) {
$statementPrototype->setProfiler($this->getProfiler());
$driver->registerStatementPrototype($statementPrototype);
$statementPrototype = new ZdbDriver\Pdo\Statement();
}

$statementPrototype->setProfiler($this->getProfiler());
$driver->registerStatementPrototype($statementPrototype);
}
}
}
Expand Down
33 changes: 19 additions & 14 deletions src/BjyProfiler/Db/Profiler/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Profiler implements ProfilerInterface
/**
* Logical OR these together to get a proper query type filter
*/
const CONNECT = 1;
const QUERY = 2;
const INSERT = 4;
const UPDATE = 8;
const DELETE = 16;
const SELECT = 32;
const TRANSACTION = 64;
const CONNECT = 1;
const QUERY = 2;
const INSERT = 4;
const UPDATE = 8;
const DELETE = 16;
const SELECT = 32;
const TRANSACTION = 64;

/**
* @var array
Expand Down Expand Up @@ -62,12 +62,20 @@ public function getFilterQueryType()
return $this->filterTypes;
}

public function startQuery($sql, $parameters = null, $stack = array())
public function startQuery($sql, $parameters = null, $stack = null)
{
if (!$this->enabled) {
return null;
}

if (is_null($stack)) {
if (version_compare('5.3.6', phpversion(), '<=')) {
$stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
} else {
$stack = array();
}
}

// try to detect the query type
switch (strtolower(substr(ltrim($sql), 0, 6))) {
case 'select':
Expand Down Expand Up @@ -95,15 +103,13 @@ public function startQuery($sql, $parameters = null, $stack = array())
return key($this->profiles);
}

public function endQuery($queryId)
public function endQuery()
{
if (!$this->enabled) {
return false;
}

$queryProfile = $this->profiles[$queryId];
$queryProfile->end();

end($this->profiles)->end();
return true;
}

Expand Down Expand Up @@ -135,7 +141,6 @@ public function profilerStart($target)

public function profilerFinish()
{

$this->endQuery();
}

}

0 comments on commit 09a9627

Please sign in to comment.