r111325 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111324‎ | r111325 | r111326 >
Date:20:39, 12 February 2012
Author:mkroetzsch
Status:deferred (Comments)
Tags:
Comment:
accept integer return values (rather than just string) for counting queries; this prevented format=count to work with SPARQL databases
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStoreQueryEngine.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -408,7 +408,10 @@
409409 wfProfileOut( 'SMWQueryProcessor::getResultFromQuery (SMW)' );
410410
411411 return $result;
412 - } else { // result for counting or debugging is just a string
 412+ } else { // result for counting or debugging is just a string or number
 413+ if ( is_numeric( $res ) ) {
 414+ $res = strval( $res );
 415+ }
413416 if ( is_string( $res ) ) {
414417 if ( array_key_exists( 'intro', $params ) ) {
415418 $res = str_replace( '_', ' ', $params['intro'] ) . $res;
@@ -418,9 +421,7 @@
419422 }
420423
421424 $result = $res . smwfEncodeMessages( $query->getErrors() );
422 - }
423 - else {
424 - // When no valid result was obtained, $res will be a SMWQueryResult.
 425+ } else { // When no valid result was obtained, $res will be a SMWQueryResult.
425426 $result = smwfEncodeMessages( $query->getErrors() );
426427 }
427428
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStoreQueryEngine.php
@@ -296,6 +296,7 @@
297297 $options['DISTINCT'] = true;
298298 $sparqlResultWrapper = smwfGetSparqlDatabase()->selectCount( '?' . self::RESULT_VARIABLE,
299299 $condition, $options, $namespaces );
 300+
300301 if ( $sparqlResultWrapper->getErrorCode() == SMWSparqlResultWrapper::ERROR_NOERROR ) {
301302 return (int)$sparqlResultWrapper->getNumericValue();
302303 } else {

Comments

#Comment by Nikerabbit (talk | contribs)   07:09, 13 February 2012

is_numeric accepts all kinds of crap starting from hex numbers. is_int is probably better.