<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" 
               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="redland-query">
<refmeta>
<refentrytitle role="top_of_page" id="redland-query.top_of_page">Querying</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>REDLAND Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Querying</refname>
<refpurpose>RDF query languages and execution.</refpurpose>
<!--[<xref linkend="desc" endterm="desc.title"/>]-->
</refnamediv>

<refsynopsisdiv id="redland-query.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>
typedef             <link linkend="librdf-query">librdf_query</link>;
typedef             <link linkend="librdf-query-factory">librdf_query_factory</link>;
<link linkend="void">void</link>                <link linkend="librdf-query-register-factory">librdf_query_register_factory</link>       (<link linkend="librdf-world">librdf_world</link> *world,
                                                         const <link linkend="char">char</link> *name,
                                                         unsigned <link linkend="char">char</link> *uri_string,
                                                         <link linkend="void">void</link> (factorylibrdf_query_factory*) ());
<link linkend="librdf-query">librdf_query</link>*       <link linkend="librdf-new-query">librdf_new_query</link>                    (<link linkend="librdf-world">librdf_world</link> *world,
                                                         const <link linkend="char">char</link> *name,
                                                         <link linkend="librdf-uri">librdf_uri</link> *uri,
                                                         unsigned <link linkend="char">char</link> *query_string,
                                                         <link linkend="librdf-uri">librdf_uri</link> *base_uri);
<link linkend="librdf-query">librdf_query</link>*       <link linkend="librdf-new-query-from-query">librdf_new_query_from_query</link>         (<link linkend="librdf-query">librdf_query</link> *old_query);
<link linkend="librdf-query">librdf_query</link>*       <link linkend="librdf-new-query-from-factory">librdf_new_query_from_factory</link>       (<link linkend="librdf-world">librdf_world</link> *world,
                                                         <link linkend="librdf-query-factory">librdf_query_factory</link> *factory,
                                                         const <link linkend="char">char</link> *name,
                                                         <link linkend="librdf-uri">librdf_uri</link> *uri,
                                                         unsigned <link linkend="char">char</link> *query_string,
                                                         <link linkend="librdf-uri">librdf_uri</link> *base_uri);
<link linkend="void">void</link>                <link linkend="librdf-free-query">librdf_free_query</link>                   (<link linkend="librdf-query">librdf_query</link> *query);
<link linkend="librdf-query-results">librdf_query_results</link>* <link linkend="librdf-query-execute">librdf_query_execute</link>              (<link linkend="librdf-query">librdf_query</link> *query,
                                                         <link linkend="librdf-model">librdf_model</link> *model);
<link linkend="int">int</link>                 <link linkend="librdf-query-get-limit">librdf_query_get_limit</link>              (<link linkend="librdf-query">librdf_query</link> *query);
<link linkend="int">int</link>                 <link linkend="librdf-query-set-limit">librdf_query_set_limit</link>              (<link linkend="librdf-query">librdf_query</link> *query,
                                                         <link linkend="int">int</link> limit);
<link linkend="int">int</link>                 <link linkend="librdf-query-get-offset">librdf_query_get_offset</link>             (<link linkend="librdf-query">librdf_query</link> *query);
<link linkend="int">int</link>                 <link linkend="librdf-query-set-offset">librdf_query_set_offset</link>             (<link linkend="librdf-query">librdf_query</link> *query,
                                                         <link linkend="int">int</link> offset);
</synopsis>
</refsynopsisdiv>









<refsect1 id="redland-query.description" role="desc">
<title role="desc.title">Description</title>
<para>
Provides classes to create query objects and to execute them over
an RDF graph (<link linkend="librdf-model"><type>librdf_model</type></link>) returning a <link linkend="librdf-query-results"><type>librdf_query_results</type></link>
Query result limits and offsets can be set.
</para>
</refsect1>

<refsect1 id="redland-query.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="librdf-query" role="typedef">
<title>librdf_query</title>
<indexterm zone="librdf-query"><primary>librdf_query</primary></indexterm><programlisting>typedef struct librdf_query_s librdf_query;
</programlisting>
<para>
Redland query class.</para>
<para>

</para></refsect2>
<refsect2 id="librdf-query-factory" role="typedef">
<title>librdf_query_factory</title>
<indexterm zone="librdf-query-factory"><primary>librdf_query_factory</primary></indexterm><programlisting>typedef struct librdf_query_factory_s librdf_query_factory;
</programlisting>
<para>
Redland query factory class.</para>
<para>

</para></refsect2>
<refsect2 id="librdf-query-register-factory" role="function">
<title>librdf_query_register_factory ()</title>
<indexterm zone="librdf-query-register-factory"><primary>librdf_query_register_factory</primary></indexterm><programlisting><link linkend="void">void</link>                librdf_query_register_factory       (<link linkend="librdf-world">librdf_world</link> *world,
                                                         const <link linkend="char">char</link> *name,
                                                         unsigned <link linkend="char">char</link> *uri_string,
                                                         <link linkend="void">void</link> (factorylibrdf_query_factory*) ());</programlisting>
<para>
Register a query factory.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>world</parameter>&nbsp;:</term>
<listitem><simpara> redland world object
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>name</parameter>&nbsp;:</term>
<listitem><simpara> the query language name
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>uri_string</parameter>&nbsp;:</term>
<listitem><simpara> the query language URI string (or NULL if none)
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>factory</parameter>&nbsp;:</term>
<listitem><simpara> pointer to function to call to register the factory
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-new-query" role="function">
<title>librdf_new_query ()</title>
<indexterm zone="librdf-new-query"><primary>librdf_new_query</primary></indexterm><programlisting><link linkend="librdf-query">librdf_query</link>*       librdf_new_query                    (<link linkend="librdf-world">librdf_world</link> *world,
                                                         const <link linkend="char">char</link> *name,
                                                         <link linkend="librdf-uri">librdf_uri</link> *uri,
                                                         unsigned <link linkend="char">char</link> *query_string,
                                                         <link linkend="librdf-uri">librdf_uri</link> *base_uri);</programlisting>
<para>
Constructor - create a new <link linkend="librdf-query"><type>librdf_query</type></link> object.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>world</parameter>&nbsp;:</term>
<listitem><simpara> redland world object
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>name</parameter>&nbsp;:</term>
<listitem><simpara> the name identifying the query language
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>uri</parameter>&nbsp;:</term>
<listitem><simpara> the URI identifying the query language (or NULL)
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>query_string</parameter>&nbsp;:</term>
<listitem><simpara> the query string
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>base_uri</parameter>&nbsp;:</term>
<listitem><simpara> the base URI of the query string (or NULL)
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> a new <link linkend="librdf-query"><type>librdf_query</type></link> object or NULL on failure
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-new-query-from-query" role="function">
<title>librdf_new_query_from_query ()</title>
<indexterm zone="librdf-new-query-from-query"><primary>librdf_new_query_from_query</primary></indexterm><programlisting><link linkend="librdf-query">librdf_query</link>*       librdf_new_query_from_query         (<link linkend="librdf-query">librdf_query</link> *old_query);</programlisting>
<para>
Should create a new query in the same context as the existing one
as appropriate.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>old_query</parameter>&nbsp;:</term>
<listitem><simpara> the existing query <link linkend="librdf-query"><type>librdf_query</type></link> to use
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> a new <link linkend="librdf-query"><type>librdf_query</type></link> object or NULL on failure
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-new-query-from-factory" role="function">
<title>librdf_new_query_from_factory ()</title>
<indexterm zone="librdf-new-query-from-factory"><primary>librdf_new_query_from_factory</primary></indexterm><programlisting><link linkend="librdf-query">librdf_query</link>*       librdf_new_query_from_factory       (<link linkend="librdf-world">librdf_world</link> *world,
                                                         <link linkend="librdf-query-factory">librdf_query_factory</link> *factory,
                                                         const <link linkend="char">char</link> *name,
                                                         <link linkend="librdf-uri">librdf_uri</link> *uri,
                                                         unsigned <link linkend="char">char</link> *query_string,
                                                         <link linkend="librdf-uri">librdf_uri</link> *base_uri);</programlisting>
<para>
Constructor - create a new <link linkend="librdf-query"><type>librdf_query</type></link> object.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>world</parameter>&nbsp;:</term>
<listitem><simpara> redland world object
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>factory</parameter>&nbsp;:</term>
<listitem><simpara> the factory to use to construct the query
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>name</parameter>&nbsp;:</term>
<listitem><simpara> query language name
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>uri</parameter>&nbsp;:</term>
<listitem><simpara> query language URI (or NULL)
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>query_string</parameter>&nbsp;:</term>
<listitem><simpara> the query string
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>base_uri</parameter>&nbsp;:</term>
<listitem><simpara> base URI of the query string (or NULL)
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> a new <link linkend="librdf-query"><type>librdf_query</type></link> object or NULL on failure
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-free-query" role="function">
<title>librdf_free_query ()</title>
<indexterm zone="librdf-free-query"><primary>librdf_free_query</primary></indexterm><programlisting><link linkend="void">void</link>                librdf_free_query                   (<link linkend="librdf-query">librdf_query</link> *query);</programlisting>
<para>
Destructor - destroy a <link linkend="librdf-query"><type>librdf_query</type></link> object.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>query</parameter>&nbsp;:</term>
<listitem><simpara> <link linkend="librdf-query"><type>librdf_query</type></link> object
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-query-execute" role="function">
<title>librdf_query_execute ()</title>
<indexterm zone="librdf-query-execute"><primary>librdf_query_execute</primary></indexterm><programlisting><link linkend="librdf-query-results">librdf_query_results</link>* librdf_query_execute              (<link linkend="librdf-query">librdf_query</link> *query,
                                                         <link linkend="librdf-model">librdf_model</link> *model);</programlisting>
<para>
Run the query on a model.
</para>
<para>
Runs the query against the (previously registered) model
and returns a <link linkend="librdf-query-results"><type>librdf_query_results</type></link> for the result objects.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>query</parameter>&nbsp;:</term>
<listitem><simpara> <link linkend="librdf-query"><type>librdf_query</type></link> object
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>model</parameter>&nbsp;:</term>
<listitem><simpara> model to operate query on
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara>  <link linkend="librdf-query-results"><type>librdf_query_results</type></link> or NULL on failure
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-query-get-limit" role="function">
<title>librdf_query_get_limit ()</title>
<indexterm zone="librdf-query-get-limit"><primary>librdf_query_get_limit</primary></indexterm><programlisting><link linkend="int">int</link>                 librdf_query_get_limit              (<link linkend="librdf-query">librdf_query</link> *query);</programlisting>
<para>
Get the query-specified limit on results.
</para>
<para>
This is the limit given in the query on the number of results allowed.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>query</parameter>&nbsp;:</term>
<listitem><simpara> <link linkend="librdf-query"><type>librdf_query</type></link> query object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> integer &gt;=0 if a limit is given, otherwise &lt;0
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-query-set-limit" role="function">
<title>librdf_query_set_limit ()</title>
<indexterm zone="librdf-query-set-limit"><primary>librdf_query_set_limit</primary></indexterm><programlisting><link linkend="int">int</link>                 librdf_query_set_limit              (<link linkend="librdf-query">librdf_query</link> *query,
                                                         <link linkend="int">int</link> limit);</programlisting>
<para>
Set the query-specified limit on results.
</para>
<para>
This is the limit given in the query on the number of results allowed.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>query</parameter>&nbsp;:</term>
<listitem><simpara> <link linkend="librdf-query"><type>librdf_query</type></link> query object
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>limit</parameter>&nbsp;:</term>
<listitem><simpara> the limit on results, &gt;=0 to set a limit, &lt;0 to have no limit
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> non-0 on failure
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-query-get-offset" role="function">
<title>librdf_query_get_offset ()</title>
<indexterm zone="librdf-query-get-offset"><primary>librdf_query_get_offset</primary></indexterm><programlisting><link linkend="int">int</link>                 librdf_query_get_offset             (<link linkend="librdf-query">librdf_query</link> *query);</programlisting>
<para>
Get the query-specified offset on results.
</para>
<para>
This is the offset given in the query on the number of results allowed.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>query</parameter>&nbsp;:</term>
<listitem><simpara> <link linkend="librdf-query"><type>librdf_query</type></link> query object
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> integer &gt;=0 if a offset is given, otherwise &lt;0
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="librdf-query-set-offset" role="function">
<title>librdf_query_set_offset ()</title>
<indexterm zone="librdf-query-set-offset"><primary>librdf_query_set_offset</primary></indexterm><programlisting><link linkend="int">int</link>                 librdf_query_set_offset             (<link linkend="librdf-query">librdf_query</link> *query,
                                                         <link linkend="int">int</link> offset);</programlisting>
<para>
Set the query-specified offset on results.
</para>
<para>
This is the offset given in the query on the number of results allowed.</para>
<para>

</para><variablelist role="params">
<varlistentry><term><parameter>query</parameter>&nbsp;:</term>
<listitem><simpara> <link linkend="librdf-query"><type>librdf_query</type></link> query object
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>offset</parameter>&nbsp;:</term>
<listitem><simpara> offset for results, &gt;=0 to set an offset, &lt;0 to have no offset
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&nbsp;:</term><listitem><simpara> non-0 on failure
</simpara></listitem></varlistentry>
</variablelist></refsect2>

</refsect1>




</refentry>
