Home

Contents
Preface

RDF Database and SPARQL

Data Representation
RDF and SPARQL API and SQL
SPARQL Implementation Extent
SPARQL Protocol End Point
Supported Methods and End Point URI Supported MIME Types of SPARQL Protocol SPARQL Client Functions

14.4. SPARQL Protocol End Point

The Virtuoso Server supports SPARQL protocol according to 'SPARQL Protocol for RDF ', W3C Working Draft 25 January 2006. The server contains both SPARQL protocol server (HTTP service endpoint) and functions of SPARQL protocol client that let application execute remote SPARQL query and receive the result as a typical result set.

Supported features include

14.4.1. Supported Methods and End Point URI

Virtuoso reserves the path '/sparql/' and a synonym path '/SPARQL/' for SPARQL service. In the current implementation, Virtuoso defines virtual directories for HTTP requests that come to the port specified as 'ServerPort' in the '[HTTPServer]' section of Virtuoso configuration file and refer to one of these two path strings. So if the Virtuoso installation on host example.com listens for HTTP requests on port 8080 then client applications should use the 'service endpoint' string equal to 'http://example.com:8080/sparql/'.

Both GET and POST requests are supported by both server and client. The server recognizes the 'Accept: ...' line of request header to find MIME types preferred by the connected client and adjust the output mode of the response.

The client chooses between GET and POST automatically, using the length of query text as a criterion. Queries longer than 1900 bytes are POST-ed, short queries are sent in GET mode.


14.4.2. Supported MIME Types of SPARQL Protocol

All standard MIME types of SPARQL Protocol are supported. SPARQL client supports 'application/sparql-results+xml' for results of SELECT and ASK queries, 'application/rdf+xml' and 'text/rdf+n3' for results of CONSTRUCT and DESCRIBE queries. If the HTTP header returned by the remote server does not contain 'Content-Type' line, the MIME type may be guessed from the text of the returned body. The current implementation does not support results of SELECT returned in RDF /XML, TURTLE or 'sparql-results-2'.

The Virtuoso SPARQL server can produce 'application/sparql-results+xml' for results of SELECT and ASK queries, 'application/rdf+xml' and 'text/rdf+n3' for results of CONSTRUCT and DESCRIBE queries.


14.4.3. SPARQL Client Functions

The SPARQL client can be invoked by three similar functions. All the functions get the following list of arguments:

DBA.SPARQL_REXEC () behaves like DBA.SPARQL_EVAL, but executes the query on the specified server. The procedure does not return anything. Instead, it creates a result set.

create procedure DB.DBA.SPARQL_REXEC (
    in service varchar, in query varchar, in dflt_graph varchar, in named_graphs any,
    in req_hdr any, in maxrows integer, in bnode_dict any );

Similarly, DBA.SPARQL_REXEC_TO_ARRAY () behaves like DBA.SPARQL_EXEC_TO_ARRAY (), but executes the query on the specified server. The function return a vector of rows, where every row is represented by a vector of valeus of fields.

create function DB.DBA.SPARQL_REXEC_TO_ARRAY (
    in service varchar, in query varchar, in dflt_graph varchar, in named_graphs any,
    in req_hdr any, in maxrows integer, in bnode_dict any )
    returns any;

The function DBA.SPARQL_REXEC_WITH_META () has no local 'SPARQL_EVAL' analog. It produces not only an array of result rows but also array of metadata about result set in a format used by the exec () function. This function can be used when the result should be passed later to exec_result_names () and exec_result () built-in functions. To process local query in similar style, an application can use plain SQL built-in function exec (): an SPARQL query (with 'SPARQL' keyword in front) can be passed to exec () instead of text of plain SQL SELECT statement.

create procedure DB.DBA.SPARQL_REXEC_WITH_META (
    in service varchar, in query varchar, in dflt_graph varchar, in named_graphs any,
    in req_hdr any, in maxrows integer, in bnode_dict any,
    out metadata any,  -- metadata like exec () returns.
    out resultset any) -- results as 'long valmode' values.

If the query is a CONSTRUCT or DESCRIBE then the result set consists of a single row and a single column, the value inside is a dictionary of triples in 'long valmode'. Note that the dictionary object can not be sent to SQL client, say, via ODBC . The client can loose database connection trying to fetch a result set row that contain a dictionary object. This disconnect will be safe for server, so the client can re-connect to the server, but the disconnected transaction will be rolled back.