Click here to Skip to main content
15,894,896 members
Articles / Database Development / SQL Server

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 157.8K   2.9K   57  
An embedded database library in C++.
/**
	bridge.h

	Purpose: provide interfaces to DSQLM kernel
			These interfaces are used directly by
			client applications

	Author: Vijay Mathew Pandyalakal
	Date:	16/11/2003
	Copyright: logicmatrix
**/

#ifndef BRIDGE_H_
#define BRIDGE_H_


namespace dsqlm{

	class ResultSet;
	class Table;
	class MyDate;
	class MyTime;	
	class Column;

	class DBIni {
	private:
		float version;
		char cr[20];
		openutils::MyDate date;
	public:
		DBIni() {
			version = 1.0;
			strcpy(cr,"");
		}
		void operator = (DBIni dbini) {
			version = dbini.version;
			strcpy(cr,dbini.cr);
			date = dbini.date;
		}
		float getVersion() {
			return version;
		}
		void setVersion(float ver) {
			version = ver;
		}
		string getCr() {
			return cr;
		}
		void setCr(const char* cr) {
			strcpy(this->cr,cr);
		}
		string getDate() {
			return date.getDate();
		}
		void setDate(const char* dt) {
			date.setDate(dt);
		}
	};

	class Database {
	private:
		bool inited;
		DBIni db_ini;
		string db_name;
	public:
		Database() {
			db_name = "data";
		}
		Database(const char* db) {
			db_name = db;
			init();			
		}		
		long execute(const char* sql);
		ResultSet executeQuery(const char* sql);
		void useDatabase(const char* db) {
			db_name = db;
			init();
		}
		void dropDatabase() {
			char buff[101];
			sprintf(buff,"rd /S /Q %s",db_name.c_str());
			system(buff);
		}
		bool isInited() {
			return inited;
		}
		DBIni getDBInfo() {
			return db_ini;
		}
		string getDBName() {
			return db_name;
		}
	private:
		void init();
	};

	class ResultSet {
	private:
		vector<Column> vct_cols;
		vector<long> vct_cursor;
		Table table;
		Database* m_db;
		long cur_pos;
	public:
		ResultSet();
		ResultSet(Table table,Database* db);
		void setColumns(vector<Column> vct);
		void setCursor(vector<long> vct);
		void setDb(Database* db);
				
		bool next();
		bool prev();
		bool first();
		bool last();
		string getString(int col_num);
		string getString(const char* col_name);
		int getInt(int col_num);
		int getInt(const char* col_name);
		float getFloat(int col_num);
		float getFloat(const char* col_name);
		double getDouble(int col_num);
		double getDouble(const char* col_name);
		long getLong(int col_num);
		long getLong(const char* col_name);
		openutils::MyDate getDate(int col_num);
		openutils::MyDate getDate(const char* col_name);
		//openutils::MyTime getTime(int col_num);
		//openutils::MyTime getTime(const char* col_name);
		bool getBool(int col_num);
		bool getBool(const char* col_name);
		int getColumnCount() {
			return vct_cols.size();
		}
		void operator = (ResultSet rslt);
	};
}
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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