bjyoungblood/BjyProfiler — pull request #28 by vgarvardt (2013-03-22 15:34:19+00:00)
Title: Fix for doubled queries for PDO driver

refs #26

Dug into the problem and found the reason for doubling. As I use PDO as driver I applied fix only to PDO statement as I can test it. I assume this should be the same for another drivers, but can't test it.

The reason for doubling is the following:

* ProfilingStatement instance is registered as statement prototype for the driver
* Profiler is set for the statement prototype
* ProfilingStatement overrides execute method to surround real query execute with profile start and stop - this is the first call for the Profiler::startQuery which adds query to the list and adds stack trace information
* Original statement implements ProfilerAwareInterface, so when you set Profilter to ProfilingStatement you actually set profiler to original statement and it surrounds statement execute with profilerStart and profilerFinish methods
* Profiler implements ProfilerInterface, and profilerStart method is implemented, but profilerFinish method is empty, so query was not "finished" and it is added with 0 execution time. Also it has empty stack trace as you are creating stack array in ProfilingStatement

So, I removed PDO\ProfilingStatement as the only thing it does - creates additional inheritance level, that is not required here. Also I implemented profilerFinish method, so now profiling works fine and w/out any doubling. And added stack information getting to startQuery method as native statement does not pass any.

I tested this for the latest stable ZF2 (2.1.4) with PDO (mysql) and it works fine.

When all another statements will be cleaned in the following way startQuery and endQuery methods could be removed and the code is moved to profilerStart and profilerFinish methods.