#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <string.h>

#include "MyDB.h"

int main(int argc, char* argv[])
{
	int rc, option;
	
	char dbName[80]; 
	char datafile[80]; 
	char attrNumber[80]; 
	char keyValue[80]; 
	char value[80]; 
	char newValue[80]; 
	bool quitFlag = false;

	while(!quitFlag)
        {	
	cout << "Welcome to MyDB \n
		1  Create Database
		2  Print Database
		3  Record Scan Database
		4  Key Scan Database
		5  Insert Record into Database
		6  Delete Record from Database
		7  Modify Record from Database
                8  Quit this program
		Please enter a Number for a Command." << endl;
		
	cin >> option;
	
	
	switch(option)
	{
		case 1:
			cout << "Please enter name for Database>" <<endl;
			gets(dbName);
		
			cout << "Please enter name for Database data file>" <<endl;
			gets(datafile);
		
			rc = CreateDB( dbName, datafile);
			break;
		
		case 2:
			cout << "Please enter Database name>" << endl;
			gets(dbName);
		
			rc = PrintDB(dbName);
                        getchar();
			break;
		
		case 3:
			cout << "Please enter Database name>" << endl;
			gets(dbName);
		
			cout << "Please enter column number>" << endl;
			gets(attrNumber);
		
			cout << "Please enter value for attribute" << endl;
			gets(value);
		 
			rc = RecordScan(dbName, atoi(attrNumber), value);
			break;
		
		case 4:
			cout << "Please enter Database name>" << endl;
			gets(dbName);
		
			cout << "Please enter value for attribute>" << endl;
			gets(value);
				 
			rc = KeyScan(dbName, value);
			break;	
		
		case 5:
			cout << "Please enter Database name>" << endl;
			gets(dbName);
		
			cout << "Please enter record information here (*formatted*)>" << endl;
			gets(value);
				 
			rc = InsertRecord(dbName, value);
			break;
		
		case 6:
			cout << "Please enter Database name>" << endl;
			gets(dbName);
		
			cout << "Please enter record key of record to be deleted>" << endl;
			gets(value);
				 
			rc = DeleteRecord(dbName, value);
			break;		
		
		case 7:
			cout << "Please enter Database name>" << endl;
			gets(dbName);
		
			cout << "Please value of key to record that will be modified" << endl;
			gets(keyValue);
		
			cout << "Please enter column number>" << endl;
			gets(attrNumber);
		
			cout << "Please enter value for attribute" << endl;
			gets(newValue);
			
			rc = ModifyRecord(dbName, keyValue, atoi(attrNumber), newValue);
			break;
		
		case 8:
                       quitFlag = true;
                       break;
		default:
			cout << "this is not an accepted number, application is terminating" << endl;
	}	
	
	if (rc != 0)
		error(rc);
	}	
}		 
