Example #1
0
bool CheckUnqiueAndPrimaryKey(const TableInfo& table, const std::vector<std::string>& values){
  IndexManager index_manager;
  RecordManager record_manager;
  std::vector<std::string> attributes_to_be_checked;
  attributes_to_be_checked = table.unique();
  attributes_to_be_checked.push_back(table.primary_key());

  for (auto it : attributes_to_be_checked){
    int attribute_index = table.attribute_index(it);

    if (!table.attribute(it).index_names().empty()){//has index
      std::string index_name = table.attribute(it).index_names().at(0);
      IndexInfo index_info(index_name, table.table_name(), it);
      if (index_manager.FindValue(table,index_info,values.at(attribute_index))){ // has value
        return false;
      }
    }
    else{
      WhereClause where;
      where.kColumnName = it;
      where.kOperator ="=";
      where.kCondition = values.at(attribute_index);
      if (!record_manager.FindRecordsWithNoIndex(table,where).empty()){
        return false;
      }
    }
  }
  return true;
}