Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
 
Add your own
alternative version
Go to top

DarkSide SQL Mini Version 1, The embedded database

, 23 Mar 2006
An embedded database library in C++.
<!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">&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>
      </ol>
      <p align="justify"><font color="#666666">You must include &quot;dsqlm.h&quot; 
        in any file that calls DarkSide SQL Mini API functions.<br>
        <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; 
        function:</p>
      <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 
        emp");<br>
        while(rslt.next()) { <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>
        }</code>&nbsp;</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>
        &nbsp;// DsqlM API calls<br>
        }catch(DsqlMException ex) { <br>
        &nbsp;cout << ex.getMessage() << endl;<br>
        }</code></p>
      <p align="justify">Here is a complete example:</p>
      <p align="justify"><code>#include &lt;iostream&gt;<br>
        using namespace std;<br>
        <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;&nbsp;&nbsp;&nbsp;C++','MMJ','sysdate',456.88)&quot;);<br>
        &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;= 
        'sysdate'&quot;);<br>
        &nbsp;&nbsp;&nbsp;&nbsp;float tot_p = 0;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;while(rslt.next()) {<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tot_p += rslt.getFloat(&quot;price&quot;);<br>
        &nbsp;&nbsp;&nbsp;&nbsp;}<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>
      </td>
    <!-- InstanceEndEditable --></tr>
  <tr> 
    <td height="58" colspan="2" valign="top"><div align="center">&copy; 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.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 23 Mar 2006
Article Copyright 2003 by AnOldGreenHorn
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid