80 lines
9.4 KiB
HTML
80 lines
9.4 KiB
HTML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - System Overview - The Storage Kit</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
|
||
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
|
||
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="TheStorageKit_Overview.html" title="The Storage Kit" /><link rel="prev" href="IndexFunctions_Overview.html" title="Index Functions" /><link rel="next" href="FileSystemInfoFunctions_Overview.html" title="File System Info Functions" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="IndexFunctions_Overview.html" title="Index Functions"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="TheStorageKit_Overview.html" title="The Storage Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="FileSystemInfoFunctions_Overview.html" title="File System Info Functions"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - System Overview - The Storage Kit</div></div><div id="headerB">Prev: <a href="IndexFunctions_Overview.html">Index Functions</a> Up: <a href="TheStorageKit_Overview.html">The Storage Kit</a> Next: <a href="FileSystemInfoFunctions_Overview.html">File System Info Functions</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="QueryFunctions_Overview"></a>Query Functions</h2></div></div></div><p>
|
||
Normally, when you want to perform a file system query, you would use the
|
||
<a class="link" href="BQuery.html" title="BQuery"><code class="classname">BQuery</code></a> class,
|
||
which is a nice, clean, object-oriented way to do it. If
|
||
you have an aversion to object-oriented programming, however, or you're
|
||
writing a simple C program and would rather use C functions instead, then
|
||
you've come to the right place.
|
||
</p><p>
|
||
Be aware that, currently, you can't perform "live" queries at the C
|
||
level. If you want a live query, you have to use a
|
||
<a class="link" href="BQuery.html" title="BQuery"><code class="classname">BQuery</code></a> object.
|
||
</p><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="QueryFunctions_Opening_Reading_Closing"></a>Opening, Reading, and Closing a Query</h3></div></div></div><p>
|
||
To begin a query, you call
|
||
<a class="link" href="TheStorageKit_Functions.html#fs_open_query" title="fs_open_query()"><code class="function">fs_open_query()</code></a>.
|
||
<a class="link" href="TheStorageKit_Functions.html#fs_open_query" title="fs_open_query()"><code class="function">fs_open_query()</code></a> performs a
|
||
"one-shot" query: It lets you ask for all the files that fulfill certain
|
||
criteria right now. This criteria is expressed as a "predicate" string.
|
||
This is a formula that lists the attribute values that you're interested
|
||
in. A simple predicate takes the form
|
||
</p><pre class="screen">
|
||
<span class="emphasis"><em>attribute op value</em></span>
|
||
</pre><p>
|
||
For example, you can look for files that are larger than 5K by supplying
|
||
a string that looks like this:
|
||
</p><pre class="screen">
|
||
"size > 5000"
|
||
</pre><p>
|
||
Simple predicates can be grouped and combined to create more complex
|
||
predicates. Here we look for files named "fido" that are greater than 5K:
|
||
</p><pre class="screen">
|
||
"(name = fido) && (size > 5000)"
|
||
</pre><p>
|
||
For a full description of the predicate format, see
|
||
"<a class="xref" href="BQuery_Overview.html#BQuery_Predicate_Attributes_Indices" title="The Predicate, Attributes, and Indices">The Predicate, Attributes, and Indices</a>" in the
|
||
<a class="link" href="BQuery.html" title="BQuery"><code class="classname">BQuery</code></a> class
|
||
description, but be aware of this difference:
|
||
</p><ul class="itemizedlist"><li><p>
|
||
The <code class="function">fs_query</code> functions don't let you "push" elements onto the
|
||
predicate; all predicates must be expressed as strings.
|
||
</p></li></ul><p>
|
||
Once the query has been opened, you can step through the files that
|
||
fulfill the predicate through iterated calls to
|
||
<a class="link" href="TheStorageKit_Functions.html#fs_read_query" title="fs_read_query()"><code class="function">fs_read_query()</code></a>. When all
|
||
the winning files have been visited,
|
||
<a class="link" href="TheStorageKit_Functions.html#fs_read_query" title="fs_read_query()"><code class="function">fs_read_query()</code></a>
|
||
returns <code class="constant">NULL</code>.
|
||
</p><p>
|
||
When you've finished using your query, you must close it by using the
|
||
<a class="link" href="TheStorageKit_Functions.html#fs_close_query" title="fs_close_query()"><code class="function">fs_close_query()</code></a>
|
||
function.
|
||
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="QueryFunctions_An_Example"></a>An Example</h3></div></div></div><p>
|
||
The following sample demonstrates very briefly how to perform a simple,
|
||
non-live query. In this example, we're searching for all C header files
|
||
on the device specified by devnum.
|
||
</p><pre class="programlisting example c">void <code class="function">sample_query</code>(<span class="type">dev_t</span> <code class="parameter">devnum</code>) {
|
||
<span class="type">DIR*</span> <code class="varname">q</code>;
|
||
<span class="type">dirent_t*</span> <code class="varname">d</code>;
|
||
|
||
<code class="varname">q</code> = <code class="function">fs_open_query</code>(<code class="parameter">devnum</code>, "name=*.h", 0);
|
||
if (<code class="varname">q</code>) {
|
||
while (<code class="varname">d</code> = <code class="function">fs_read_query</code>(<code class="varname">q</code>)) {
|
||
...
|
||
}
|
||
<code class="function">fs_close_query</code>(<code class="varname">q</code>);
|
||
}
|
||
}</pre><p>
|
||
The code opens the query by calling
|
||
<a class="link" href="TheStorageKit_Functions.html#fs_open_query" title="fs_open_query()"><code class="function">fs_open_query()</code></a>, then, calls
|
||
<a class="link" href="TheStorageKit_Functions.html#fs_read_query" title="fs_read_query()"><code class="function">fs_read_query()</code></a>
|
||
in a loop until <code class="constant">NULL</code> is returned. Once that happens,
|
||
<a class="link" href="TheStorageKit_Functions.html#fs_close_query" title="fs_close_query()"><code class="function">fs_close_query()</code></a>
|
||
is used to close the query.
|
||
</p></div></div><div id="footer"><hr /><div id="footerT">Prev: <a href="IndexFunctions_Overview.html">Index Functions</a> Up: <a href="TheStorageKit_Overview.html">The Storage Kit</a> Next: <a href="FileSystemInfoFunctions_Overview.html">File System Info Functions</a> </div><div id="footerB"><div id="footerBL"><a href="IndexFunctions_Overview.html" title="Index Functions"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="TheStorageKit_Overview.html" title="The Storage Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="FileSystemInfoFunctions_Overview.html" title="File System Info Functions"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
|
||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
|
||
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>
|