void CommandOpen(const char *method, const char *table) { if (numTables == MAX_TABLES) { cout << "This progam can only handle "<<MAX_TABLES<<" open tables.\n"; return; } if (GetTable(table) != NOT_FOUND) { cout << "Table already open!\n"; return; } if (strcmp(method, "btree")) { cerr << "The only supported method is btree.\n"; return; } GiST *gist = new BT; gist->Open(table); if (!gist->IsOpen()) { delete gist; cout << "Error opening table.\n"; return; } cout << "Table " << table << " opened.\n"; tables[numTables].gist = gist; tables[numTables].name = strdup(table); numTables++; }
void CommandInsert(const char *table, const BTkey& key, int ptr) { int i; if ((i = GetTable(table)) == NOT_FOUND) { cerr << "Table not open!\n"; return; } GiST *gist = tables[i].gist; gist->Insert(BTentry(key, ptr)); cout << "(" << key << ", " << ptr << ") inserted into " << table << ".\n"; }
void CommandInsert(const char *table, const BTkey& key, int value) { int i; if ((i = GetTable(table)) == NOT_FOUND) { cerr << "Table not open!\n"; return; } Record* rec = new_in(db, Record); rec->value = value; GiST *gist = tables[i].gist; gist->Insert(BTentry(key, (GiSTpage)rec)); cout << "(" << key << ", " << value << ") inserted into " << table << ".\n"; }
void CommandSelect(const char *table, const GiSTpredicate& pred) { int i; i = GetTable(table); if (i == NOT_FOUND) { cerr << "Table is not open!\n"; return; } GiST *gist = tables[i].gist; GiSTcursor *c = gist->Search(pred); GiSTentry *e; while ((e = c->Next()) != NULL) { cout << e; delete e; } delete c; }
void CommandCreate(const char *method, const char *table) { if (numTables == MAX_TABLES) { cout << "This progam can only handle "<<MAX_TABLES<<" open tables.\n"; return; } if (GetTable(table) != NOT_FOUND) { cerr << "Table already open!\n"; return; } if (strcmp(method, "btree")) { cerr << "The only supported method is btree.\n"; return; } GiST *gist = new BT(db); GiST_POST_Root* root = (GiST_POST_Root*)db.get_root_object(); if (root == NULL) { root = new_in(db, GiST_POST_Root)(db); db.set_root_object(root); } gist->Create(table); if (!gist->IsOpen()) { cout << "Error opening table.\n"; delete gist; return; } cout << "Table " << table << " created as type " << method << ".\n"; tables[numTables].name = strdup(table); tables[numTables].gist = gist; numTables++; }