Click here to Skip to main content
12,890,181 members (44,223 online)
Click here to Skip to main content
Articles » Database » Database » General » Downloads


56 bookmarked
Posted 30 Nov 2003

DarkSide SQL Mini Version 1, The embedded database

, 23 Mar 2006 BSD
An embedded database library in C++.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/main.dwt" codeOutsideHTMLIsLocked="false" -->
<!-- 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 --> 

<body bgcolor="#FFFFFF" text="#666666">
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC">
    <td bgcolor="#CCCCCC"><h3><font color="#999999">DarkSide SQL Mini Help</font></h3></td>
<table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC">
    <td width="164" height="305" valign="top"><table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC">
          <td><a href="index.htm">Home</a></td>
          <td><a href="intro.htm">Introduction</a></td>
          <td><a href="using.htm">Using The Library</a></td>
          <td><a href="api_ref.htm">API Reference</a></td>
          <td><strong>SQL Commands</strong></td>
          <td><div align="center"><a href="sql_ct.htm">CREATE TABLE</a></div></td>
          <td><div align="center"><a href="sql_dd.htm">DROP DATABASE</a></div></td>
          <td><div align="center"><a href="sql_dt.htm">DROP TABLE</a></div></td>
          <td><div align="center"><a href="sql_use.htm">USE</a></div></td>
          <td><div align="center"><a href="sql_i.htm">INSERT</a></div></td>
          <td><div align="center"><a href="sql_u.htm">UPDATE</a></div></td>
          <td><div align="center"><a href="sql_d.htm">DELETE</a></div></td>
          <td><div align="center"><a href="sql_s.htm">SELECT</a></div></td>
          <td><div align="center"><a href="sql_o.htm">OPTIMIZE</a></div></td>
          <td><a href="types.htm">Data Types</a></td>
          <td><a href="oprs.htm">Operators</a></td>
          <td><a href="bugs.htm">Bugs</a></td>
          <td><a href="lic.htm">License</a></td>
          <td><a href="tps.htm">Third-party software</a></td>
          <td><a href="abt.htm">About</a></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>
        <li>Copy the cpp files in the <font color="#990000">&quot;C:\dsqlm_1\cpp&quot;</font> 
          folder to your project directory</li>
        <li>Take &quot;Project-&gt;Add to projects-&gt;Files&quot; and add all 
          these files to your project.</li>
        <li><font color="#666666">Take &quot;C/C++&quot; tab from &quot;Project-&gt;Settings&quot;,select 
          &quot;Preprocessor&quot; from the &quot;Category&quot; drop-down list 
          and add <font color="#990000">&quot;C:\dsqlm_1\include&quot;</font> 
          to the &quot;Additional include directories&quot; field.</font></li>
        <li><font color="#666666">T</font><font color="#666666">ake the &quot;Link&quot; 
          tab from &quot;Project-&gt;Settings&quot; and add <font color="#990000">&quot;C:\dsqlm_1\libdb41s.lib&quot;</font> 
          to &quot;Object\Library modules&quot;.</font></li>
      <p align="justify"><font color="#666666">You must include &quot;dsqlm.h&quot; 
        in any file that calls DarkSide SQL Mini API functions.<br>
        <code>#include &quot;dsqlm.h&quot;<br>
        using namespace dsqlm;</code></font></p>
      <p align="justify">The next step is to initialize a Database object:</p>
      <p align="justify">&nbsp;<code>Database db;</code></p>
      <p align="justify">You can connect to a database using the &quot;USE&quot; 
      <p align="justify"><code>db.execute(&quot;USE mydb&quot;);</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 &quot;execute()&quot; function of Database class:</p>
      <p align="justify"><code>long rows_affected = db.execute(&quot;DELETE FROM 
        emp WHERE salary &gt; 4500&quot;);</code> </p>
      <p align="justify">A SELECT statement is executed using the &quot;executeQuery()&quot; 
        function which will return a &quot;ResultSet&quot; object on success:</p>
      <p align="justify"><code>ResultSet rslt = db.executeQuery("SELECT * FROM 
        while( { <br>
        &nbsp;&nbsp;for(int i=0;i&lt;rslt.getColumnCount();i++) {<br>
        &nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; rslt.getString((i+1)) << "\t"; <br>
        &nbsp; } <br>
        &nbsp;cout << endl;<br>
      <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>
        &nbsp;// DsqlM API calls<br>
        }catch(DsqlMException ex) { <br>
        &nbsp;cout << ex.getMessage() << endl;<br>
      <p align="justify">Here is a complete example:</p>
      <p align="justify"><code>#include &lt;iostream&gt;<br>
        using namespace std;<br>
        #include &quot;dsqlm.h&quot;<br>
        using namespace dsqlm;</code></p>
      <p align="justify"><code>int main() {<br>
        &nbsp;&nbsp;try {<br>
        &nbsp;&nbsp;&nbsp;&nbsp;Database db;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;// creates the bookstore database&nbsp; <br>
        &nbsp;&nbsp;&nbsp;&nbsp;db.execute(&quot;USE bookstore&quot;); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;// creates the books table&nbsp; <br>
        &nbsp;&nbsp;&nbsp;&nbsp;db.execute(&quot;CREATE TABLE books(id autoid 
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;indexed,title VARCHAR(50) indexed,author 
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VARCHAR(40),date_of_pub DATE,price 
        FLOAT)&quot;); </code></p>
      <p align="justify"><code>&nbsp;&nbsp;&nbsp;&nbsp;// insert some data<br>
        &nbsp;&nbsp;&nbsp;&nbsp;db.execute(&quot;INSERT INTO books VALUES(0,'Complete 
        &nbsp;&nbsp;&nbsp;&nbsp;// insert some more data....<br>
        &nbsp;&nbsp;&nbsp;&nbsp;// and find out the total of prices of books &nbsp;&nbsp;&nbsp;&nbsp;//purchased 
        before or on current date<br>
        &nbsp;&nbsp;&nbsp;&nbsp;ResultSet rslt = db.executeQuery(&quot;SELECT 
        price &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FROM 
        books WHERE date_of_pub&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;= 
        &nbsp;&nbsp;&nbsp;&nbsp;float tot_p = 0;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;while( {<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tot_p += rslt.getFloat(&quot;price&quot;);<br>
        &nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; &quot;Total price: &quot; &lt;&lt; 
        tot_p &lt;&lt; endl;<br>
        &nbsp;&nbsp;&nbsp;}catch(DsqlMException ex) { <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt; ex.getMessage(); <br>
        &nbsp;&nbsp; } <br>
        &nbsp;&nbsp; return 1;<br>
        } </code></p>
      <p align="justify">&nbsp;</p>
    <!-- InstanceEndEditable --></tr>
    <td height="58" colspan="2" valign="top"><div align="center">&copy; 2003 <a href="">LogicMatrix</a></div></td>
<!-- 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 article, along with any associated source code and files, is licensed under The BSD License


About the Author

No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 23 Mar 2006
Article Copyright 2003 by AnOldGreenHorn
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid