[TYPO3-core] RFC: minor optimisation of getRecordRaw()
Martin Kutschker
Martin.Kutschker at n0spam-blackbox.net
Wed Dec 13 15:45:50 CET 2006
Dmitry Dulepov schrieb:
> Hi!
>
> Martin Kutschker wrote:
>
>> I noticed that t3lib_BEfunc::getRecordRaw() does not free the SQL
>> result. While changing that I have also added a LIMIT to the query as
>> only the first found record is used.
>
>
> Good idea but I see a possibility for PHP errors here:
>
>> + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields,
>> $table, $where, '', '', '1');
>> + $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
>
>
> Second line will produce PHP error if first line does not return proper
> result set. Of course, it will not happen under normal conditions but
> still it would be cleaner to check for result:
>
> -------------------------
> $row = null;
> if (false !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
> $fields, $table, $where, '', '', '1'))) {
> $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
> $GLOBALS['TYPO3_DB']->sql_free_result($res);
> }
> return $row;
> -------------------------
>
> This would also take care about Franz's comment. $row on the first line
> can also be set to false, which will not be 100% identical to previous
> behavior but will look nicer and will be fully compatible with existing
> code.
Commited (but return FALSE, not NULL on error).
Masi
More information about the TYPO3-team-core
mailing list