Feature #14582
closedRFE: get t3lib_DB->debug_lastBuiltQuery without t3lib_DB->debugOutput
0%
Description
It's annoying to get the last query only when debug output is enabled. The last query should always be stored so it can be retrieved and eg written to the devLog on error.
TYPO3 wastes some many CPU cycles and bytes in RAM, it hardly matters. And of course it's less if-clauses :-)
(issue imported from #M850)
Files
Updated by Rainer Kuhn over 19 years ago
Refering to a recent discussion on the dev list ("[Typo3-dev] DBAL usage question") : I proposed removing the condition from the line
if ($this->debugOutput) $this->debug_lastBuiltQuery = $query;
in all query building functions (INSERTquery(), UPDATEquery(), DELETEquery andSELECTquery()) to make the last built query always available in $this->debug_lastBuiltQuery. I did a quick try with my TYPO3 3.7.0 installation and it worked as expected, so I attached a unified diff here.
Greetings, Rainer
Updated by Michael Stucki over 19 years ago
I asked Kasper for the reason for not enabling this by default. Answer:
"I think it is because we want to save memory in the 99,9% of cases where
TYPO3 is NOT run under dev-circumstances!
Further, as you can see $this->debug_lastBuiltQuery is not meant to be
accessed from outside but rather presented to people from the
t3lib_db::debug() function. So developers should set the internal flag
->debug of the typo3_db class instead."
For your comfort I donate the fantastic stucki_debugdb extension to you! :-)
Updated by Martin Kutschker over 19 years ago
Ok, then why don't we get an debugQueries switch?
Works likes this: the value defaults to false, if debugOutput is set then it is automatically enabled, but it can of course be set manually.
Then the conditions for debugging should read like this:
if ($this->debugQueries) $this->debug_lastBuiltQuery = $query;
BTW: I don't take memory footprint argument. TYPO3 is a fine and working system that wastes megabytes by copying arrays multiple times by bulidung huge config arrays. I don't care about the few extra bytes as wasting resources is a trait in the complete code.
Updated by Rainer Kuhn over 19 years ago
I support masi's argumentation. Moreover the last query is not only needed under dev-circumstances but also in a production environment, e.g. for logging purposes.
Updated by Michael Stucki over 19 years ago
please change this:
if ($this->debugOutput) $this->debug_lastBuiltQuery = $query;
to something like this:
if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query;
I think everybody could live with that...
Updated by Rainer Kuhn over 19 years ago
I asked Kasper for the suggestions posted here and he agreed with stucki's suggestion:
"if ($this->debugOutput || $this->store_lastBuiltQuery)
$this->debug_lastBuiltQuery = $query;
This is fine with me."
So I've attached the resulting unified diff here, this one is based on TYPO3 3.8.0rc1: class.t3lib_db.php.patch2_for_380rc1.diff