Click here to Skip to main content
Licence BSD
First Posted 30 Nov 2003
Views 107,071
Bookmarked 56 times

DarkSide SQL Mini Version 1, The embedded database

By | 23 Mar 2006 | Article
An embedded database library in C++.
 
Part of The SQL Zone sponsored by
See Also

Introduction

Providing local data storage in an application is a real problem faced by many a C++ programmer. To avoid getting oneself confused with low-level file handling routines and chores like data indexing, most programmers tend to use commercial database systems even for minimum data handling purposes. If your application doesn't need the capabilities of a complete RDBMS server, then a small and efficient database library that plugs into your source code will seem an interesting solution. DarkSide SQL Mini is an effort to create such a library. You can take this as a beta release and I want developers to test this code and report bugs before the stable release. You may find even this beta release useful in many of your projects. The best thing about DarkSide SQL Mini is that, unlike other embedded database libraries, you don't have to learn a new set of APIs. It provides a subset of SQL that you can use to define schemas and manipulate data. All you have to learn to use are two classes (Database and ResultSet) and two member functions (execute() and executeQuery())!. Everything else is plain SQL.

Using the code

DarkSide SQL Mini is a source code library. Copy all CPP files in the \dsqlm_1\cpp folder to your projects working directory, add the \dsqlm_1\include directory to your include path, link your object code with dsqlm_1\libdb41s.lib and you are done. You have a nice database system embedded in your application. Now on to some SQL lessons...

First include dsqlm.h in your CPP file:

#include "dsqlm.h"
using namespace dsqlm;

Next create a database object:

Database db("zoo");

This will create the folder zoo, if it does not exist. To create a table, call the CREATE TABLE command.

db.execute("CREATE TABLE animals(name varchar(40) indexed,age int,dob date)");

Data is inserted using the INSERT command:

db.execute("INSERT INTO animals VALUES('Joe',2,'2001-2-20')");

SELECT command is used to search and retrieve data:

ResultSet rslt = db.executeQuery("SELECT * FROM animals WHERE age > 1");
while(rslt.next()) {
  cout << rslt.getString(1) << rslt.getString(3) << endl;
}

The above code will print the name and date of birth of all animals whose age is above 1. In addition to these commands, DarkSide SQL Mini supports DELETE, DROP TABLE, DROP DATABASE and OPTIMIZE commands. The installation contains detailed documentation on the library.

In the demo code, you will find a complete working program that demonstrates the use of various DarkSide SQL commands. Follow the instructions in DarkSide SQL Mini Help files to compile this code.

If you need a complete RDBMS server, you can download DarkSide SQL server for free.

History

  • Created: Nov 23rd, 2003
  • Updated: Nov 27th, 2003: Fixed bug in logical expression parsing.

License

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

About the Author

AnOldGreenHorn



India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralOne Kind Information Sir PinmemberGovindanHari2:17 3 Apr '09  
QuestionAgain bugs sir.... PinmemberGovindanHari2:09 3 Apr '09  
AnswerRe: Again bugs sir.... PinmemberVijay Mathew Pandyalakal2:24 3 Apr '09  
GeneralRe: Again bugs sir.... PinmemberGovindanHari2:58 4 Apr '09  
GeneralRe: Again bugs sir.... PinmemberGovindanHari3:47 4 Apr '09  
Generalerror LNK2005 PinmemberGovindanHari21:37 2 Apr '09  
GeneralRe: error LNK2005 PinmemberVijay Mathew Pandyalakal21:56 2 Apr '09  
Questionerror C2059 PinmemberGovindanHari6:14 2 Apr '09  
AnswerRe: error C2059 PinmemberVijay Mathew Pandyalakal19:27 2 Apr '09  
Questioncompile error PinmemberGovindanHari4:58 2 Apr '09  
AnswerRe: compile error PinmemberVijay Mathew Pandyalakal19:23 2 Apr '09  
GeneralSqlite Pinmembernewmodel4:20 27 Mar '06  
GeneralRe: Sqlite [modified] PinmemberVijay Mathew Pandyalakal15:47 27 Mar '06  
GeneralRe: Sqlite Pinmembernewmodel21:36 27 Mar '06  
GeneralRe: Sqlite PinmemberVijay Mathew Pandyalakal15:25 28 Mar '06  
I was talking in the context of how databases normally interprets the term "type". If u r so keen on sqlite, the article at the following link might interest u:
http://www.codeproject.com/database/embedded_db_cpp.asp
Generalsource code of the library: libdb41s.lib Pinmemberozmanothman16:04 9 Nov '04  
GeneralRe: source code of the library: libdb41s.lib PinmemberVijay Mathew Pandyalakal16:35 9 Nov '04  
GeneralRe: source code of the library: libdb41s.lib Pinmemberozmanothman3:50 10 Nov '04  
Generalwarning massage Pinmemberozmanothman9:37 6 Nov '04  
GeneralRe: warning massage PinmemberVijay Mathew Pandyalakal16:49 7 Nov '04  
Question.net assembly? Pinmemberarachno7:39 5 Nov '04  
AnswerRe: .net assembly? PinmemberVijay Mathew Pandyalakal16:36 5 Nov '04  
GeneralCompile error PinmemberChong Ching Yu20:16 6 Jan '04  
GeneralRe: Compile error PinmemberVijay Mathew Pandyalakal0:42 8 Jan '04  
GeneralRe: Compile error PinmemberChong Ching Yu16:31 8 Jan '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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