This document is part of the D2RQ documentation.

d2r-query: Running SPARQL queries against a database

The d2r-query tool allows executing SPARQL queries against a D2RQ-mapped relational database from the command line. This can be done with or without a D2RQ mapping file. If a mapping file is specified, then the tool will query the virtual RDF graph defined by the mapping. If no mapping file is specified, then the tool will use the default mapping of generate-mapping for the translation.

To query a D2RQ-mapped database using a web-based interface, use D2R Server.


d2r-query [-f format] [-b baseURI] [-t timeout] [--verbose] [--debug] mapping-file.ttl query

The filename of a D2RQ mapping file that contains a database mapping.

If no mapping file is provided, then the database connection must be specified on the command line using the same connection parameters as for the generate-mapping tool, and a default mapping will be used.

A SPARQL query. All prefixes defined in the mapping file are available without being declared. The query can also be read from a file by using the syntax @filename.
-f format
The output format. Supported formats include text (the default), xml, json, csv, tsv, srb, and ttl.
-b baseURI
The base URI for turning relative URIs and URI patterns into absolute URIs. It is used both for the data and for the query.
-t timeout
Query timeout in seconds.
Print extra progress log information.
Print all debug log information.


Invocation using a mapping file

d2r-query mapping-iswc.ttl "SELECT * { ?s ?p ?o } LIMIT 10"

Writing results to a CSV file

d2r-query -f csv mapping-iswc.ttl "SELECT * { ?paper dc:title ?title }" > papers.csv

Invocation with default mapping

d2r-query -u root jdbc:mysql:///iswc "SELECT * { ?s ?p ?o } LIMIT 10"

Querying a SQL dump using a temporary in-memory database

dump-rdf -l db_dump.sql -o output.nt "SELECT * { ?s ?p ?o } LIMIT 10"

Reading the query from a file

dump-rdf mapping.ttl @my-query.sparql