Index: trunk/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php |
— | — | @@ -377,7 +377,9 @@ |
378 | 378 | * method does not throw anything, then an empty result with an error |
379 | 379 | * code is returned. |
380 | 380 | * |
381 | | - * @note This method currently is specific to 4Store. It uses POST parameters that are not given in the specification. |
| 381 | + * @note This method has not been tesetd sufficiently since 4Store uses |
| 382 | + * another post encoding. To avoid using it, simply do not provide a |
| 383 | + * data endpoint URL when configuring the SPARQL database. |
382 | 384 | * |
383 | 385 | * @param $payload string Turtle serialization of data to send |
384 | 386 | * @return SMWSparqlResultWrapper |
— | — | @@ -388,16 +390,14 @@ |
389 | 391 | } |
390 | 392 | curl_setopt( $this->m_curlhandle, CURLOPT_URL, $this->m_dataEndpoint ); |
391 | 393 | curl_setopt( $this->m_curlhandle, CURLOPT_POST, true ); |
392 | | - $parameterString = "data=" . urlencode( $payload ) . '&graph=default&mime-type=application/x-turtle'; |
393 | | - curl_setopt( $this->m_curlhandle, CURLOPT_POSTFIELDS, $parameterString ); |
394 | 394 | |
395 | | -//// POST as file, fails in 4Store |
396 | | -// $payloadFile = tmpfile(); |
397 | | -// fwrite( $payloadFile, $payload ); |
398 | | -// fseek( $payloadFile, 0 ); |
399 | | -// curl_setopt( $this->m_curlhandle, CURLOPT_INFILE, $payloadFile ); |
400 | | -// curl_setopt( $this->m_curlhandle, CURLOPT_INFILESIZE, strlen( $payload ) ); |
401 | | -// curl_setopt( $this->m_curlhandle, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-turtle' ) ); |
| 395 | + // POST as file (fails in 4Store) |
| 396 | + $payloadFile = tmpfile(); |
| 397 | + fwrite( $payloadFile, $payload ); |
| 398 | + fseek( $payloadFile, 0 ); |
| 399 | + curl_setopt( $this->m_curlhandle, CURLOPT_INFILE, $payloadFile ); |
| 400 | + curl_setopt( $this->m_curlhandle, CURLOPT_INFILESIZE, strlen( $payload ) ); |
| 401 | + curl_setopt( $this->m_curlhandle, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-turtle' ) ); |
402 | 402 | |
403 | 403 | curl_exec( $this->m_curlhandle ); |
404 | 404 | |
Index: trunk/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase4Store.php |
— | — | @@ -18,27 +18,36 @@ |
19 | 19 | class SMWSparqlDatabase4Store extends SMWSparqlDatabase { |
20 | 20 | |
21 | 21 | /** |
22 | | - * ASK wrapper. |
23 | | - * "ASK" is buggy in 4Store and must be avoided. |
| 22 | + * Execute a HTTP-based SPARQL POST request according to |
| 23 | + * http://www.w3.org/2009/sparql/docs/http-rdf-update/. |
| 24 | + * The method throws exceptions based on |
| 25 | + * SMWSparqlDatabase::throwSparqlErrors(). If errors occur and this |
| 26 | + * method does not throw anything, then an empty result with an error |
| 27 | + * code is returned. |
| 28 | + * |
| 29 | + * This method is specific to 4Store since it uses POST parameters that |
| 30 | + * are not given in the specification. |
24 | 31 | * |
25 | | - * @note This does not avoid the 4Store bug: all SPARQL queries are |
26 | | - * potentially answered incorrectly by 4Store v.1.1.2. Nothing we can |
27 | | - * do. |
28 | | - * |
29 | | - * @see SMWSparqlDatabase::ask |
30 | | - * @param $where string WHERE part of the query, without surrounding { } |
31 | | - * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
| 32 | + * @param $payload string Turtle serialization of data to send |
32 | 33 | * @return SMWSparqlResultWrapper |
33 | 34 | */ |
34 | | - public function ask( $where, $extraNamespaces = array() ) { |
35 | | - $sparql = self::getPrefixString( $extraNamespaces ) . "SELECT * WHERE {\n" . $where . "\n} LIMIT 1"; |
36 | | - $result = $this->doQuery( $sparql ); |
37 | | - if ( $result->numRows() > 0 ) { |
38 | | - $expLiteral = new SMWExpLiteral( 'true', 'http://www.w3.org/2001/XMLSchema#boolean' ); |
39 | | - } else { |
40 | | - $expLiteral = new SMWExpLiteral( 'false', 'http://www.w3.org/2001/XMLSchema#boolean' ); |
| 35 | + public function doHttpPost( $payload ) { |
| 36 | + if ( $this->m_dataEndpoint == '' ) { |
| 37 | + throw new SMWSparqlDatabaseError( SMWSparqlDatabaseError::ERROR_NOSERVICE, "SPARQL POST with data: $payload", 'not specified', $error ); |
41 | 38 | } |
42 | | - return new SMWSparqlResultWrapper( array( '' => 0 ), array( array( $expLiteral ) ) ); |
| 39 | + curl_setopt( $this->m_curlhandle, CURLOPT_URL, $this->m_dataEndpoint ); |
| 40 | + curl_setopt( $this->m_curlhandle, CURLOPT_POST, true ); |
| 41 | + $parameterString = "data=" . urlencode( $payload ) . '&graph=default&mime-type=application/x-turtle'; |
| 42 | + curl_setopt( $this->m_curlhandle, CURLOPT_POSTFIELDS, $parameterString ); |
| 43 | + |
| 44 | + curl_exec( $this->m_curlhandle ); |
| 45 | + |
| 46 | + if ( curl_errno( $this->m_curlhandle ) == 0 ) { |
| 47 | + return true; |
| 48 | + } else { ///TODO The error reporting based on SPARQL (Update) is not adequate for the HTTP POST protocol |
| 49 | + $this->throwSparqlErrors( $this->m_dataEndpoint, $payload ); |
| 50 | + return false; |
| 51 | + } |
43 | 52 | } |
44 | 53 | |
45 | 54 | } |
\ No newline at end of file |