Ejemplo n.º 1
0
Archivo: core.cpp Proyecto: ravitx/608
void deleteFromTable(string tableName, string whereCondition) {

	if(whereCondition.empty()){
		if(!schemaManager.relationExists(tableName)) {
			cout<<"Illegal Table Name"<<endl;
			return;
		}
		Relation *relation = schemaManager.getRelation(tableName);
		while(relation->getNumOfBlocks())
		relation->deleteBlocks(relation->getNumOfBlocks()-1);
	}
	else {
		Relation *relation = schemaManager.getRelation(tableName);
		for(int i=0;i<relation->getNumOfBlocks();i++) {
			relation->getBlock(i,0);
			Block *block = mainMemory.getBlock(0);
			vector<Tuple> tuples = block->getTuples();
			for(int j=0;j<tuples.size();j++) {
				if(!tuples[j].isNull() && whereConditionEvaluator(whereCondition, tuples[j])) {
					block->nullTuple(j);
				}
			}	
			relation->setBlock(i,0);
		}
	}
}
Ejemplo n.º 2
0
Archivo: core.cpp Proyecto: ravitx/608
void dropTable(string tableName) {

        if(schemaManager.relationExists(tableName)) {
                schemaManager.deleteRelation(tableName);
        }
        else
                cout<<"Table "<<tableName<<" doesn't exist"<<endl;
}
Ejemplo n.º 3
0
Archivo: core.cpp Proyecto: ravitx/608
bool validate(vector<string> tableNames) {

	for(int i=0;i<tableNames.size();i++) {
		if(!schemaManager.relationExists(tableNames[i])) {
			cout<<"Invalid Table Name "<< tableNames[i]<<endl;
			return true;
		}
	}
	return false;
}
Ejemplo n.º 4
0
Archivo: core.cpp Proyecto: ravitx/608
void insertIntoTable(string tableName, vector<string> fieldNames, vector<string> fieldValues) {

        if(!schemaManager.relationExists(tableName)) { 
		cout<<"Illegal Tablename"<<endl;
		return;
	}	
	Relation *relation = schemaManager.getRelation(tableName);
	Tuple tuple = relation->createTuple();
	Schema schema = relation->getSchema();
 	vector<string>::iterator it,it1;	
	for(it = fieldNames.begin(),it1 = fieldValues.begin();it!=fieldNames.end();it++, it1++) {
		string str=*it,str1=*it1;
		str = removeSpaces(str);
		int type = schema.getFieldType(str);
		if(!type) {
			str1 = removeSpaces(str1);
			if(isNumber(str1)) {
				tuple.setField(str,stoi(str1));
			}
			else {
				cout<<"Data type is not supported\n";
				return;
			}
		} 
		else {
			regex exp("\\ *\"(.*)\"");
			cmatch match;
			if(regex_match(str1.c_str(),match,exp)) {
				str1 = match[1];
				if(str1.length()>20) {
					cout<<"Data type is not supported\n";
					return;
				}
				else tuple.setField(str,str1);
			}
			else {
				cout<<"Data type is not supported\n";
				return;
			}
		}
	}
	insertTuple(tableName, tuple);
	cout<<disk.getDiskIOs()<<endl;
}