File: complete_8cpp-example.html

package info (click to toggle)
simpledb 1.5-1.4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, squeeze
  • size: 888 kB
  • ctags: 238
  • sloc: cpp: 529; makefile: 127; perl: 23; sh: 9
file content (52 lines) | stat: -rw-r--r-- 4,910 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!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>Simple&amp;nbsp;C++&amp;nbsp;ODBC&amp;nbsp;Database&amp;nbsp;API: complete.cpp</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a> | <a class="qindex" href="examples.html">Examples</a></div>
<h1>complete.cpp</h1>This is an example of how to use the Simple Database API. This example makes use of just about all of the functionality. The test consists of the following steps:<p>
<ul>
<li>Create the columns that will be bound to the query. </li>
<li>Connect to the data source. </li>
<li>Create a query object from the database. </li>
<li>Bind the columns to the query. </li>
<li>Execute the query. </li>
<li>Fetch the results of the query.</li>
</ul>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include "SimpleDB/SimpleDB.h"</span>

<span class="keywordtype">int</span> main() {
  <a name="_a0"></a><a class="code" href="classSimpleDB_1_1LongColumn.html">SimpleDB::LongColumn</a> <span class="keywordtype">id</span> = <a class="code" href="classSimpleDB_1_1LongColumn.html">SimpleDB::LongColumn</a>();
  <a name="_a1"></a><a class="code" href="classSimpleDB_1_1StringColumn.html">SimpleDB::StringColumn</a> name = <a class="code" href="classSimpleDB_1_1StringColumn.html">SimpleDB::StringColumn</a>(1000);
  <a name="_a2"></a><a class="code" href="classSimpleDB_1_1Column.html">SimpleDB::Column</a> * columns[2] = {&amp;id,&amp;name};
  
  <span class="keywordflow">try</span> {
    <a name="_a3"></a><a class="code" href="classSimpleDB_1_1Database.html">SimpleDB::Database</a> db = <a class="code" href="classSimpleDB_1_1Database.html">SimpleDB::Database</a>(<span class="stringliteral">"eminence"</span>);    
    <a name="_a4"></a><a class="code" href="classSimpleDB_1_1Query.html">SimpleDB::Query</a> query = db.<a name="a5"></a><a class="code" href="classSimpleDB_1_1Database.html#a1">newQuery</a>();
    query.<a name="a6"></a><a class="code" href="classSimpleDB_1_1Query.html#a2">bind</a>(columns, <span class="keyword">sizeof</span>(columns)/<span class="keyword">sizeof</span>(columns[0]));
    query.<a name="a7"></a><a class="code" href="classSimpleDB_1_1Query.html#a3">execute</a>(<span class="stringliteral">"SELECT contact_number, first_name FROM contacts LIMIT 10"</span>);
    
    <span class="keywordflow">while</span>(query.<a name="a8"></a><a class="code" href="classSimpleDB_1_1Query.html#a4">fetchRow</a>())
      std::cout &lt;&lt; <span class="stringliteral">"ID: "</span> &lt;&lt; *columns[0] &lt;&lt; <span class="stringliteral">" NAME: "</span> &lt;&lt; *columns[1] &lt;&lt; std::endl;
    
    query.<a class="code" href="classSimpleDB_1_1Query.html#a3">execute</a>(<span class="stringliteral">"SELECT contact_number, last_name FROM contacts LIMIT 5"</span>);
    <span class="keywordflow">while</span>(query.<a class="code" href="classSimpleDB_1_1Query.html#a4">fetchRow</a>()) {
      std::cout &lt;&lt; <span class="stringliteral">"ID: "</span> &lt;&lt; *columns[0] &lt;&lt; <span class="stringliteral">" NAME: "</span> &lt;&lt; *columns[1] &lt;&lt; std::endl;
      std::cout &lt;&lt; <span class="stringliteral">"Some math "</span> &lt;&lt; <span class="keywordtype">id</span>.value()*5 &lt;&lt; <span class="stringliteral">" "</span> &lt;&lt; name.value().append(<span class="stringliteral">" adfad"</span>) &lt;&lt;
        std::endl;
    }
  } <span class="keywordflow">catch</span>(<a name="_a9"></a><a class="code" href="classSimpleDB_1_1Database_1_1Exception.html">SimpleDB::Database::Exception</a> &amp;s) {
    std::cerr &lt;&lt; s &lt;&lt; std::endl;
  } <span class="keywordflow">catch</span>(<a name="_a10"></a><a class="code" href="classSimpleDB_1_1Column_1_1UnboundException.html">SimpleDB::Column::UnboundException</a>) {
    std::cerr &lt;&lt; <span class="stringliteral">"A column was not bound!"</span> &lt;&lt; std::endl;
  }
  <span class="keywordflow">return</span> 0;
}
    
</pre></div> <hr>
<div align="right"><small>
Copyright (C) 2005 <a target="top" href="http://www.eminence.com.au">Eminence Technology Pty Ltd</a>.<br>
Documentation pages generated by doxygen.</small><br>
<a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=129109&amp;type=1" width="88" height="31" border="0" alt="SourceForge.net Logo" /></a>
</div>