Click here to Skip to main content
13,143,637 members (34,125 online)
Click here to Skip to main content
Articles » Database » Database » General » Downloads


56 bookmarked
Posted 30 Nov 2003

DarkSide SQL Mini Version 1, The embedded database

, 23 Mar 2006
An embedded database library in C++.
Copyright 2000 - 2003 LogicMatrix. All rights reserved. 

This software is distributed under the LogicMatrix Free Software License. This software may be used for any purpose, personal or commercial. Redistributions in binary /source code form are permitted. Commercial redistribution of larger works derived from, or works which bundle this software requires a "Commercial Redistribution License" which can be purchased from LogicMatrix. Contact LogicMatrix for details

Redistributions qualify as Free and non-commercial under one of the following terms:

1) Redistributions are made at no charge beyond the reasonable cost of materials and delivery.
2) Redistributions in binary/source code form must reproduce this Copyright Notice,these license terms, and the disclaimer/limitation of liability set forth as below, in the documentation and/or other materials
provided with the distribution.

The Software is provided on an "AS IS" basis. No warranty is
provided that the Software is free of defects, or fit for a
particular purpose. 

Limitation of Liability 
LogicMatrix shall not be liable for any damages suffered by the Licensee or any third party resulting from use of the Software.



  Purpose: Handles SELECT command
	Author: Vijay Mathew Pandyalakal
	Date:	16/11/2003
	Copyright: logicmatrix

#include <string>
#include <vector>
using namespace std;

#include "mydate.h"
using namespace openutils;

#include "dsql_m_structs.h"
#include "bridge.h"
#include "sql_lexer.h"
#include "cmpr.h"
#include "bridge.h"
#include "rec.h"
#include "sql_utils.h"
#include "select.h"
using namespace dsqlm;

Select::Select(const char* sql,Database* db) {
	this->sql = sql;
	if(db == 0) {
		throw DsqlMException("Select.cpp - database not inited");
	m_db = db;

void Select::setSql(const char* sql) {
	this->sql = sql;

ResultSet Select::parse() {
	SQLLexer lexer(sql.c_str());
	vector<string> vct = lexer.tokenize();	
	int tsz = vct.size();	
	if(tsz < 4) {
		char buff[50];
		sprintf(buff,"Invalid SELECT statement %d",tsz);
		throw DsqlMException(buff);
	string s = vct[0];
	if(strcmpi(s.c_str(),"SELECT") != 0) {
		throw DsqlMException("Not a select statement");
	SQLUtils utils(m_db);
	int fi = utils.findPos(vct,"FROM");
	if(fi <= 1) {
		throw DsqlMException("FROM not found where expected");
	s = vct[fi+1];	
	Table table(s.c_str(),m_db);;
	ResultSet rslt(table,m_db);
	vector<Column> vct_cols;
	s = vct[1];	
	if(s == "*") {
		int num_cols = table.getNumberOfColumns();
		for(int i=0;i<num_cols;i++) {
	}else {
		TokenType tt = ANY;
		for(int i=1;i<fi;i++) {
			s = vct[i].c_str();
			if(tt == ANY) {
				tt = COMMA;
			}else if(tt == COMMA) {
				if(s != ",") {
					throw DsqlMException("Expected comma");
				tt = ANY;
	vector<long> vct_pos;
	if(tsz == (fi+2)) { // no WHERE clause
		Rec rec(&table,m_db);
		long pos = 0;
		while( {
			if(rec.isDeleted()) {
			}else {
	}else {
		int idx = fi+2;
		s = vct[idx];
		if(strcmpi(s.c_str(),"WHERE") != 0) {
			throw DsqlMException("Expected WHERE clause not found");
		TokenType tt = ID;		
		vector<Column> vct_cols;
		vector<ComparissonOperator> vct_coprs; 
		vector<string> vct_vals;
		vector<LogicalOperator> vct_loprs;
		SQLUtils utils(m_db);
		for(int i=idx;i<tsz;i++) {
			s = vct[i];
			if(tt == ID) {
				Column col = table.getCol(s.c_str());
				tt = COPR;
			}else if(tt == COPR) {
				tt = ANY;
			}else if(tt == ANY) {
				tt = LOPR;
			}else if(tt == LOPR) {
				tt = ID;
			}else {
				char err_buff[50];
				sprintf(err_buff,"Unexpected token at %d",(i+1));
		Cmpr cmpr(&table,m_db,vct_cols,vct_coprs,vct_vals,vct_loprs);;
		long csz = cmpr.getCursorLength();
		Rec rec(&table,m_db);
		for(long k=0;k<csz;k++) {			
			if(rec.isDeleted(cmpr.getPos(k))) {
	return rslt;

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.


This article, along with any associated source code and files, is licensed under The BSD License


About the Author

No Biography provided

You may also be interested in...

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