Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
documentation
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Jul 2013 at 12:52 UTC
Updated:
20 Jun 2017 at 14:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
pkiraly commentedI attached the patch with the modified documentation sentence.
Comment #2
pkiraly commentedComment #3
chx commented94 characters; need a linebreak before 80; otherwise great.
Comment #4
pkiraly commentedComment #5
chx commentedGood to go.
Comment #6
jhodgdonUm... Maybe it should say that the return value is *typically* the number of deleted rows? What else could it be and in what way does it depend on the database connection? I don't really think this makes the situation much clearer.
Also, I think we need to do this in D8 first:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Query!De...
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Query!De...
and other classes/interfaces
Comment #7
chx commentedApparently I remembered wrong. Here's the code:
Here's the official docs: http://www.php.net/manual/en/pdostatement.rowcount.php and a relevant #805858: Affected rows inconsistent across database engines well researched issue.
Reading the latter,
So apparently the standard does define affected rows... and the problem really is only with UPDATEs not DELETEs. Well then, thanks for catching me being too cautious -- let's make the patch say definitely it is the number of deleted rows.
Comment #8
jhodgdonExcellent! Thanks for the detailed research notes. I think this is now a good Novice issue. The task:
Search out all Delete query classes/interfaces in Drupal 8, and make sure their execute() return value docs say that the return value is the number of deleted rows.
Comment #9
oriol_e9gI just found another occurrence but the documentation seems right:
Comment #10
jhodgdonIt sounds like the SQLite class's execute() documentation should say that it returns the number of rows deleted, except in the case where there is no WHERE, then? Or does it? The documentation you pasted here is just the class documentation, not the execute() method.
And aren't there more cases than just core/lib/Drupal/Core/Database/Query/Delete.php where the execute() documentation needs an update?
Comment #11
oriol_e9g@jhodgdon I just found this extra case. The documentation is in the class and nothing in the execute method.
Maybe we can move some documentation from the class to the execute method:
So, you can found similar documentation in other places like TRUCATE executes:
...but all those cases are out of the issue scope.
Comment #12
jhodgdonRight, let's stick with the execute() method on Delete classes for this issue, and yes, let's move the documentation on the return value of execute() to the execute() method on the SQLite class.
And maybe on the delete interface, we should mention that some engines do make exceptions to the rule that execute() always returns the number of rows.
Anyway, the supplied patch does not appear to fix all the cases of execute() on all Delete classes and interfaces, right?
Comment #14
ivanchaer commentedComment #15
ivanchaer commentedIn order to find all the files that implemented the execute() function of Delete, I made a search for all files that contained the string "function execute()", and then made another search for the string "delete", just on the files that were returned by the first search.
The only result besides the file previously patched (a/core/lib/Drupal/Core/Database/Query/Delete.php) was a/core/lib/Drupal/Core/Database/Driver/sqlite/Delete.php.
I added the {@inheritdoc} to its execute() function.
Comment #16
jhodgdonThanks! I agree with your analysis and the SQLite class is the only one that overrides the base Delete::execute() method.
However, as noted above, in SQLite, the execute() method does not always return the number of rows deleted, so it should not be inheriting the documentation from the base class. It needs its own documentation header.
Also, when attaching a patch, please name it *.patch so it gets flagged as a patch for testing/review. Thanks!
Comment #17
lucaslg commentedI added its own documentation to the SQLite implementation and mentioned on the parent class that some implementations work differently.
Comment #18
Anonymous (not verified) commentedComment #22
lucaslg commentedSame as #17 but with unix line ending
Comment #24
lucaslg commented#22 failed because of changes in #2465221: Raise the minimun version requirement for SQLite to 3.6.8. Beginner error, i forgot to git pull.
I think that now, because SQLite support starts at 3.6.8 which always return the number of rows deleted , #9 is relevant and should be used.
Comment #25
jhodgdontagging in hopes the SQLite folks see this... I do not know the answer.
Comment #26
cilefen commentedComment #27
cilefen commentedIn response to #24 and #25, it seems the "number of rows deleted" bug was fixed in 3.6.5.
Comment #28
travis-bradbury commentedAdded beta evaluation.
Comment #29
travis-bradbury commentedComment #30
travis-bradbury commentedThis was actually fixed with issue 2465221. There is no longer a special behaviour to Delete for sqlite and the documentation in question has already been removed.
Comment #31
jhodgdonIn that case, it's a D7 issue.
Comment #32
travis-bradbury commentedHow does this look? There didn't appear to be anything unclear about the documentation in 7.x but I modified it a little to limit lines to 80 characters and added @return, like the D8 patch.
Comment #33
Anonymous (not verified) commentedTriggering testbot, but it will need to be put in needs work for the feedback below.
It generally looks ok to me.
The patch in #22 also had a doc change here. Is that not relevant in D7?
There is a trailing space at the end here. It should be removed.
Also optimisation is with an "s".
Edit:
Actually this wrapping is incorrect. "deleted" should move up a line. It just fits.
Comment #34
travis-bradbury commentedI removed the extra whitespace after "entire" and moved "deleted" up a line.
I left the spelling as "optimization" because, as far as I can tell, Drupal prefers the Oxford spelling.[1]
There wasn't anything wrong with the changes #22; it's just not applicable to D8 any more and it doesn't apply to D7.
[1] https://www.drupal.org/style-guide/content#english
Comment #35
jhodgdonyes, please use American English spelling with a Z not S in optimization.
Comment #36
Anonymous (not verified) commentedOh I see. Looks good to me!
Comment #37
jhodgdon+1, thanks!
Comment #38
David_Rothstein commentedThis doesn't look right to me; classes don't have return values. Perhaps the @return is supposed to be on the execute() method instead?
And it's written pretty definitively but that conflicts with the documentation below which says that it depends on SQLite version...
Also, this patch no longer seems to deal with the original issue, which is DeleteQuery::execute() itself, which still says the vague/unhelpful "The return value is dependent on the database connection"....
Comment #39
jhodgdonDoh. Actually, we should go back to Drupal 8 first. The Delete::execute() method does not say what its return value is. All it says is:
The return value is dependent on the database connection.
That will teach me to accept it when someone else says the issue is fixed, when it isn't.
Comment #40
Anonymous (not verified) commentedAfter reading this thread again, I think we need to fix the return docs. The sqllite docs state that the number of affected rows is returned (see https://www.sqlite.org/lang_delete.html). According to http://php.net/manual/en/pdostatement.rowcount.php the type would be int.
The comment about version 3.6.5 is only relevant for D7, since the min version for D8 is 3.6.8. That was done in #2465221: Raise the minimun version requirement for SQLite to 3.6.8.
Comment #41
jhodgdonLooks good, thanks!
Also I noticed #2594845: Many database driver classes have no class doc blocks while checking this... Sigh. Who lets all these documentless-classes into Core???!?
Comment #42
xjmThat's much better. :) As a documentation-only fix, this change is considered "rc eligible" and can be committed any time during RC. Reference: https://www.drupal.org/core/d8-allowed-changes#rc
Committed and pushed to 8.0.x. Thanks!
Comment #44
jhodgdonComment #45
snehi commentedDone for 7.x
Comment #46
jhodgdonThis line has an extra space at the end.
By the way, there was a long discussion above about SQLite and whether it was correct that all of the databases return the number of rows affected. So I looked at the execute() method on the D7 SQLite DeleteQuery_sqlite class, and the execute method definitely returns the number of rows (the implementation has some code that makes sure this happens).
So, in this patch, we should remove this text in the class header docs... or actually, we should move it into a code comment:
This information should be turned into // comments and put just before this if() in the execute() method:
Also maybe say something like "But we want to return the number of rows affected, so we calculate it directly.
Comment #47
snehi commentedPlease review attached one.
Comment #48
jhodgdonThis information needs to go into the SQLite Delete class, not the generic class. Sorry, my comment above wasn't specific and I pasted in the comment again instead of the if() statement I was referring to. But you need to find the place in the SQLite class where it calculates the number of rows affected, and put this comment there.
Comment #50
lucaslg commentedHi,
I moved the comment to the SQLite Delete class as mentionned in #48 and removed the class header comment.
Comment #53
stefan.r commentedTagging the Drupal 7 backport as Novice -- this still needs review to see if this is RTBC and all the feedback has been addressed, and to further iterate if necessary.
Comment #56
yago elias commentedChanging the status of this ticket.
Comment #57
David_Rothstein commentedCommitted to 7.x - thanks!
I removed this on commit since we don't have @inheritdoc anywhere else in Drupal 7 right now and I didn't want to add it to just this one place:
Comment #59
yago elias commented