|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/main.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Using The Library</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<link href="ss.css" rel="stylesheet" type="text/css">
<!-- InstanceEndEditable -->
</head>
<body bgcolor="#FFFFFF" text="#666666">
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC">
<tr>
<td bgcolor="#CCCCCC"><h3><font color="#999999">DarkSide SQL Mini Help</font></h3></td>
</tr>
</table>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC">
<!--DWLayoutTable-->
<tr>
<td width="164" height="305" valign="top"><table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC">
<tr>
<td><a href="index.htm">Home</a></td>
</tr>
<tr>
<td><a href="intro.htm">Introduction</a></td>
</tr>
<tr>
<td><a href="using.htm">Using The Library</a></td>
</tr>
<tr>
<td><a href="api_ref.htm">API Reference</a></td>
</tr>
<tr>
<td><strong>SQL Commands</strong></td>
</tr>
<tr>
<td><div align="center"><a href="sql_ct.htm">CREATE TABLE</a></div></td>
</tr>
<tr>
<td><div align="center"><a href="sql_dd.htm">DROP DATABASE</a></div></td>
</tr>
<tr>
<td><div align="center"><a href="sql_dt.htm">DROP TABLE</a></div></td>
</tr>
<tr>
<td><div align="center"><a href="sql_use.htm">USE</a></div></td>
</tr>
<tr>
<td><div align="center"><a href="sql_i.htm">INSERT</a></div></td>
</tr>
<tr>
<td><div align="center"><a href="sql_u.htm">UPDATE</a></div></td>
</tr>
<tr>
<td><div align="center"><a href="sql_d.htm">DELETE</a></div></td>
</tr>
<tr>
<td><div align="center"><a href="sql_s.htm">SELECT</a></div></td>
</tr>
<tr>
<td><div align="center"><a href="sql_o.htm">OPTIMIZE</a></div></td>
</tr>
<tr>
<td><a href="types.htm">Data Types</a></td>
</tr>
<tr>
<td><a href="oprs.htm">Operators</a></td>
</tr>
<tr>
<td><a href="bugs.htm">Bugs</a></td>
</tr>
<tr>
<td><a href="lic.htm">License</a></td>
</tr>
<tr>
<td><a href="tps.htm">Third-party software</a></td>
</tr>
<tr>
<td><a href="abt.htm">About</a></td>
</tr>
</table></td>
<!-- InstanceBeginEditable name="txt" -->
<td width="398" valign="top"><p align="justify">If you are using Visual C++,
follow the steps listed below to add database support to your application.
The steps should be identical for other IDEs too. It is assumed that you
installed DarkSide SQL Mini in the C:\ drive.</p>
<ol>
<li>Copy the cpp files in the <font color="#990000">"C:\dsqlm_1\cpp"</font>
folder to your project directory</li>
<li>Take "Project->Add to projects->Files" and add all
these files to your project.</li>
<li><font color="#666666">Take "C/C++" tab from "Project->Settings",select
"Preprocessor" from the "Category" drop-down list
and add <font color="#990000">"C:\dsqlm_1\include"</font>
to the "Additional include directories" field.</font></li>
<li><font color="#666666">T</font><font color="#666666">ake the "Link"
tab from "Project->Settings" and add <font color="#990000">"C:\dsqlm_1\libdb41s.lib"</font>
to "Object\Library modules".</font></li>
</ol>
<p align="justify"><font color="#666666">You must include "dsqlm.h"
in any file that calls DarkSide SQL Mini API functions.<br>
<br>
<code>#include "dsqlm.h"<br>
using namespace dsqlm;</code></font></p>
<p align="justify">The next step is to initialize a Database object:</p>
<p align="justify"> <code>Database db;</code></p>
<p align="justify">You can connect to a database using the "USE"
function:</p>
<p align="justify"><code>db.execute("USE mydb");</code></p>
<p align="justify">The database will be created if it does not already exist.</p>
<p align="justify">All SQL commands except SELECT must be executed by using
the "execute()" function of Database class:</p>
<p align="justify"><code>long rows_affected = db.execute("DELETE FROM
emp WHERE salary > 4500");</code> </p>
<p align="justify">A SELECT statement is executed using the "executeQuery()"
function which will return a "ResultSet" object on success:</p>
<p align="justify"><code>ResultSet rslt = db.executeQuery("SELECT * FROM
emp");<br>
while(rslt.next()) { <br>
for(int i=0;i<rslt.getColumnCount();i++) {<br>
cout << rslt.getString((i+1)) << "\t"; <br>
} <br>
cout << endl;<br>
}</code> </p>
<p align="justify"> The above code selects all data from the emp table and
prints them in the console. For more information on Databases and ResultSets,
see the <a href="api_ref.htm">API Reference</a>. All DarkSide SQL Mini
code must be enclosed in a try-catch block that will handle DsqlMExceptions:</p>
<p align="justify"><code>try { <br>
// DsqlM API calls<br>
}catch(DsqlMException ex) { <br>
cout << ex.getMessage() << endl;<br>
}</code></p>
<p align="justify">Here is a complete example:</p>
<p align="justify"><code>#include <iostream><br>
using namespace std;<br>
<br>
#include "dsqlm.h"<br>
using namespace dsqlm;</code></p>
<p align="justify"><code>int main() {<br>
try {<br>
Database db;<br>
// creates the bookstore database <br>
db.execute("USE bookstore"); <br>
// creates the books table <br>
db.execute("CREATE TABLE books(id autoid
indexed,title VARCHAR(50) indexed,author
VARCHAR(40),date_of_pub DATE,price
FLOAT)"); </code></p>
<p align="justify"><code> // insert some data<br>
db.execute("INSERT INTO books VALUES(0,'Complete
C++','MMJ','sysdate',456.88)");<br>
// insert some more data....<br>
// and find out the total of prices of books //purchased
before or on current date<br>
ResultSet rslt = db.executeQuery("SELECT
price FROM
books WHERE date_of_pub <=
'sysdate'");<br>
float tot_p = 0;<br>
while(rslt.next()) {<br>
tot_p += rslt.getFloat("price");<br>
}<br>
cout << "Total price: " <<
tot_p << endl;<br>
}catch(DsqlMException ex) { <br>
cout << ex.getMessage(); <br>
} <br>
return 1;<br>
} </code></p>
<p align="justify"> </p>
</td>
<!-- InstanceEndEditable --></tr>
<tr>
<td height="58" colspan="2" valign="top"><div align="center">© 2003 <a href="mailto:vijaymathewp@yahoo.co.in">LogicMatrix</a></div></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.