r87824 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87823‎ | r87824 | r87825 >
Date:16:14, 10 May 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
separate methods that generate SPARQL query string, so that it can be retrieved separately for debugging
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php
@@ -204,6 +204,21 @@
205205 * @return SMWSparqlResultWrapper
206206 */
207207 public function select( $vars, $where, $options = array(), $extraNamespaces = array() ) {
 208+ $sparql = $this->getSparqlForSelect( $vars, $where, $options, $extraNamespaces );
 209+ return $this->doQuery( $sparql );
 210+ }
 211+
 212+ /**
 213+ * Build the SPARQL query that is used by SMWSparqlDatabase::select().
 214+ * The function declares the standard namespaces wiki, swivt, rdf, owl,
 215+ * rdfs, property, xsd, so these do not have to be included in
 216+ * $extraNamespaces.
 217+ *
 218+ * @param $where string WHERE part of the query, without surrounding { }
 219+ * @param $extraNamespaces array (associative) of namespaceId => namespaceUri
 220+ * @return string SPARQL query
 221+ */
 222+ public function getSparqlForSelect( $vars, $where, $options = array(), $extraNamespaces = array() ) {
208223 $sparql = self::getPrefixString( $extraNamespaces ) . 'SELECT ';
209224 if ( array_key_exists( 'DISTINCT', $options ) ) {
210225 $sparql .= 'DISTINCT ';
@@ -223,8 +238,7 @@
224239 if ( array_key_exists( 'LIMIT', $options ) ) {
225240 $sparql .= "\nLIMIT " . $options['LIMIT'];
226241 }
227 -
228 - return $this->doQuery( $sparql );
 242+ return $sparql;
229243 }
230244
231245 /**
@@ -238,11 +252,25 @@
239253 * @return SMWSparqlResultWrapper
240254 */
241255 public function ask( $where, $extraNamespaces = array() ) {
242 - $sparql = self::getPrefixString( $extraNamespaces ) . "ASK {\n" . $where . "\n}";
 256+ $sparql = $this->getSparqlForAsk( $where, $extraNamespaces );
243257 return $this->doQuery( $sparql );
244258 }
245259
246260 /**
 261+ * Build the SPARQL query that is used by SMWSparqlDatabase::ask().
 262+ * The function declares the standard namespaces wiki, swivt, rdf, owl,
 263+ * rdfs, property, xsd, so these do not have to be included in
 264+ * $extraNamespaces.
 265+ *
 266+ * @param $where string WHERE part of the query, without surrounding { }
 267+ * @param $extraNamespaces array (associative) of namespaceId => namespaceUri
 268+ * @return string SPARQL query
 269+ */
 270+ public function getSparqlForAsk( $where, $extraNamespaces = array() ) {
 271+ return self::getPrefixString( $extraNamespaces ) . "ASK {\n" . $where . "\n}";
 272+ }
 273+
 274+ /**
247275 * SELECT wrapper for counting results.
248276 * The function declares the standard namespaces wiki, swivt, rdf, owl,
249277 * rdfs, property, xsd, so these do not have to be included in

Status & tagging log