Project

General

Profile

Actions

Bug #17940

closed

t3lib_DB displays wrong SQL in error case

Added by Franz Holzinger over 16 years ago. Updated almost 14 years ago.

Status:
Closed
Priority:
Should have
Category:
-
Target version:
-
Start date:
2007-12-19
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
4.2
PHP Version:
4.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

If there is a SQL error due to an UPDATE query with empty field array,
then an error message is displayed. However the last displayed SQL query
is not the one which has caused the error. Therefore it is hard to find
out what has went wrong.

(issue imported from #M7015)


Files

class.t3lib_db-wrong-sql.diff (1.68 KB) class.t3lib_db-wrong-sql.diff Administrator Admin, 2007-12-19 13:29
martix7015.patch (1.57 KB) martix7015.patch Administrator Admin, 2008-08-29 14:15
rfc7015_updated.diff (1.35 KB) rfc7015_updated.diff Administrator Admin, 2010-04-30 10:42
7015_v2.diff (1.79 KB) 7015_v2.diff Administrator Admin, 2010-05-28 11:10
Actions #1

Updated by Martin Kutschker about 16 years ago

But if the field list is empty than no query is generated at all. In this case the functin returns nothing (void) and it's ok that debug_lastBuiltQuery is not set.

Actions #2

Updated by Franz Holzinger about 16 years ago

The query is not generated in error case? It is bad behaviour to accept the parameters and simply do nothing. It should at least set the $this->store_lastBuiltQuery to the query which would have been created, and show the wrong query. Otherwise it is very hard to find out that nothing has been done in this function. This is needed, because only this is output as sqlDebug. Or invent a second variable for such a case. It is important that a wrong SQL is output in every error case.

Actions #3

Updated by Martin Kutschker about 16 years ago

The docs says it will return FALSE, in fact it returns nothting. You may check the failure case with code like that:

$query = UPDATEquery(..);
if (is_string($query)) {
// ok
} else {
//error
}

But I think this may fail with DBAL.

Best would be to do what the docs say: return FALSE in case of an error. So you can check it like this:

$query = UPDATEquery(..);
if ($query===FALSE) {
// error
} else {
// ok
}

Actions #4

Updated by Franz Holzinger about 16 years ago

Yes, this would be fine to do such a check in the program code.
But the sqlDebug should still show this buggy SQL and not another SQL query which is correct.

Actions #5

Updated by Martin Kutschker about 16 years ago

Why, the funciton did not generate any SQL code. If it does anything with lastGeneartedQuery it should set it to an empty string, but I think this is dull.

IMHO it would be better if all parameter checking in this function (there is one that die's) and the filed list check would throw an exception.

Actions #6

Updated by Franz Holzinger about 16 years ago

But the function description says:
"Creates an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values."
So the caller of this function assumes that this query will be created, even if an error occurs.

If you do not want to use lastGeneratedQuery, then create another one: lastErroneousSQL
This would help the caller of the function to display this for error debugging.

IMHO the check
if (is_array($fields_values) && count($fields_values)) {
is not necessary. It should create the wrong UPDATE query. This function should not avoid this. It is still possible to produce a wrong SQL UPDATE statement. Why does the function check this case?

A die is the worst solution.

Actions #7

Updated by Martin Nielsen over 15 years ago

I have supplied a patch: martix7015.patch

Suggested solutions were:
  • Leaving debug_lastBuiltQuery unaltered - which results in very confusing debug output since it would contain a previous unrelated query.
  • Setting debug_lastBuiltQuery to the empty string - which would let the debug output show the actual return value, but not provide any information about the cause of the error either.
  • Setting debug_lastBuiltQuery to the actual query that was asked for and let the debug output show what caused the error.

The supplied patch uses the last suggestion (even when $fields_values is not an array)

Bonuses:
  • Now the function always sets debug_lastBuiltQuery to the requested query.
  • The return value when an error occurs is no longer NULL but boolean FALSE as stated in the description.
Actions #8

Updated by Christian Kuhn almost 14 years ago

Committed 7015_v2 to trunk, rev. 7708

Actions

Also available in: Atom PDF