2008年9月17日星期三

[fw-db] Zend_Db_Profiler_Firebug - query time fix

Hi

I'm writing here as i don't have create issue permision on zf issue
tracker.

*Problem*

Zend_Db_Profiler_Firebug. Query times are passed to firebug as float
without quoting which results as 4 cols table JSON in headers. Eg.:


[0,00011,"SET CHARACTER SET utf8",null]
^ ^

result is broken (shifted) table in firebug. eg:

Time | Event | Parameters | [null] |
0 | 11 | SET CHARACTER SET utf8 | [null] |

instead of expected:

Time | Event | Parameters |
0,00011 | SET CHARACTER SET utf8 | [null] |

*Solution*


Forcing ZF to pass query time as string instead of original float:

Zend_Db_Profiler_Firebug::queryEnd() line 128

_original line_:
$this->_message->addRow(array(round($profile->getElapsedSecs(),5),
$profile->getQuery(),

($params=$profile->getQueryParams())?$params:null));


_fixed line_:

$this->_message->addRow(array( (string) round(
$profile->getElapsedSecs(), 5),
$profile->getQuery(),

($params=$profile->getQueryParams())?$params:null));


*Additional enhancement*

And, my small enhancement of updateMessageLabel() function to add total
queries count in message label:


Zend_Db_Profiler_Firebug::updateMessageLabel() line 145:

_original:_
$this->_message->setLabel($this->_label . ' (' .
round($this->_totalElapsedTime,5) . ' sec)');

_changed (added query count):_

$this->_message->setLabel($this->_label . ' (' .
$this->getTotalNumQueries() .' - ' . round($this->_totalElapsedTime,5) .
' sec)');

--
K.

没有评论: