Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
Add your own
alternative version

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 DELETE command
	Author: Vijay Mathew Pandyalakal
	Date:	17/11/2003
	Copyright: logicmatrix

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

#include "db_cxx.h"

#include "mydate.h"
using namespace openutils;

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

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

long Delete::parse() {
	SQLLexer lexer(sql.c_str());
	vector<string> vct = lexer.tokenize();
	int tsz = vct.size();
	if(tsz < 3) {
		throw DsqlMException("Not a valid DELETE statement");
	string s = vct[0];
	if(strcmpi(s.c_str(),"DELETE") != 0) {
		throw DsqlMException("Not a valid DELETE statement");
	s = vct[1];
	if(strcmpi(s.c_str(),"FROM") != 0) {
		throw DsqlMException("FROM keyword not found where expected");
	s = vct[2];
	Table table(s.c_str(),m_db);;
	Rec rec(&table,m_db);
	if(tsz == 3) { // no "where" clause
		char filnm[101];
		long filsz = rec.fileLength();
		int reclen = rec.recLength();		
		int cols = table.getNumberOfColumns();
		for(int i=0;i<cols;i++) {
			Column col = table.getCol(i+1);
			if(col.isIndexed() == TRUE || col.isUnique() == TRUE) {
			if(col.getType() == AUTOID) {
		return (long)(filsz/reclen);
	}else { // has a WHERE clause
		s = vct[3];
		if(strcmpi(s.c_str(),"WHERE") != 0) {
			throw DsqlMException("Expected WHERE caluse not found");
		}else if(tsz < 7) {
			throw DsqlMException("Invalid WHERE condition");
		int idx = 4;
		vector<long> vct_pos;
		Copied from select.cpp
		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();
		for(long k=0;k<csz;k++) {

		// actual deletion
		long ret = 0;
		for(long h=0;h<vct_pos.size();h++) {
			long pos = vct_pos[h];;
			if(!rec.isDeleted()) {
				for(int c=0;c<table.getNumberOfColumns();c++) {
					Column col = table.getCol((c+1));
					if(col.isIndexed() == TRUE || col.isUnique() == TRUE) {
						bool uk = false;
						/*if(col.isUnique() == TRUE) {
							uk = true;
						char fil[101];
						BdbIndex index(fil,uk);
						char data[24];
		return ret;

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 23 Mar 2006
Article Copyright 2003 by AnOldGreenHorn
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid