vector<pair<Attribute, PageIndexType>> Table::getAll(int attrnum) { vector<pair<Attribute, PageIndexType>> result; PageIndexType i = head; while(i != UNDEFINEED_PAGE_NUM) { RecordPage page; page.tableName = TableName; page.pageIndex = i; bm.readPage(page); Tuple tuple; tuple.page = page; tuple.createlist(TableName); tuple.ParseFromRawData(); pair<Attribute, PageIndexType> p; p.first = tuple.list[attrnum]; p.second = i; result.push_back(p); i = page.readnext(); } return result; }
vector<PageIndexType> Table::scanNotEqual(int attrnum, Attribute attribute) { vector<PageIndexType> result; PageIndexType i = head; while (i != UNDEFINEED_PAGE_NUM) { RecordPage page; page.tableName = TableName; page.pageIndex = i; bm.readPage(page); Tuple tuple; tuple.page = page; tuple.createlist(TableName); tuple.ParseFromRawData(); if (tuple.list[attrnum] != attribute) result.push_back(i); i = page.readnext(); } return result; }
vector<Attribute> Table::getTupleAtPage(PageIndexType num) { RecordPage page; page.tableName = TableName; page.pageIndex = num; bm.readPage(page); Tuple tuple; tuple.page = page; tuple.createlist(TableName); tuple.ParseFromRawData(); return tuple.list; }
void Table::printinfo(PageIndexType index) { RecordPage page; page.pageIndex = index; page.tableName = TableName; bm.readPage(page); Tuple tuple; tuple.page = page; tuple.createlist(TableName); tuple.ParseFromRawData(); for(int i = 0; i < tuple.list.size(); i++) { switch(tuple.list[i].type) { case AttributeType::CHAR: for (int j = 0; j < tuple.list[i].length; j++) cout << tuple.list[i].chardata[j]; break; case AttributeType::FLOAT: printf("%.2f", tuple.list[i].floatdata); break; case AttributeType::INT: cout << tuple.list[i].intdata; break; case AttributeType::UNDEFINED:; default: cout << "Type error!" ; break; } cout << "\t\t\t"; } cout << endl; }