예제 #1
0
int Classifier::validateRecord(TableRow record) // private
{
	int required_num_of_attributes = relation_obj.getNumOfAttributes();

	if (record.size() != required_num_of_attributes)
		return RECORD_SIZE_ERROR;

	for (int i = 0; i < required_num_of_attributes; i++)

		if (relation_obj[i].type == AttributeType::NUMERIC)
		{
			try 
			{
				stof(record[i]); // parse number
			}
			catch (invalid_argument e) {
				return ATTRIBUTE_TYPE_MISMATCH_ERROR;
			}
		}
		else if (relation_obj[i].type == AttributeType::DATE)
		{
			// implement
		}

	return 0;
}
예제 #2
0
// get user prompts for table fields and add a new row
// to a table, with an auto-incremented id. 
void CreateInTable(TableDefinition Def, char* Table, char* key){
	
	string name, val;
	
	DB.UseTableDefinition(Def);
	//cout << "key: " << key;

	TableRow Columns = DB.GetColumnsForTable(Table); // get all the columns
	TableDataSet NewDataSet;

	for(unsigned int i=0; i<Columns.size(); i++){

		if(Columns[i] == key){
		 
			 int maxID = DB.GetMaxField(Table, key);
			 int newID = maxID+1;

			 stringstream ID("");
			 ID << newID;

			 NewDataSet.push_back(make_pair(key, (char*)ID.str().c_str()));
		}
		else{

			cout << Columns[i] << ": ";
		
			getline(cin, val);
		
			FieldDefinition WorkingFieldDefinition = DB.GetFieldDefinition((char*)Columns[i].c_str());

			if((WorkingFieldDefinition.getLength() > 0) && (WorkingFieldDefinition.Validate((char*)val.c_str()))){
				NewDataSet.push_back(make_pair(Columns[i],val));
			}
			else{
				cout << "validation failed for the field " << WorkingFieldDefinition.getName();
				return;
			}
		}
	}

	DB.Create(Table, NewDataSet);
	DB.ShowTable(Table, NewDataSet);
	return;
}
예제 #3
0
void Table::append_record(const TableRow& new_record) {
    if ( new_record.size() != m_headers.size() ) {
        throw TableMismatchedRecordLength(std::to_string(new_record.size()));
    }
    m_records.push_back(new_record);
}
예제 #4
0
Table::Table(const TableRow& headers) :
    m_headers(headers), m_records(), m_quoted(headers.size()) {
    for ( size_t i = 0; i < m_quoted.size(); ++i ) {
        m_quoted[0] = true;
    }
}