Its good to learn SQLite3

Nowadays most applications avoid using logs and text files to store their logging data and other unencrypted data.  This has be seen by just doing a search for SQLite3.dll in your installation folder. Incase you are wondering what this SQLite is according to their website:
SQLite is a in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. The code for SQLite is in the public domain and is thus free for use for any purpose, commercial or private. SQLite is currently found in more applications than we can count, including several high-profile projects.
Now how do you use it.  You can zero in on files with extension *.db which are the databases of the product to store their logging details.  Also to directly see whats inside the database you can use SQLite browser, which is fast and lite.
[ http://sqlitebrowser.sourceforge.net/ ]
Now comes the part to where you would need to use it in C++
Firstly initialize the dll using the code below:
GetCurrentDirectory( MAX_PATH ,buffer);
SetCurrentDirectory( sDir.c_str());
HMODULE hFile = LoadLibrary( sFile.c_str());
SetCurrentDirectory( buffer);
sFile is the variable to store the sqlite3.dll
Now comes the part to query the datbase and get the results:
firstly declare a typedef as follows in your header:
typedef int (*SQLITE3_OPEN)( const char *filename, sqlite3 **mydatabase );
SQLITE3_OPEN         openDb_Open;
Now you are getting the exported functions, hence show this as follows:
openDb_Open = (SQLITE3_OPEN)GetProcAddress( hFile, (LPCSTR)”sqlite3_open”)) // check for errors when you do this
sqlite3 *inDatabase = NULL; // pointer to the database
if (openDb_Open( sFile.c_str(), &inDatabase) != SQLITE_OK)
return error;
In this way you can open a connection the database

Leave a Reply

Your email address will not be published. Required fields are marked *