Example #1
0
int
listFields(int argc, char** argv) {
    // parse arguments
    parseArguments(argc, argv);
    string backend = options['t'];
    string indexdir = options['d'];

    // check arguments: indexdir
    if (indexdir.length() == 0) {
        pe("Provide the directory with the index.\n");
        return usage(argc, argv);
    }

    // create an index manager
    IndexManager* manager = getIndexManager(backend, indexdir);
    if (manager == 0) {
        return usage(argc, argv);
    }
    IndexReader* reader = manager->indexReader();
    vector<string> fields = reader->fieldNames();
    vector<string>::const_iterator i;
    for (i=fields.begin(); i!=fields.end(); ++i) {
        printf("%s\n", i->c_str());
    }
    IndexPluginLoader::deleteIndexManager(manager);
    return 0;
}
Example #2
0
void xyzsql_process_insert(insert_stmt *s ) {
    if ( s == NULL )
        s = dynamic_cast<insert_stmt *>(stmt_queue.front().second);

    auto t = catm.exist_relation(s->table_name)->cols;
    if (verify_validation(s->values, t) == false) 
        throw invalid_argument("Uncapatable values");
    
    auto table_info = catm.exist_relation(s->table_name);
    Record r(*(s->values), table_info->cols);

    for(auto x : *(r.table_info)) {
        if(x->flag & (table_column::unique_attr | table_column::primary_attr)) {
            string filename;
            indexIterator cursor;
            int asdf = IndexManager.selectNode(cursor, s->table_name + "/index_" + x->name + ".db", 
                    condition::EQUALTO, r.get_value(x).to_str(x->data_type));
            if (asdf == 0) throw invalid_argument("Unique Key already exists.");
        } 
    }

    int blockNum, offset;
    RecordManager.insertRecord(s->table_name, r, blockNum, offset);
    table_info->inc_size();

    for(auto x : *(r.table_info)) {
        if(x->flag & (table_column::unique_attr | table_column::primary_attr)) {
            IndexManager.insertNode(s->table_name + "/index_" + x->name + ".db", 
                    r.get_value(x->name).to_str(x->data_type) , blockNum, offset);
        } 
    }
}
Example #3
0
int
listFiles(int argc, char** argv) {
    // parse arguments
    parseArguments(argc, argv);
    string backend = options['t'];
    string indexdir = options['d'];

    // check arguments: indexdir
    if (indexdir.length() == 0) {
        pe("Provide the directory with the index.\n");
        return usage(argc, argv);
    }

    // create an index manager
    IndexManager* manager = getIndexManager(backend, indexdir);
    if (manager == 0) {
        return usage(argc, argv);
    }

    IndexReader* reader = manager->indexReader();
    if (arguments.empty())
        listFiles(reader, "");

    for (vector<string>::iterator iter = arguments.begin();
         iter != arguments.end(); ++iter) {
        cout << "indexed files under " << *iter << endl;
        listFiles(reader, *iter);
    }
    
    IndexPluginLoader::deleteIndexManager(manager);
    return 0;
}
Example #4
0
void API::CreateIndex(SQLCreateIndex& statement)
{
	cout << "Creating Index: " << statement.get_index_name() << endl;
	if (current_db_.length() == 0) throw NoDatabaseSelectedException();
	
	Database *db = catalog_m_->GetDB(current_db_);
	if (db->GetTable(statement.get_tb_name()) == NULL) throw TableNotExistException();
	if (db->CheckIfIndexExists(statement.get_index_name()) ) throw IndexAlreadyExistsException();

	IndexManager *im = new IndexManager(catalog_m_, buffer_m_, current_db_);
	im->CreateIndex(statement);
	delete im;
}
Example #5
0
int
get(int argc, char** argv) {
    // parse arguments
    parseArguments(argc, argv);
    string backend = options['t'];
    string indexdir = options['d'];

    // check arguments: indexdir
    if (indexdir.length() == 0) {
        pe("Provide the directory with the index.\n");
        return usage(argc, argv);
    }

    // check arguments: dirs
    if (arguments.size() == 0) {
        pe("'%s' '%s'\n", backend.c_str(), indexdir.c_str());
        pe("Provide one or more files to search.\n");
        return usage(argc, argv);
    }
    
    // create an index manager
    IndexManager* manager = getIndexManager(backend, indexdir);
    if (manager == 0) {
        return usage(argc, argv);
    }
    IndexReader* reader = manager->indexReader();
    QueryParser parser;
    
    for (vector<string>::iterator iter = arguments.begin();
         iter != arguments.end(); ++iter) {
        Query query = parser.buildQuery( "system.location:'"+ *iter + '\'');
        vector<IndexedDocument> matches = reader->query(query, 0, 10);
        if (matches.size() == 0)
            printf ("%s: is not indexed\n", iter->c_str());
        else
        {
            printf ("Information associated to %s:\n", iter->c_str());
            for (vector<IndexedDocument>::iterator it = matches.begin();
                 it != matches.end(); ++it)
            {
                printIndexedDocument(*it);
            }
        }
    }
    
    IndexPluginLoader::deleteIndexManager(manager);
    return 0;
}
Example #6
0
void xyzsql_process_create_table(create_table_stmt *s ) {
    cout << "table created." << endl;
    if ( s == NULL ) {
        s = dynamic_cast<create_table_stmt *>(stmt_queue.front().second);
        for ( auto x : *(s->cols) ) {
            x->name = s->name + "." + x->name;
        }
    }

    catm.add_relation(s);
    catm.write_back();
    RecordManager.createMaster(s->name);
    for(auto x : *(s->cols)) {
        if(x->flag & (table_column::unique_attr | table_column::primary_attr)) {
            IndexManager.createIndex(s->name + "/index_" + x->name + ".db", data_type_to_str(x->data_type), x->str_len, 0,
                    {}, {}, {});
        } 
    }
}
    // gradient computation function for collection with EED boundary
    // conditions
    VectorN EED_collection_gradient(const BpCollection& bp_collection,
                                    const IndexManager& idx_mgr) {

        // dofs gradient
        const StepGradientVec grads =
        imposed_origin_dofs_gradient(bp_collection, idx_mgr);

        // frozen step contributions
        const StepGradientVec frozen_grads =
        add_frozen_steps_contribs(grads, bp_collection, idx_mgr);

        // filtering
        VectorN grad_vec = filter_free_dofs_in_StepGradientVec(frozen_grads,
                                                               idx_mgr);

        // remove dofs related to boundary conditions
        // for EED boundary conditions this corresponds to the last three dofs
        return grad_vec.slice(0,
                              idx_mgr.n_of_free_dofs_variables()-
                              BoundaryConditionsDofsTrimming::EEDCollection);

    };
Example #8
0
void calc_algric_tree(algbric_node *root) {
    if (root->flag == true) 
        return;
    string table_name;
    int blockNum, offset;
    auto new_col_list = new vector<table_column *>, old_col_list = new_col_list, old_col_list2 = new_col_list;
    // auto old_col_list = catm.exist_relation((root->left->table))->cols;

    switch ( root->op ) {
        case algbric_node::DIRECT :
            root->flag = true;
            return;
        case algbric_node::PROJECTION : 
        {
            if (!root->left->flag) calc_algric_tree(root->left);
            old_col_list = catm.exist_relation((root->left->table))->cols;

            for( auto x : *(root->projection_list) ) {
                auto att = catm.exist_relation(x->relation_name)->get_column(x->attribute_name);
                new_col_list->push_back(new table_column((root->left->op == algbric_node::DIRECT ? x->attribute_name.c_str() : x->full_name.c_str()), att->data_type, att->str_len, 0 ));
            }
            table_name = create_temp_table(new_col_list);
            root->table = table_name;

            auto cursor = RecordManager.getCursor(root->left->table, catm.calc_record_size(root->left->table));
            while (cursor->next()) {
                Record r = cursor->getRecord();
                vector<record_value> result;
                for(auto i = new_col_list->begin(); i != new_col_list->end(); i++) {
                    for(auto j = old_col_list->begin(); j != old_col_list->end(); j++ ) {
                        if ( (*i)->name == (*j)->name ) {
                            result.push_back(r.values[j-old_col_list->begin()]);
                        }
                    }
                }
                RecordManager.insertRecord(table_name, Record(result, new_col_list), blockNum, offset);
            }

            if (root->left->op != algbric_node::DIRECT) catm.drop_table(root->left->table);

            root->flag = true;
            return;
        }
        case algbric_node::SELECTION : 
        {
            string left_name = root->left->table;
            old_col_list = catm.exist_relation(left_name)->cols;
            for( auto x : *(old_col_list) ) {
                new_col_list->push_back( new table_column(x->name.c_str(), x->data_type, x->str_len, x->flag ));
            }

            table_name = create_temp_table(new_col_list);
            root->table = table_name;

            condition *p = NULL, *eq = NULL;
            for(auto x : (root->conditions)) {
                if ( catm.is_indexed(x->left_attr) ) {
                    p = x;
                    if (x->op == condition::EQUALTO) 
                        eq = x;
                }
            }

            if ( eq != NULL ) p = eq;

            if ( p != NULL ) {
                cout << "Index used: " << p->left_attr->full_name << endl;
                int record_size = catm.calc_record_size(root->left->table);
                auto t = p->left_attr;
                indexIterator cursor;
                int asdf = IndexManager.selectNode(cursor, t->relation_name + "/index_" + t->attribute_name + ".db", 
                        p->op, (p->v).to_str(catm.get_data_type(t)));
                if ( asdf == 0 ) {
                    int b = 0, c = 0;
                    while (cursor.next(b, c) == 0) {
                        Record a = RecordManager.getRecord(t->relation_name, b, c, record_size);
                        if (calc_conditions(&(root->conditions), a))
                            RecordManager.insertRecord(table_name, a, blockNum, offset);
                    }
                }
            } else {
                string t = root->left->table;
                int record_size = catm.calc_record_size(t);
                indexIterator cursor;
                int asdf = IndexManager.getStarter(cursor, t + "/index_" + catm.get_primary(t) + ".db");
                if ( asdf == 0 ) {
                    int b = 0, c = 0;
                    while (cursor.next(b, c) == 0) {
                        Record a = RecordManager.getRecord(t, b, c, record_size);
                        if (calc_conditions(&(root->conditions), a))
                            RecordManager.insertRecord(table_name, a, blockNum, offset);
                    }
                }
            }

            root->flag = true;
            return;
        }
        case algbric_node::JOIN :
        {
            if (!root->left->flag) calc_algric_tree(root->left);
            if (!root->right->flag) calc_algric_tree(root->right);
            if ( catm.get_size(root->right->table) < catm.get_size(root->left->table) ) {
                auto tmp = root->left;
                root->left = root->right;
                root->right = tmp;
            }

            
            old_col_list = catm.exist_relation((root->left->table))->cols;
            old_col_list2= catm.exist_relation((root->right->table))->cols;

            for( auto x : *old_col_list ) {
                new_col_list->push_back(new table_column(x->name.c_str(), x->data_type, x->str_len, 0 ));
            }

            for( auto x : *old_col_list2 ) {
                new_col_list->push_back(new table_column(x->name.c_str(), x->data_type, x->str_len, 0 ));
            }

            table_name = create_temp_table(new_col_list);
            root->table = table_name;

            auto outter_table = catm.exist_relation(root->left->table), inner_table = catm.exist_relation(root->right->table);
            int outter_size = catm.calc_record_size(root->left->table), inner_size = catm.calc_record_size(root->right->table);
            outter_table->get_size();
            condition * p = NULL;

            for ( auto x : root->conditions ) {
                if ( outter_table->get_column(x->left_attr->full_name) != NULL && inner_table->get_column(x->right_attr->full_name) != NULL) {

                } else if ( inner_table->get_column(x->left_attr->full_name) != NULL && outter_table->get_column(x->right_attr->full_name) != NULL) {
                    auto tmp = x->left_attr;
                    x->left_attr = x->right_attr;
                    x->right_attr = tmp;
                }
                assert( outter_table->get_column(x->left_attr->full_name) != NULL && inner_table->get_column(x->right_attr->full_name) != NULL);

                if ( inner_table->is_indexed(x->right_attr->full_name) ) {
                    p = x;
                }

            }

            auto cursor1 = RecordManager.getCursor(root->left->table, outter_size);

	    cout << "Index used: " << p->right_attr->full_name << endl;
            while (cursor1->next()) {
                Record r1 = cursor1->getRecord();
                if ( p ) {
                    // nested-index join
                    indexIterator a;
                    int asdf = IndexManager.getStarter(a, root->right->table + "/index_" + p->right_attr->full_name + ".db");
                    if (asdf == 0) {
                        int b = 0, c = 0;
                        while (a.next(b, c) == 0) {
                            Record r2 = RecordManager.getRecord(root->right->table, b, c, inner_size);
                            if ( calc_conditions(&(root->conditions), r1, r2) )  {
                                vector<record_value> result(r1.values);
                                result.insert(result.end(), r2.values.begin(), r2.values.end());
                                RecordManager.insertRecord(table_name, Record(result, new_col_list), blockNum, offset);
                            }
                        }
                    }
                } else {
                    // nested-loop join
                    auto cursor2 = RecordManager.getCursor(root->right->table, inner_size);
                    while (cursor2->next()) {
                        Record r2 = cursor2->getRecord();
                        if ( calc_conditions(&(root->conditions), r1, r2) )  {
                            vector<record_value> result(r1.values);
                            result.insert(result.end(), r2.values.begin(), r2.values.end());
                            RecordManager.insertRecord(table_name, Record(result, new_col_list), blockNum, offset);
                        }
                    }
                    delete cursor2;
                }
            }
            delete cursor1;

            if (root->right->op != algbric_node::DIRECT) catm.drop_table(root->right->table);
            if (root->left->op != algbric_node::DIRECT) catm.drop_table(root->left->table);

            root->flag = true;
            return;
        }
    }
}
Example #9
0
void xyzsql_process_delete() {

    auto s = dynamic_cast<delete_stmt *>(stmt_queue.front().second);

    if (s->condition_list->empty()) {
        // delete all
        system(("rm " + s->table_name + "/*.db").c_str());
        RecordManager.createMaster(s->table_name);
        auto table_info = catm.exist_relation(s->table_name);
        auto cols = table_info->cols;
        table_info->set_size(0);
        for(auto x : *cols)
            if(x->flag & (table_column::unique_attr | table_column::primary_attr))
                IndexManager.createIndex(s->table_name + "/index_" + x->name + ".db", data_type_to_str(x->data_type), 
                        x->str_len, 0, {}, {}, {});
    } else {
        auto table_info = catm.exist_relation(s->table_name);
        int record_size = catm.calc_record_size(s->table_name);
        BufferManager.newTrashCan();
        // unique 
        condition *p = NULL, *eq = NULL;
        for(auto x : *(s->condition_list)) {
            if ( catm.is_indexed(x->left_attr) ) {
                p = x;
                if (x->op == condition::EQUALTO) 
                    eq = x;
            }
        }

        if ( eq != NULL || p != NULL ) {
            cout << "Index used: " << p->left_attr->full_name << endl;
            auto t = eq == NULL ? p->left_attr : eq->left_attr;
            if (eq != NULL) p = eq;
            indexIterator a;
            int asdf = IndexManager.selectNode(a, base_addr + "/" + t->relation_name + "/index_" + t->attribute_name + ".db", 
                    p->op, (p->v).to_str(catm.get_data_type(t)));
            if ( asdf == 0 ) {
                int b = 0, c = 0;
                while (a.next(b, c) == 0) {
                    Record a = RecordManager.getRecord(t->relation_name, b, c, record_size);
                    if (calc_conditions(s->condition_list, a))
                        BufferManager.appendTrashCan(b, c);
                }
            }
        } else {
            indexIterator a;
            int asdf = IndexManager.getStarter(a, s->table_name + "/index_" + catm.get_primary(s->table_name) + ".db");
            if (asdf == 0) {
                int b = 0, c = 0;
                while (a.next(b, c) == 0) {
                    Record a = RecordManager.getRecord(s->table_name, b, c, record_size);
                    if (calc_conditions(s->condition_list, a))
                        BufferManager.appendTrashCan(b, c);
                }
            }
        }

        BufferManager.beginFetchTrash();
        int blockNum, offset;
        while(BufferManager.fetchTrash(blockNum, offset)) {
            auto r = RecordManager.getRecord(s->table_name, blockNum, offset, record_size);

            for(auto x : *(r.table_info)) {
                if(x->flag & (table_column::unique_attr | table_column::primary_attr)) {
                    indexIterator cursor;
                    IndexManager.deleteNode(s->table_name + "/index_" + x->name + ".db", r.get_value(x).to_str(x->data_type));
                } 
            }

            RecordManager.deleteRecord(s->table_name, blockNum, offset, record_size);
            table_info->dec_size();
        }
    }
    cout << "records deleted." << endl;
}
Example #10
0
/*
int
xesamquery(int argc, char** argv) {
    // parse arguments
    parseArguments(argc, argv);
    string backend = options['t'];
    string indexdir = options['d'];
    string ulfile = options['u'];
    string qlfile = options['q'];

    // check arguments: indexdir
    if (indexdir.length() == 0) {
        pe("Provide the directory with the index.\n");
        return usage(argc, argv);
    }

    if ((ulfile.length() == 0) && (qlfile.length() == 0)) {
        pe ("Provide at last one file containing the xesam query formulated ");
        pe ("with query language or user language.\n");
        return usage(argc, argv);
    }
    
    if (arguments.size() != 0) {
        pe("You do not have to provide other arguments.\n");
        return usage(argc, argv);
        return 1;
    }

    Xesam2Strigi xesam2strigi;

    if (qlfile.length() != 0) {
        printf ("processing xesam querylanguage query from file %s\n", qlfile.c_str());

        if (xesam2strigi.parse_file ( qlfile, Xesam2Strigi::QueryLanguage))
            printf ("Xesam query parsed successfully\n");
        else
        {
            pe ("error parsing query\n");
            return 1;
        }
    }
    else if (ulfile.length() != 0) {
      printf ("processing xesam userlanguage query from file %s\n", ulfile.c_str());

      if (xesam2strigi.parse_file ( ulfile, Xesam2Strigi::UserLanguage))
        printf ("Xesam query parsed successfully\n");
      else
      {
        pe ("error parsing query\n");
        return 1;
      }

    }
    
    // create an index manager
    IndexManager* manager = getIndexManager(backend, indexdir);
    if (manager == 0) {
        return usage(argc, argv);
    }
    IndexReader* reader = manager->indexReader();

    unsigned int results = 0;
    const uint batchsize = 10;
    Query query = xesam2strigi.query();
    vector<IndexedDocument> matches = reader->query(query, 0, batchsize);

    if (matches.size() != 0) {
        printf ("Search results:\n");
    } else {
        printf ("No results for search\n");
    }

    while (matches.size() > 0) {
        for (vector<IndexedDocument>::iterator it = matches.begin();
            it != matches.end(); ++it) {
                printf ("\"%s\" matched\n", it->uri.c_str());
                printIndexedDocument(*it);
            }

        results += (int)matches.size();

        if (matches.size() == batchsize) {
            // maybe there're other results
            matches = reader->query(query, results + 1, 10);
        } else {
            matches.clear(); // force while() exit
        }
    }

    if (results != 0)
        printf ("Query returned %i results\n", results);

    IndexPluginLoader::deleteIndexManager(manager);
    return 0;
}
*/
int
deindex(int argc, char** argv) {
    // parse arguments
    parseArguments(argc, argv);
    string backend = options['t'];
    string indexdir = options['d'];

    // check arguments: indexdir
    if (indexdir.length() == 0) {
        pe("Provide the directory with the index.\n");
        return usage(argc, argv);
    }

    // check arguments: dirs
    if (arguments.size() == 0) {
        pe("'%s' '%s'\n", backend.c_str(), indexdir.c_str());
        pe("Provide directories/files to deindex.\n");
        return usage(argc, argv);
    }
    
    AnalyzerConfiguration config;
    
    // create an index manager
    IndexManager* manager = getIndexManager(backend, indexdir);
    if (manager == 0) {
        return usage(argc, argv);
    }
    
    // retrieve all indexed files at level 0 (archives contents aren't returned)
    map<string, time_t> indexedFiles;
/* TODO: make this code not use indexReader->files(0)

    IndexReader* indexReader = manager->indexReader();
    indexedFiles = indexReader->files(0);
*/
    vector<string> toDelete;
    
    for (vector<string>::iterator iter = arguments.begin();
         iter != arguments.end(); ++iter)
    {
        // find all indexed files whose path starts with *iter
        FindIndexedFiles match (*iter);
        map<string, time_t>::iterator itBeg, itEnd, itMatch;
        itBeg = indexedFiles.begin();
        itEnd = indexedFiles.end();
        
        itMatch = find_if (itBeg, itEnd, match);
        while (itMatch != itEnd)
        {
            toDelete.push_back (itMatch->first);
            itBeg = ++itMatch;
            itMatch = find_if (itBeg, itEnd, match);
        }
    }
    
    if (toDelete.empty())
        printf ("no file will be deindexed\n");
    else
    {
        for (vector<string>::iterator iter = toDelete.begin();
             iter != toDelete.end(); ++iter)
        {
            printf ("%s will be deindex\n", iter->c_str());
        }
        IndexWriter* writer = manager->indexWriter();
        writer->deleteEntries(toDelete);
        writer->commit();
        writer->optimize();
    }
    
    IndexPluginLoader::deleteIndexManager(manager);
    return 0;
}
Example #11
0
int
query(int argc, char** argv) {
    // parse arguments
    parseArguments(argc, argv);
    string backend = options['t'];
    string indexdir = options['d'];

    // check arguments: indexdir
    if (indexdir.length() == 0) {
        pe("Provide the directory with the index.\n");
        return usage(argc, argv);
    }

    // check arguments: dirs
    if (arguments.size() == 0) {
        pe("'%s' '%s'\n", backend.c_str(), indexdir.c_str());
        pe("Provide one or more files to search.\n");
        return usage(argc, argv);
    }
    
    // create an index manager
    IndexManager* manager = getIndexManager(backend, indexdir);
    if (manager == 0) {
        return usage(argc, argv);
    }
    IndexReader* reader = manager->indexReader();
    QueryParser parser;
    
    for (vector<string>::iterator iter = arguments.begin();
            iter != arguments.end(); ++iter) {
        int results = 0;
        Query query = parser.buildQuery(*iter);
        const uint batchsize = 10;
        vector<IndexedDocument> matches = reader->query(query, 0, batchsize);

        if (matches.size() != 0) {
            printf ("Results for search \"%s\"\n", (*iter).c_str());
        } else {
            printf ("No results for search \"%s\"\n", (*iter).c_str());
        }

        while (matches.size() > 0) {
            for (vector<IndexedDocument>::iterator it = matches.begin();
                 it != matches.end(); it++) {
                printf ("\"%s\" matched\n", it->uri.c_str());
                printIndexedDocument(*it);
            }

            results += (int)matches.size();
            
            if (matches.size() == batchsize) {
                // maybe there're other results
                matches = reader->query(query, results + 1, 10);
            } else {
                matches.clear(); // force while() exit
            }
        }

        if (results != 0) {
            printf ("Query \"%s\" returned %i results\n", (*iter).c_str(),
                                                           results);
        }
    }
    
    IndexPluginLoader::deleteIndexManager(manager);
    return 0;
}
Example #12
0
void Execute()
{	
	int i;
	int j;
	int k;
	Table tableinfor;
	Index indexinfor;
	string tempKeyValue;
	int tempPrimaryPosition=-1;
	int rowCount=0;
	Data data;
	switch(parsetree.m_operation)
	{
	case CRETAB:
		parsetree.getTableInfo.attriNum=parsetree.getTableInfo.attributes.size();
		catalog.createTable(parsetree.getTableInfo);
		record.createTable(parsetree.getTableInfo);
		cout<<"Table "<<parsetree.getTableInfo.name<<" is created successfully"<<endl;
		break;
	case TABLEEXISTED:
		cout<<"CREATE ERROR: Table existed"<<endl;
		break;
	case DRPTAB:
		record.dropTable(parsetree.getTableInfo);
		for(int i = 0; i < parsetree.getTableInfo.attriNum; i++){//���������е�index��ɾ��
			indexinfor = catalog.getIndexInformation(parsetree.getTableInfo.name, i);
			if(indexinfor.index_name != "")
				indexm.dropIndex(indexinfor);
		}
		catalog.dropTable(parsetree.getTableInfo);
		cout<<"Table "<<parsetree.getTableInfo.name<<" is dropped successfully"<<endl;
		break;
	case INSERT:
		tableinfor = parsetree.getTableInfo;
		if(parsetree.PrimaryKeyPosition==-1&&parsetree.UniquePostion==-1){
			record.insertValue(tableinfor, parsetree.row);
			catalog.update(tableinfor);
			cout<<"Insert successfully"<<endl;
			break;
		}
		if(parsetree.PrimaryKeyPosition!=-1)
		{
			data=record.select(tableinfor, parsetree.condition);
			if(data.rows.size()>0){
				cout<<"INSERT ERROR: Primary key redundancy"<<endl;
				break;
			}
		}
		if(parsetree.UniquePostion!=-1){
			
			data=record.select(tableinfor, parsetree.UniqueCondition);
			if(data.rows.size()>0){
				cout<<"INSERT ERROR: Unique value redundancy"<<endl;
				break;
			}
		}
		record.insertValue(tableinfor,parsetree.row);
		catalog.update(tableinfor);
		cout<<"Insert successfully"<<endl;
		break;
	case INSERTERR:
		cout << "Syntax ERROR: Incorrect usage of \"insert\"." << endl;
		break;
	case SELECT_NOWHERE_CAULSE:
		tableinfor = parsetree.getTableInfo;
		data=record.select(tableinfor);
		if(data.rows.size()!=0)
			ShowResult( data, tableinfor, parsetree.column);
		else{
			cout << "No data is found." << endl;
		}
		break;
	case SELECT_WHERE_CAULSE:
		tableinfor=parsetree.getTableInfo;
		if(parsetree.condition.size()==1){
			for(int i=0;i<parsetree.getTableInfo.attributes.size();i++){
		/*�޸�*/if((parsetree.getTableInfo.attributes[i].isPrimeryKey==true||parsetree.getTableInfo.attributes[i].isUnique==true)&&parsetree.m_colname==parsetree.getTableInfo.attributes[i].name){
					tempPrimaryPosition=i;
					indexinfor=catalog.getIndexInformation(tableinfor.name,i);
					break;
				}
			}
			if(tempPrimaryPosition==parsetree.condition[0].columnNum&&parsetree.condition[0].op==Eq&&indexinfor.table_name!=""){
				
				tempKeyValue=parsetree.condition[0].value;
				data= indexm.selectEqual(tableinfor,indexinfor,tempKeyValue);
			}
			else{

				data=record.select(tableinfor,parsetree.condition);
			}
		}
		else{
			data=record.select(tableinfor,parsetree.condition);
		}
		if(data.rows.size()!=0)
			ShowResult( data, tableinfor, parsetree.column);
		else{
			cout << "No data is found." << endl;
		}
		break;
	case DELETE:
		rowCount = record.deleteValue(parsetree.getTableInfo,parsetree.condition);
		cout<< rowCount <<"  tuples are deleted."<<endl;
		break;
	case CREIND:
		indexinfor = parsetree.getIndexInfo;
		tableinfor = parsetree.getTableInfo;
		if(!tableinfor.attributes[indexinfor.column].isPrimeryKey && !tableinfor.attributes[indexinfor.column].isUnique){//����primary key�������Խ�index
			cout << "Column " << tableinfor.attributes[indexinfor.column].name <<"  is not unique."<< endl;
			break;
		}
		catalog.createIndex(indexinfor);
		indexm.createIndex(tableinfor, indexinfor);
		catalog.update(indexinfor);
		cout<<"Index "<< indexinfor.index_name << "is created successfully."<<endl;
		break;
	case INDEXERROR:
		cout<<"ERROR: Index existed."<<endl;
		break;
	case DRPIND:
		indexinfor = catalog.getIndexInformation(parsetree.m_indname);
		if(indexinfor.index_name == ""){
			cout << "ERROR: Index" << parsetree.m_indname << "does not exist!" << endl;
		}
		indexm.dropIndex(indexinfor);
		catalog.dropIndex(parsetree.m_indname);
		cout<<"The index is dropped successfully"<<endl;
		break;
	case CREINDERR:
		cout << "Syntax ERROR: Incorrect usage of \"create index\" query." << endl;
		break;
	case QUIT:
		cout << "Bye Bye~" << endl;
		system("pause");
		exit(0);
		break;
	case EMPTY:
		cout << "Query Empty." << endl;
		break;
	case UNKNOW:
		cout << "Syntax ERROR: Please check your query." << endl;
		break;
	case SELERR:
		cout << "Syntax ERROR: Incorrect usage of \"select\" query." << endl;
		break;
	case CRETABERR:
		cout << "Syntax ERROR: Incorrect usage of \"create table\" query." << endl;
		break;
	case DELETEERR:
		cout << "Syntax ERROR: Incorrect usage of \"delete from\" query." << endl;
		break;
	case DRPTABERR:
		cout << "Syntax ERROR: Incorrect usage of \"drop table\" query." << endl;
		break;
	case DRPINDERR:
		cout << "Syntax ERROR: Incorrect usage of \"drop index\" query." << endl;
		break;
	case VOIDPRI:
		cout << "ERROR: Invalid primary key." << endl;
		break;
	case VOIDUNI:
		cout << "ERROR: Invalid unique key." << endl;
		break;
	case CHARBOUD:
		cout << "ERROR: Too long query. Only 1~255 charactors is allowed." << endl;
		break;
	case NOPRIKEY:
		cout << "ERROR: Please define a primary key." << endl;
		break;
	case TABLEERROR:
		cout << "ERROR: Table is not existed."<<endl;
		break;
	case INDEXEROR:
		cout << "ERROR: Index is not existed."<<endl;
		break;
	case COLUMNERROR:
		cout << "ERROR: Column is not existed"<<endl;
		break;
	case INSERTNUMBERERROR:
		cout << "ERROR: The amount of the columns is not matched."<<endl;
		break;
	}
	
}