Page MenuHomePhabricator

Syntax error in SPARQL INSERT/DELETE DATA requests when default graph not set (1.7.1)
Closed, ResolvedPublic

Description

Author: jeen.broekstra

Description:
INSERT DATA and DELETE DATA requests generated by SMW_SparqlDatabase.php have illegal syntax when the default graph is not set: they have double curly brackets around the data:

INSERT DATA {{ ... }}

Here is a fix for the insertData function:

public function insertData( $triples, $extraNamespaces = array() ) {

		if ( $this->m_dataEndpoint !== '' ) {
			$turtle = self::getPrefixString( $extraNamespaces, false ) . $triples;
			return $this->doHttpPost( $turtle );
		} else {
			$sparql = self::getPrefixString( $extraNamespaces, true ) .
				"INSERT DATA { " .
				( ( $this->m_defaultGraph !== '' )? "GRAPH <{$this->m_defaultGraph}> { " : '' ) .
				" $triples } ";
				// close extra curly  bracket for graph clause
			       ( ( $this->m_defaultGraph !== '' )? " } " : " ";
			return $this->doUpdate( $sparql );
		}

}

Same should work for deleteData as well. I have not verified if this same problem occurs anywhere else.


Version: unspecified
Severity: major

Details

Reference
bz37575

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 12:22 AM
bzimport set Reference to bz37575.
bzimport added a subscriber: Unknown Object (MLST).

fpanico wrote:

patched file for properly use of default graph in SPARQL/Update query

patched file for properly use of default graph in SPARQL/Update query

Attached:

fpanico wrote:

I solved this problem modifying "\extensions\SemanticMediaWiki\includes\sparql\SMW_SparqlDatabase.php"

I update
-public function insertData( $triples, $extraNamespaces = array() ) {...} to fix the use of default graph
-public function doQuery( $sparql ) to add content type and charset
-public function doUpdate( $sparql ) to add content type and charset

I attach the patched file, so you have to download and substitute the old one.

Comment on attachment 11090
patched file for properly use of default graph in SPARQL/Update query

[Correcting MIME Type and setting patch flag]