Getting started with the BangDB for windows native

Download

Please download the BangDB for windows native file and un-compress it using 7zip. If you don't have 7zip then you can get it from 7zip-org. Ensure that you download the file for right OS architecture(32/64bit)

The download files are (once un-compressed):

  • include folder - This contains all the headers and soruce files needed to build app
  • bangdbwin.dll - The BangDB dll for nativ windows
  • bangdbwin.lib - The BangDB lib file
  • bangdbwin.exp - The BangDB exported functions file
  • bangdb.config - The config file for BangDB
  • README.txt - General info for the db and the release
  • TestBangDB-CPP - folder containing sample test files and VS solution ready to run

Install

Store the un-compressed files and folder wherever you like. You can also create path variable for the BangDB directory for easy access but this is not rquired. There is no separate install file for the binary.

Running sample test file

The above download also contains the test app folder which has Visual Studio solution and project file as well. The test app has been built using VS 2012, but it can be run using previous VS as well. If you are unable to open the VS solution/project file then you need to start from scratch.

Note that if you have created db without specifying the dbPath (the location where the db will keep it's data) then db will use the location provided in the config file. Either edit config file to put the dir loc (SERVER_DIR config) or provide it through the API. If the location provided in the config file by default (c:\\BangDBData) is not available on the disk then test will fail. The test app does require that you create c:\BangDBData folder on your disk

To build an application for BangDB from scratch, below are the steps to create an application using Visual Studio

  • Create VC++ console project using your Visual Studio
  • Change the config to target x64 or x86 based on whether you would like the app for 64 bit or 32 bit respectively
  • Copy and paste the .h and .cpp files present in the TestBangDB-CPP folder. Also copy the include folder in the project base dir
  • Add the .h and .cpp files present in th TestBangDB-CPP folder. Also add the .h and .cpp files present in the include dir (by right clicking the solution then add --> existing items)
  • Copy the bangdbwin.dll, bangdbwin.lib and bangdbwin.exp files in the project root/base folder
  • Add the folder where you have kept the dll/lib, not required if these are present in the project dir. you cand add like this (Project-->Properties-->Configuration-->C/C++-->General-->Additional Include Dir)
  • Finally link the lib (bangdbwin.lib) in the project (Project-->Configuration-->C/C++-->Linker-->Input-->Additional Dependencies), type in bangdbwin.lib in the place
  • If you get pre compiled header error then disable them from project-->properties-->C/C++-->Precompiled Headers
  • If you are building for 32 bits, then enable the LARGEADDRESSAWARE (project-->properties-->Linker->System->Enable Large Addresses), this is not required for 64 bit

The above is not required if you are able to open the solution/project file given in the TestBangDB-CPP dir

Project should build now. You should now be able to run the test. To put and get 1,000,000 items using 4 threads, issue the command (or set the command line arg in VS) like following;


	# to run with default command arguments
	c:\project_dir>\x64\Release\TestBangDB-CPP.exe
	
	# with command arguments
	c:\project_dir>\x64\Release\TestBangDB-CPP.exe 4 1000000 put
	
	c:\project_dir>\x64\Release\TestBangDB-CPP.exe 4 1000000 get
	
	# etc...
	
	#--------------------------------------------------------------------------------------------------
	#usage: exe num_threads num_items ops - put/get/all/overlap> [factor(optional, define only with overlap)]
	#--------------------------------------------------------------------------------------------------
	

Sample Code

Below is sample code to do some simple operations using BangDB. The bangdb.config file defines many configurable parameters, but most importantly edit the following values based on your liking;

  • SERVER_DIR - This is basically the location where the db will keep its files. You can also specify it while creating database using API
  • KEY_SIZE - This is to denote the maximum length of key that you will be using to store values. The min value is 8 bytes, and maximum is dependent upon the PAGE_SIZE defined. however keep it small for better performance
  • BUFF_POOL_SIZE_HINT - The size of the buffer pool

Please look at the document which describes meaning of various parameters in the config file at resources or go to the configuration section for detailed information and explanation


	/* Create db, table and connection */
	database *db = new database((char*)"mydb");
	table *tbl = db->gettable((char*)"mytbl", OPENCREATE);
	if(tbl == NULL)
	{
		printf("Table is NULL, quitting");
		return -1;
	}				
	connection *conn = tbl->getconnection();
	if(conn == NULL)
	{
		printf("Connection is NULL, quitting");
		return -1;
	}		
			
	/* do some operations */
	char *key = "key_1";
	char *val = "This is the test value for key_1";
				
	/* put */
	if(conn->put(key, val, INSERT_UNIQUE) < 0)
		printf("Put error");
					
	/* get */
	char *out = conn->get(key);
	if(out == NULL)
		printf("Get error");
				
	/* update */
	val = "Update value for the test key";
	if(conn->put(key, val, UPDATE_EXISTING) < 0)
		printf("Update error");
					
	/* del */
	if(conn->del(key) < 0)
		printf("Del error");
					
	/* try to get the del key */
	if(conn->get(key) != NULL)
		printf("Got the deleted value, error");
		

Above char* is used for keys and values, however, you can use any arbitrary bytes for keys and values using FDT data type. Look at the general data types for information and usage example for FDT

Later in the section of developing using BangDB, more and advanced details are covered