Getting Started - Bangdb Embedded

The Bangdb comes as library (both static and dynamic) to be installed on the machine where user would like to run applications which will use embeddable Bangdb. The installation of Bangdb is simple and clean. The installer would just copy the library in /usr/local/lib folder, it will also create the soft links as required. The installer would then copy the headers in the /usr/local/include/bangdb/ dir. It will also create a bangdb group on the machine and add the user to it. The UN-installer would simply remove the library and the soft links, the header files and delete the bangdb group. Hence the UN-installation is pretty clean in that sense

To get the latest version of the library, please download it from here. Please see the README for relevant information on the product

To get started, here is a sample code for simple operations. Note that to use Bangdb from the applications, please include database.h file, that's all

	#include <bangdb/database.h>

	//create database, table and connection 
	database* db = new database((char*)"userdb"); 
	short dbtype = EMBED_INMEM_PERSIST, idxtype = EXTHASH, walog = 1; 
	//get a table, a new one or existing one, walog tells if log is on or off 
	table* tbl = db->gettable((char*)"userinfo", 0); 
	if(tbl == NULL) 
		printf("ERROR:table NULL error"); exit(-1); 
	//get a new connection 
	connection* conn = tbl->getconnection(); 
	if(conn == NULL) 
		printf("ERROR:connection NULL error"); exit(-1); 
	//data type to be used 
	FDT *fk, *fv, *fout; 
	const char *key = "my_key_", *val = "my val", *val2 = "my new val"; 
	//create FDT type with key and val 
	fk = new FDT((void*)key, strlen(key)); 
	fv = new FDT((void*)val, strlen(val)); 
	int retval = 0; 
	//now insert 
	if((retval = conn->put(fk, fv, INSERT_UNIQUE)) < 0) 
		printf("error in insert\n"); 
	else if(retval == 1) 
		printf("key already exists\n"); 
	//get the val 
	if((fout = conn->get(fk)) == NULL) 
		printf("error in get\n"); 
	else if(strncmp((char*)fout->data, val, strlen(val) != 0)) 
		printf("mismatch in get\n"); 
	//release fout 
	if(fout) fout->free(); delete fout; 
	//update key 
	delete fv; 
	fv = new FDT((void*)val2, strlen(val2)); 
	if((retval = conn->put(fk, fv, UPDATE_EXISTING)) < 0) 
		printf("error in update\n"); 
	//delete key 
	if((retval = conn->del(fk)) < 0) 
		printf("error in delete\n"); 
	//clean up 
	delete fv; delete fk; 
	//close database, this cleans every other resources (table, conn, etc...) 
	db->closedatabase(); delete db; 

NOTE: we can do all for char* type as well instead of FDT if we want to, APIs are same but they take char* instead of FDT*

Also in case of char* since we don't create FDT type hence no clean up is needed for keys and values, but in case of FDT clean up is the responsibility of the developer

Please get the getting started document and other whitepapers from Resources Download Section