Click here to Skip to main content
Click here to Skip to main content

DarkSide SQL Mini Version 1, The embedded database

By , 23 Mar 2006
 

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
No Biography provided

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralOne Kind Information SirmemberGovindanHari3 Apr '09 - 2:17 
Good Evening sir...
 
I found LIBCMT.lib in "libdb41s.lib".
I think the error is coming from this linked library file.
How we change the information in the "libdb41s.lib"?
 
Another information, the error msgs says redefiniton of previous one.
So how to delete the redefinition information contained in the "libdb41s.lib"?
 
GOVINDAN
QuestionAgain bugs sir....memberGovindanHari3 Apr '09 - 2:09 
Good evening to you.
 
Thank you for your kindness sir.But i am sorry to tell that again there will be bugs occured.
Before that I am new to vc++ environment sir.so i dont know where all properties and functions in vc++ such as you said "project properties".
But i tried sir.
I found "use runtime library" dropdown list in "project menu->settings->C/C++ tag->category(code generation)".
If i change to any other options then 2 error messages will be displayed as
 

Compiling...
StdAfx.cpp
d:\program files\microsoft visual studio\vc98\mfc\include\afxver_.h(130) : fatal error C1189: #error : Please use the /MD switch for _AFXDLL builds
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\StdAfx.sbr': No such file or directory
Error executing bscmake.exe.
 
ss.exe - 2 error(s), 0 warning(s).
 
If u think i am distrubing means sorry sir.
 
GOVINDAN
AnswerRe: Again bugs sir....memberVijay Mathew Pandyalakal3 Apr '09 - 2:24 
Hello Govindan,
 
Can you try this? Create a new empty console project. And try to get the stuff compiling with a simple main() function. Then you can start adding MFC support to this. I think there are some conflicts with the dlls used by MFC and the db. I don't use MFC. So I can't give you the most helpful information. BTW, out of curiosity - why are you using MFC while there are many free, protable and much-much better options available? For instance, see these links:
 
http://www.qtsoftware.com/[^]
http://www.wxwidgets.org/[^]
 
thanks,
 
-- Vijay
GeneralRe: Again bugs sir....memberGovindanHari4 Apr '09 - 2:58 
Ok thanks sir.
 
I will manage sir.
 
Once again thanks foryour help sir.
 
GOVINDAN
GeneralRe: Again bugs sir....memberGovindanHari4 Apr '09 - 3:47 
SORRY SIR.....
 
GOVINDAN
Generalerror LNK2005memberGovindanHari2 Apr '09 - 21:37 
Hai sir
 
I am very happy to see ur reply.
 
Many more thanks to u sir.
 
But now i got linking error sir.That is,
 
Linking...
LIBCMT.lib(dosmap.obj) : error LNK2005: __errno already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMT.lib(strcat.obj) : error LNK2005: _strcpy already defined in msvcrtd.lib(MSVCRTD.dll)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __unlink already defined in LIBCMT.lib(unlink.obj)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in LIBCMT.lib(mbctype.obj)
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/ss.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating temporary file "C:\DOCUME~1\Govindan\LOCALS~1\Temp\RSP2C4.tmp" with contents
[
/nologo /o"Debug/ss.bsc"
".\Debug\StdAfx.sbr"
".\Debug\ss.sbr"
".\Debug\ssDlg.sbr"
".\Debug\update.sbr"
".\Debug\bdb_index.sbr"
".\Debug\bridge.sbr"
".\Debug\cmpr.sbr"
".\Debug\createtable.sbr"
".\Debug\delete.sbr"
".\Debug\dsql_m_structs.sbr"
".\Debug\insert.sbr"
".\Debug\mydate.sbr"
".\Debug\mytime.sbr"
".\Debug\rec.sbr"
".\Debug\select.sbr"
".\Debug\sql_lexer.sbr"
".\Debug\sql_utils.sbr"
".\Debug\text.sbr"
".\Debug\unique.sbr"]
Creating command line "bscmake.exe @C:\DOCUME~1\Govindan\LOCALS~1\Temp\RSP2C4.tmp"
Creating browse info file...
 
GOVINDAN
GeneralRe: error LNK2005memberVijay Mathew Pandyalakal2 Apr '09 - 21:56 
Hi Govindan,
 
Try changing the 'Runtime library' in project properties C/C++ section.
 
-- Vijay
Questionerror C2059memberGovindanHari2 Apr '09 - 6:14 
I got the following errors
 
Command Lines
Creating temporary file "C:\DOCUME~1\Govindan\LOCALS~1\Temp\RSP87.tmp" with contents
[
/nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR"Debug/" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
"D:\My Programs\My Works\Quash Lab\bdb_index.cpp"
]
Creating command line "cl.exe @C:\DOCUME~1\Govindan\LOCALS~1\Temp\RSP87.tmp"
Output Window
Compiling...
bdb_index.cpp
d:\my programs\my works\quash lab\dsql_m_structs.h(44) : error C2059: syntax error : 'constant'
d:\my programs\my works\quash lab\dsql_m_structs.h(44) : error C2143: syntax error : missing ';' before '}'
d:\my programs\my works\quash lab\dsql_m_structs.h(45) : error C2377: 'INT' : redefinition; typedef cannot be overloaded with any other symbol
d:\program files\microsoft visual studio\vc98\include\windef.h(161) : see declaration of 'INT'
d:\my programs\my works\quash lab\dsql_m_structs.h(45) : error C2377: 'FLOAT' : redefinition; typedef cannot be overloaded with any other symbol
d:\program files\microsoft visual studio\vc98\include\windef.h(145) : see declaration of 'FLOAT'
d:\my programs\my works\quash lab\dsql_m_structs.h(45) : error C2377: 'DOUBLE' : redefinition; typedef cannot be overloaded with any other symbol
d:\program files\microsoft visual studio\vc98\include\wtypes.h(377) : see declaration of 'DOUBLE'
d:\my programs\my works\quash lab\dsql_m_structs.h(45) : error C2377: 'CHAR' : redefinition; typedef cannot be overloaded with any other symbol
d:\program files\microsoft visual studio\vc98\include\winnt.h(134) : see declaration of 'CHAR'
d:\my programs\my works\quash lab\dsql_m_structs.h(46) : error C2377: 'DATE' : redefinition; typedef cannot be overloaded with any other symbol
d:\program files\microsoft visual studio\vc98\include\wtypes.h(1019) : see declaration of 'DATE'
d:\my programs\my works\quash lab\dsql_m_structs.h(46) : error C2377: 'BOOL' : redefinition; typedef cannot be overloaded with any other symbol
d:\program files\microsoft visual studio\vc98\include\windef.h(142) : see declaration of 'BOOL'
d:\my programs\my works\quash lab\dsql_m_structs.h(97) : error C2143: syntax error : missing ';' before '*'
d:\my programs\my works\quash lab\dsql_m_structs.h(97) : error C2501: 'Database' : missing storage-class or type specifiers
d:\my programs\my works\quash lab\dsql_m_structs.h(97) : error C2501: 'db' : missing storage-class or type specifiers
d:\my programs\my works\quash lab\dsql_m_structs.h(101) : error C2629: unexpected 'class Table ('
d:\my programs\my works\quash lab\dsql_m_structs.h(101) : error C2238: unexpected token(s) preceding ';'
d:\my programs\my works\quash lab\dsql_m_structs.h(149) : error C2143: syntax error : missing ';' before '}'
d:\my programs\my works\quash lab\dsql_m_structs.h(149) : error C2143: syntax error : missing ';' before '}'
d:\my programs\my works\quash lab\dsql_m_structs.h(149) : error C2143: syntax error : missing ';' before '}'
d:\my programs\my works\quash lab\text.h(39) : error C2143: syntax error : missing ';' before '{'
d:\my programs\my works\quash lab\text.h(39) : error C2447: missing function header (old-style formal list?)
d:\my programs\my works\quash lab\bdb_index.cpp(197) : error C2065: 'Text' : undeclared identifier
d:\my programs\my works\quash lab\bdb_index.cpp(197) : error C2146: syntax error : missing ';' before identifier 'text'
d:\my programs\my works\quash lab\bdb_index.cpp(197) : error C2065: 'text' : undeclared identifier
d:\my programs\my works\quash lab\bdb_index.cpp(199) : error C2228: left of '.trim' must have class/struct/union type
d:\my programs\my works\quash lab\bdb_index.cpp(222) : error C2146: syntax error : missing ';' before identifier 'text'
d:\my programs\my works\quash lab\bdb_index.cpp(223) : error C2228: left of '.trim' must have class/struct/union type
Error executing cl.exe.
 

 
Results
bdb_index.obj - 24 error(s), 0 warning(s)
 

what can i do?
please help me.....
 
GOVINDAN
AnswerRe: error C2059memberVijay Mathew Pandyalakal2 Apr '09 - 19:27 
If you are using MFC, then you will have to change the names of type definitions like INT, FLOAT, BOOL etc. Change them to something like DSQL_INT, DSQL_FLOAT, DSQL_BOOL etc.
Questioncompile errormemberGovindanHari2 Apr '09 - 4:58 
Hai.....
It is pleasure to contact with u.
i used ur code in my project.
My project is based on MFC dialog.
I performed following steps.
 
1.Add all cpp files and .h files to my project.
2.Project->Settings->in Object\Library modules i typed libdb41s.lib and i also copy this file to my project folder.
 
if i build then the error message as "unexpected end of file while looking for precompiled header directive" from all the cpp files.
 
please help me.
 
GOVINDAN

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

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