/* Class declaration for the Table class The Table class can be used independently or as part of the MiniDB project. Copyright (C) 2007 Hossein Hakimzadeh Comments and bug fixes can be sent to hhakimza@iusb.edu This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef TABLE_H #define TABLE_H #define FALSE 0 #define TRUE 1 #define ON 1 #define OFF 0 //----------------------------------------------------------------- #include "Data_File.h" #include "Meta_File.h" #include "Index_File.h" class Table { char TableName[256]; Data_File *dta; Meta_File *mta; Index_File *idx; int TotalRecords; // Total number of records in the data file int DeletedRecords; // Deleted records int Verbose; // Verbose flag (ON / OFF) public: Table(char *tablename); // Constructor ~Table(); // Destructor void EraseTable(void); // Erase the table (Meta, Data, and Index files) int CreateTable(char *schema); // Create the schema for the table, create empty data and index files void OpenTable(void); // The table has already been created, just open it. void CloseTable(void); int Insert(char *a_record, unsigned long key); int Delete(unsigned long key); int Update(char *a_new_record, unsigned long key); // Keys must match int SearchByKey(unsigned long key); int SearchByField(char *field_name, char *value); void Print(unsigned long key); // Print the record represented by the KEY. void Print(); // Print the active records in the entire table. void PrintSchema(void); // Format and Print the meta file void Sort(); // Same as reorganize void Reorganize(); // Only keep the ACTIVE records (This also sorts the data) int GetTotalRecords(void); // Get the total number of records in the data file. int GetDeletedRecords(void); // Get the number of deleted records in the table. double GarbageRatio(void); // return DeletedRecords / TotalRecords void CalculateTotalAndDeletedRecords(void); }; #endif