File: factory_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 (53 lines) | stat: -rw-r--r-- 4,360 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
53
<!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: factory.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>factory.cpp</h1>This is a simple example of how to instantiate and then interface to the handle factory. <ul>
<li>Instantiate the factory </li>
<li>Retrieve a handle from it. </li>
<li>Perform a query on the handle returned </li>
<li>deallocate memory created by factory when finished with handle.</li>
</ul>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;SimpleDB/SimpleDB.h&gt;</span>
<span class="preprocessor">#include &lt;unistd.h&gt;</span>
<span class="preprocessor">#include &lt;memory&gt;</span>

<span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])
{
  std::cerr &lt;&lt; <span class="stringliteral">"START"</span> &lt;&lt; std::endl ;
 std::cerr &lt;&lt; <span class="stringliteral">"Process Id : "</span> &lt;&lt; getpid() &lt;&lt; std::endl ;
  sleep (6) ;
  <span class="comment">// memory leak check</span>
  <span class="keywordtype">long</span> <span class="keywordtype">int</span> i = 0 ;
  <span class="keywordflow">while</span> (i &lt; 1000) {
    <span class="keywordflow">try</span> {
      <a name="_a11"></a><a class="code" href="classSimpleDB_1_1SimpleDBFactory.html">SimpleDB::SimpleDBFactory</a>* factory  = <a name="a12"></a><a class="code" href="classSimpleDB_1_1SimpleDBFactory.html#e0">SimpleDB::SimpleDBFactory::Instance</a>() ;
      std::auto_ptr&lt;SimpleDB::Database&gt; db = factory-&gt;<a name="a13"></a><a class="code" href="classSimpleDB_1_1SimpleDBFactory.html#e1">getDBHandle</a>(<span class="stringliteral">"nightowl"</span>) ;
      
      <a name="_a14"></a><a class="code" href="classSimpleDB_1_1Query.html">SimpleDB::Query</a> query = db-&gt;newQuery();
      <a name="_a15"></a><a class="code" href="classSimpleDB_1_1LongColumn.html">SimpleDB::LongColumn</a> longCol = <a class="code" href="classSimpleDB_1_1LongColumn.html">SimpleDB::LongColumn</a>();
      <a name="_a16"></a><a class="code" href="classSimpleDB_1_1Column.html">SimpleDB::Column</a> * columns[1] = {&amp;longCol};
      query.<a name="a17"></a><a class="code" href="classSimpleDB_1_1Query.html#a2">bind</a>(columns, 1);
      query.<a name="a18"></a><a class="code" href="classSimpleDB_1_1Query.html#a3">execute</a>(<span class="stringliteral">"SELECT count(moduleId) FROM Modules"</span>);
      query.<a name="a19"></a><a class="code" href="classSimpleDB_1_1Query.html#a4">fetchRow</a>();
      <span class="comment">//cerr &lt;&lt; "I: " &lt;&lt; i &lt;&lt; endl ;</span>
      i++ ;
      <span class="comment">//std::cout &lt;&lt; "Number: " &lt;&lt; longCol &lt;&lt; std::endl;</span>
      factory-&gt;<a name="a20"></a><a class="code" href="classSimpleDB_1_1SimpleDBFactory.html#e2">Kill</a>() ;
    }
    <span class="keywordflow">catch</span> (<a name="_a21"></a><a class="code" href="classSimpleDB_1_1Database_1_1Exception.html">SimpleDB::Database::Exception</a> &amp;exc ){
      std::cerr &lt;&lt; exc &lt;&lt; std::endl ;
    }
  }
  std::cerr &lt;&lt; <span class="stringliteral">"FINISH"</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>