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&nbsp;C++&nbsp;ODBC&nbsp;Database&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 Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="pages.html">Related 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 <SimpleDB/SimpleDB.h></span>
<span class="preprocessor">#include <unistd.h></span>
<span class="preprocessor">#include <memory></span>
<span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[])
{
std::cerr << <span class="stringliteral">"START"</span> << std::endl ;
std::cerr << <span class="stringliteral">"Process Id : "</span> << getpid() << 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 < 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<SimpleDB::Database> db = factory-><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->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] = {&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 << "I: " << i << endl ;</span>
i++ ;
<span class="comment">//std::cout << "Number: " << longCol << std::endl;</span>
factory-><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> &exc ){
std::cerr << exc << std::endl ;
}
}
std::cerr << <span class="stringliteral">"FINISH"</span> << 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&type=1" width="88" height="31" border="0" alt="SourceForge.net Logo" /></a>
</div>
|