Click here to Skip to main content
15,879,326 members
Articles / Database Development / SQL Server
Article

DarkSide SQL Mini Version 1, The embedded database

Rate me:
Please Sign up or sign in to vote.
3.50/5 (27 votes)
23 Mar 2006BSD2 min read 156.4K   2.9K   57   56
An embedded database library in C++.

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


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Compile error Pin
AnOldGreenHorn9-Jan-04 3:33
AnOldGreenHorn9-Jan-04 3:33 
QuestionDarkSide Server Link? Pin
lbills6-Jan-04 2:11
lbills6-Jan-04 2:11 
AnswerRe: DarkSide Server Link? Pin
AnOldGreenHorn8-Jan-04 0:39
AnOldGreenHorn8-Jan-04 0:39 
Generalcompile errors Pin
Rene De La Garza2-Jan-04 5:45
Rene De La Garza2-Jan-04 5:45 
GeneralRe: compile errors Pin
AnOldGreenHorn3-Jan-04 0:49
AnOldGreenHorn3-Jan-04 0:49 
GeneralCompile Error Pin
Gilfrog13-Dec-03 9:29
Gilfrog13-Dec-03 9:29 
GeneralRe: Compile Error Pin
AnOldGreenHorn18-Dec-03 1:46
AnOldGreenHorn18-Dec-03 1:46 
QuestionWhere? Pin
Dewey Vozel10-Dec-03 3:20
Dewey Vozel10-Dec-03 3:20 
AnswerRe: Where? Pin
AnOldGreenHorn11-Dec-03 18:06
AnOldGreenHorn11-Dec-03 18:06 
GeneralRe: Where? Pin
Dewey Vozel12-Dec-03 2:38
Dewey Vozel12-Dec-03 2:38 
QuestionWhat is the source of the library? Pin
Bill Seddon9-Dec-03 21:00
Bill Seddon9-Dec-03 21:00 
AnswerRe: What is the source of the library? Pin
AnOldGreenHorn11-Dec-03 18:10
AnOldGreenHorn11-Dec-03 18:10 
GeneralRe: What is the source of the library? Pin
TimSmith_S12-Jan-04 9:04
TimSmith_S12-Jan-04 9:04 
GeneralRe: What is the source of the library? Pin
AnOldGreenHorn12-Jan-04 17:18
AnOldGreenHorn12-Jan-04 17:18 
AnswerRe: What is the source of the library? Beware License Pin
Neville Franks9-Mar-04 23:39
Neville Franks9-Mar-04 23:39 
GeneralLink not accessible Pin
Perry Bruins2-Dec-03 19:35
Perry Bruins2-Dec-03 19:35 
GeneralUNICODE support Pin
João Paulo Figueira1-Dec-03 4:32
professionalJoão Paulo Figueira1-Dec-03 4:32 
GeneralRe: UNICODE support Pin
AnOldGreenHorn1-Dec-03 18:12
AnOldGreenHorn1-Dec-03 18:12 
GeneralRe: UNICODE support Pin
Johann Gerell1-Dec-03 22:50
Johann Gerell1-Dec-03 22:50 
GeneralRe: UNICODE support Pin
AnOldGreenHorn4-Dec-03 0:29
AnOldGreenHorn4-Dec-03 0:29 
GeneralRe: UNICODE support Pin
Uwe Keim4-Dec-03 22:21
sitebuilderUwe Keim4-Dec-03 22:21 
GeneralA similar library exists: SQLite - An Embeddable SQL Database Engine Pin
Olan Patrick Barnes1-Dec-03 4:29
Olan Patrick Barnes1-Dec-03 4:29 
GeneralReally contructive ! Pin
Emilio Garavaglia1-Dec-03 22:02
Emilio Garavaglia1-Dec-03 22:02 
GeneralRe: Really contructive ! Pin
Olan Patrick Barnes2-Dec-03 2:38
Olan Patrick Barnes2-Dec-03 2:38 
GeneralRe: Really contructive ! Pin
AnOldGreenHorn4-Dec-03 0:33
AnOldGreenHorn4-Dec-03 0:33 

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

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