67 lines
5.7 KiB
HTML
67 lines
5.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
|
<title>XQilla XQC API Documentation</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
<link href="tabs.css" rel="stylesheet" type="text/css">
|
|
</head><body>
|
|
<a style="float:right;" href="http://sourceforge.net/projects/xqilla"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=152021&type=2" border="0" alt="SourceForge.net Logo" /></a>
|
|
<!-- Generated by Doxygen 1.6.1 -->
|
|
<div class="navigation" id="top">
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li><a href="examples.html"><span>Examples</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="contents">
|
|
<h1>xqc-basic.c</h1><p>This example executes a simple XQuery expression ("1 to 100"), which returns the numbers from 1 to 100 inclusive.</p>
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="xqilla-xqc_8h.html">xqilla/xqilla-xqc.h</a>></span>
|
|
|
|
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
|
|
{
|
|
<a name="_a0"></a><a class="code" href="structXQC__Implementation__s.html" title="The XQC_Implementation struct provides factory functions for preparing queries.">XQC_Implementation</a> *impl;
|
|
<a name="_a1"></a><a class="code" href="structXQC__Expression__s.html" title="The XQC_Expression struct represents a prepared query, and allows the user to execute...">XQC_Expression</a> *expr;
|
|
<a name="_a2"></a><a class="code" href="structXQC__Sequence__s.html">XQC_Sequence</a> *seq;
|
|
<a class="code" href="xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3f" title="The error enumeration used by all XQC functions to designate error condition.">XQC_Error</a> err;
|
|
<span class="keyword">const</span> <span class="keywordtype">char</span> *value;
|
|
|
|
<span class="comment">// XQilla specific way to create an XQC_Implementation struct</span>
|
|
impl = <a name="a3"></a><a class="code" href="xqilla-xqc_8h.html#acd9659e93bbfafcd0cac9d7c4c12e13c" title="Creates an XQC_Implementation object that uses XQilla.">createXQillaXQCImplementation</a>(<a name="a4"></a><a class="code" href="xqc_8h.html#a8fbc00dfcf0a3527e0ccba36322e1c84" title="The version of the XQC API in this header file.">XQC_VERSION_NUMBER</a>);
|
|
<span class="keywordflow">if</span>(impl == 0) <span class="keywordflow">return</span> 1;
|
|
|
|
<span class="comment">// Prepare an XQuery expression</span>
|
|
err = impl-><a name="a5"></a><a class="code" href="structXQC__Implementation__s.html#a4f82aa0b0e5c675f95f6c78b3bf76216" title="Prepares a query from a UTF-8 string, returning an XQC_Expression object.">prepare</a>(impl, <span class="stringliteral">"1 to 100"</span>, 0, &expr);
|
|
<span class="keywordflow">if</span>(err != 0) <span class="keywordflow">goto</span> free_impl;
|
|
|
|
<span class="comment">// Execute the query</span>
|
|
err = expr-><a name="a6"></a><a class="code" href="structXQC__Expression__s.html#a3181579fa2677d43c29efd31a649726c" title="Executes the query represented by the XQC_Expression object using the values in the...">execute</a>(expr, 0, &seq);
|
|
<span class="keywordflow">if</span>(err != 0) <span class="keywordflow">goto</span> free_expr;
|
|
|
|
<span class="comment">// Iterate over the results, printing them</span>
|
|
<span class="keywordflow">while</span>((err = seq-><a name="a7"></a><a class="code" href="structXQC__Sequence__s.html#ab84594b06f7e69fd870c41f55ae5c6c6" title="Moves the XQC_Sequence so that the current item is positioned at the next item in...">next</a>(seq)) == <a name="a8"></a><a class="code" href="xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3fa975a11c6557d4d849e48f4034380a375" title="No error.">XQC_NO_ERROR</a>) {
|
|
seq-><a name="a9"></a><a class="code" href="structXQC__Sequence__s.html#a3bd3b6dab0c68652af816438407dd037" title="Returns the string value of the current item in the sequence - this is equivalent...">string_value</a>(seq, &value);
|
|
printf(<span class="stringliteral">"%s\n"</span>, value);
|
|
}
|
|
|
|
<span class="keywordflow">if</span>(err == <a name="a10"></a><a class="code" href="xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3fadfd1d8eea45c90655b98cfd728bfee2e" title="The end of the XQC_Sequence has been reached.">XQC_END_OF_SEQUENCE</a>)
|
|
err = <a class="code" href="xqc_8h.html#aeb1ad206e9c38a7f84749cafe04d7a3fa975a11c6557d4d849e48f4034380a375" title="No error.">XQC_NO_ERROR</a>;
|
|
|
|
<span class="comment">// free everything</span>
|
|
seq-><a name="a11"></a><a class="code" href="structXQC__Sequence__s.html#a13ab651edb4e0754cb8a032e2bce50b0" title="Called to free the resources associated with the XQC_Sequence.">free</a>(seq);
|
|
free_expr:
|
|
expr-><a name="a12"></a><a class="code" href="structXQC__Expression__s.html#a6aa28a94f0ff6732c26f131bbe4d44a9" title="Called to free the resources associated with the XQC_Expression.">free</a>(expr);
|
|
free_impl:
|
|
impl-><a name="a13"></a><a class="code" href="structXQC__Implementation__s.html#afb636b6cbd236831652a518d9e71418d" title="Called to free the resources associated with the XQC_Implementation.">free</a>(impl);
|
|
|
|
<span class="keywordflow">return</span> err;
|
|
}
|
|
</pre></div> </div>
|
|
<hr size="1"/><address style="text-align: right;"><small>Generated on 18 May 2015 for XQilla XQC API by
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
|
|
</body>
|
|
</html>
|