Last modified: 2012-11-20 09:32:02 UTC
In the code for Semantic Drilldown, there's a set of lines that essentially looks like this: $store = smwfGetStore(); $page = new SMWDIWikiPage( $pageName, $pageNamespace, null ); $property = new SMWDIProperty( $propertyID ); $requestOptions = null; return $store->getPropertyValues( $page, $property, $requestOptions ); However, this didn't work for any values that were passed in - and it turned out to be because the SQL query that SMW was using to get the SMW ID of the original page failed; and that was because the "iw" (interwiki) value in the query was null, but in the smw_object_ids table all the empty "iw" values are instead blank strings. After tracing the cause of the problem, I was able to fix it by adding the following line on line 252 of SMWSql3SmwIds::getSMWPageIDandSort(), right before the database select call: if ( is_null( $iw ) ) { $iw = ''; } I could just check in that line, but I wasn't sure that that was the right thing to do - or maybe there's something that needs fixing in my original SD code.
Thanks for digging this up. This should definitely return you an empty string. But normally this should not require a special code line. Will investigate.
I have reconsidered this now. It is correct for getPropertyValues() and any other SMW function to respect this discrepancy. This was not seen in earlier versions of SMW since we were not always using the MW database wrapping functions (building your own WHERE condition can mix up null and empty strings). But MySQL distinguishes NULL and empty strings very clearly, and so should we. The actual error here is in the code that you sketched above. It calls a method that expects a string with null. SMW should help to discover such errors by throwing an exception when you pass null where a string is needed, but this is only a small change.
Ah - changing the call from: new SMWDIWikiPage( $pageName, $pageNamespace, null ); to new SMWDIWikiPage( $pageName, $pageNamespace, '' ); ...did indeed fix the problem. I just checked in that change to the Semantic Drilldown code. I still think it's weird that calling it with blank instead of null causes it to no longer work. Does it ever make sense to different between a blank and a null value for the interwiki? Throwing an exception would be fine, but so, I think, would having that constructor method change a null value to a blank one.
I meant "to differentiate", above.
Good to hear that it works now. Regarding your questions: null and '' (and 0 and false) are different things. We are not making extra effort to differentiate between them. We just don't make any effort to treat them as equal. Due to the way in which PHP works, this can sometimes go unnoticed for some time, since things can easily get type converted if you are not careful.