db_result should return FALSE if no result was found.

robertDouglass - November 21, 2006 - 21:18
Project:Drupal
Version:5.x-dev
Component:database system
Category:bug report
Priority:normal
Assigned:chx
Status:closed
Description

Otherwise it returns NULL which is too ambiguous and makes many comparisons harder.

AttachmentSizeStatusTest resultOperations
dbresult.patch1.49 KBIgnoredNoneNone

#1

robertDouglass - November 21, 2006 - 21:20

update doxygen comments

AttachmentSizeStatusTest resultOperations
dbresult_0.patch2.17 KBIgnoredNoneNone

#2

chx - November 21, 2006 - 21:24
Assigned to:Anonymous» chx
Status:active» reviewed & tested by the community

Also, I consider db_* just a wrapper against mysql_*/pgsql_* and mysql_result never returns NULL so we should not either.

#3

chx - November 21, 2006 - 21:40

also... the API change is extremely small as if(db_result()) does not change. you need to put the results in an array and check with isset -- but then this is the desired.

#4

Dries - November 22, 2006 - 08:55
Priority:critical» normal

#5

Dries - November 24, 2006 - 09:57

I don't understand why this is considered a bug.

The reason for this patch ...
Otherwise it returns NULL which is too ambiguous and makes many comparisons harder.
... doesn't seem to fly. With the patch, we'd be able to say:
When it returns FALSE, it is too ambiguous and makes many comparisons harder.

#6

chx - November 24, 2006 - 10:07

The problem is that when you store these in an array, because you will store NULLs and require the slow array_key_exists to be used.

But, as i said, this makes the db_result inconsistent with its PHP origins which is also a wrong.

#7

robertDouglass - November 24, 2006 - 11:19

Right. The reasons for this patch are 1) consistency, 2) performance. Getting FALSE back from this function will have a direct effect on how efficient we can make drupal_lookup_path.

#8

drumm - November 25, 2006 - 08:20

With 81 calls to db_result() in Drupal, I fear that something which depends on db_result returning NULL will break in some subtle way. Same applies to contributions. While the change does make sense, I don't want to make subtle API changes at this point in the release process.

#9

chx - November 25, 2006 - 09:43

I read each and every === and !== in core -- they are very rare, especially if you take out the strpos related ones, 11 and 9 -- and none of them is related to a strpos.

Once again: you need a _strict typed check_ to make this any difference. Who uses strict type checks on database data?

#10

chx - November 25, 2006 - 09:44

obviously the above should read: "and none of them relates to a db_result".

#11

robertDouglass - November 25, 2006 - 19:54

A similar audit of modules tagged with DRUPAL-5 would be possible, Neil, if you ask for it. I think it is most important to get it right in core... especially so close to the heart of core, our database layer, and then document it and let contrib sort itself out.

#12

drumm - November 26, 2006 - 01:32

This also matters for more tests than === or !==, like isset(), as #97317 has demonstrated.

I do think this should happen, but am not sure if it is something for 5.0 or 6. I don't want to waste contrib module authors' time as they "sort it out." I would expect this sort of thing to be rather annoying to debug if it caused a problem.

I'll leave this as RTC so other committers may see this and help decide when this should happen.

#13

Dries - November 28, 2006 - 09:45

The reasons for this patch are 1) consistency, 2) performance. Getting FALSE back from this function will have a direct effect on how efficient we can make drupal_lookup_path.

So far, the only valid reason for this patch is 'better performance', not? If this is about performance, we should back up our claims and measure the gain. I'm not convinced it will be measurable, in which case we want to postpone this patch. If the gain is significant (>= 2%), I suggest we go ahead and commit this.

#14

drumm - November 29, 2006 - 03:14

I was thinking this patch was good because of consistency with low-level database APIs.

#15

Dries - December 1, 2006 - 17:13

I was thinking this patch was good because of consistency with low-level database APIs.

Which low-level database API. I don't think many low-level database APIs use mixed value returns, but I might be wrong. Url?

#16

robertDouglass - December 1, 2006 - 20:40

http://de.php.net/manual/en/function.mysql-result.php

Return Values

The contents of one cell from a MySQL result set on success, or FALSE on failure.

#17

Dries - December 4, 2006 - 11:03

Thanks for the URL. I'm convinced now -- the patch can go in. :)

#18

Dries - December 4, 2006 - 11:36
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#19

Anonymous - December 18, 2006 - 11:46
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.