Click here to Skip to main content
12,396,230 members (67,140 online)
Click here to Skip to main content
Articles » Database » Database » General » Downloads

Stats

126.2K views
2.7K downloads
56 bookmarked
Posted

DarkSide SQL Mini Version 1, The embedded database

, 23 Mar 2006 BSD
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

Share

About the Author

No Biography provided

You may also be interested in...

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