/** * Entry point to the Karana Lightweight SQL Interpreter. */ int main (int argc, char ** argv) { //Handle command-line params for usage etc if (argc == 1) { cout << "\n Karana: Lightweight SQL interpreter: " << endl; cout << "------------------------------------------------" << endl; cout << "Usage:\n Login and then enter SQL queries from the prompt $$" << endl; cout << "End every query with a delimiter ;" << endl; cout << "Do not enter two complete queries in one line." << endl; cout << "Type 'quit' to quit the program." << endl; cout << "------------------------------------------------" << endl; } else { if (argv[1] == "--h" ) { cout << "\n Karana: Lightweight SQL interpreter: " << endl; cout << "------------------------------------------------" << endl; cout << "Usage:\n Login and then enter SQL queries from the prompt $$" << endl; cout << "End every query with a delimiter ;" << endl; cout << "Do not enter two complete queries in one line." << endl; cout << "Type 'quit' to quit the program." << endl; cout << "------------------------------------------------" << endl; } } //Instantiate all major objects cout << "The memory now contains " << mem.getMemorySize() << " blocks" << endl << endl; setDelay(10); //Perform some initial data setup. initial_setup(); // Ask for user to input a query string line = "", query = "", linepart = ""; const char* chars = "\n\t\v\f\r "; size_t delimPosition; //printlogicaltree or printphysicaltree - flags to signify that the user requested to print parse //trees for logical or physical tree int printphysicaltree = 0, printlogicaltree = 0; while (line != "quit" && line != "QUIT") { //Check if there were any unterminated queries from previous line. if (!linepart.empty() && linepart.find_first_not_of(chars) != string::npos) { cout << "Continuing from the line: " << endl << linepart << endl; line = linepart + line; linepart = ""; } line = trim(line); delimPosition = line.find_last_of(";"); if (delimPosition == string::npos) { linepart = line; } else if (delimPosition != line.size()) { query = line.substr(0,delimPosition); linepart = line.substr(delimPosition+1); } if (!query.empty()) { if (query == "printlogicaltree") { printlogicaltree = 1; } else if (query == "printphysicaltree") { printphysicaltree = 1; } else { //Loop for each query run_query(query, printlogicaltree, printphysicaltree, 0, false); } cout << endl << "------------------------------------------" << endl; } cout << endl << "$$ "; query = ""; getline(cin, line); } //Perform some final cleanup final_cleanup(); }
int main() { //=======================Initialization========================= cout << "=======================Initialization=========================" << endl; // Initialize the memory, disk and the schema manager MainMemory mem; Disk disk; cout << "The memory contains " << mem.getMemorySize() << " blocks" << endl; cout << mem << endl << endl; SchemaManager schema_manager(&mem,&disk); Schema *schema; disk.resetDiskIOs(); disk.resetDiskTimer(); // Another way to time clock_t start_time; start_time=clock(); // TODO Set up a block here?? //=========================Initialization ends ========================== string line; vector<string> strings; ifstream myfile ("TinySQL_linux.txt"); if(myfile.is_open()) { while(getline (myfile,line)) { //cout << line << '\n'; istringstream f(line); string s; while(getline(f, s, ' ')) { //cout << s << endl; strings.push_back(s); } if(strings[0].compare("CREATE") == 0) { // Creating a schema for the create statement. schema = processCreate(strings); //printSchema(*schema); // Creating the relation with the schema above using schema manager. string relation_name=strings[2]; cout << "Creating table " << relation_name << endl; Relation* relation_ptr=schema_manager.createRelation(relation_name, *schema); //printRelation(relation_ptr); } // TODO Change the command to lower-case and compare else if(strings[0].compare("INSERT") == 0) { cout << "It is an INSERT statement " << endl; processInsert(line, strings, schema_manager); } else if(strings[0].compare("SELECT") == 0) { cout << "It is a SELECT statement " << endl; processSelect(line, strings, schema_manager, &mem); } strings.clear(); } myfile.close(); } else cout << "Unable to open file"; return 0; }