BadgerDB
/afs/cs.wisc.edu/u/j/o/jorgenso/private/cs564/quut/src/main.cpp
00001 #include <sys/types.h>
00002 #include <sys/stat.h>
00003 #include <cstdio>
00004 #include <cstring>
00005 #include <string>
00006 #include <unistd.h>
00007 #include "catalog.h"
00008 #include "utility.h"
00009 #include "filescan.h"
00010 #include "query.h"
00011 #include "sort.h"
00012 #include "exceptions/end_of_file_exception.h"
00013 #include "parser/SqlParser.h"
00014 #include "parser/SqlInterp.h"
00015 
00016 #define NUMBUFS 100
00017 #define TESTREL "testrel"
00018 #define TESTREL2 "testrel2"
00019 
00020 extern FILE *yyin;
00021 extern void parse();
00022 
00023 using namespace badgerdb;
00024 
00025 badgerdb::BufMgr *bufMgr;        // pointer to the buffer manager 
00026 badgerdb::RelCatalog *relCat;    // pointer to the relation catalogs 
00027 badgerdb::AttrCatalog *attrCat;  // pointer to the attribute catalogs
00028 
00029 /*
00030  * Add tuples describing relcat and attrcat to relation catalog and attribute catalog
00031  */
00032 void bootstrapCatalogs()
00033 {
00034   /*
00035    * ADD YOUR CODE HERE
00036   */
00037 
00038   attrCat->flushFile();
00039   relCat->flushFile();
00040 }
00041 
00042 
00043 //Driver program for creating the database
00044 int main(int argc, char *argv[])
00045 {
00046   if( argc < 2 )
00047   {
00048     std::cerr << "Usage: " << argv[0] << " <dbname>" << " <queryfile>" << std::endl;
00049     std::cerr << "<queryfile> is optional" << std::endl;
00050     return 1;
00051   }
00052 
00053   bool newDB = true;
00054 
00055   //Create database subdirectory and chdir there
00056   if(mkdir(argv[1], S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP) < 0)
00057   {
00058     std::cerr << "Using database from last run." << std::endl;
00059     newDB = false;
00060   }
00061 
00062   if(chdir(argv[1]) < 0)
00063   {
00064     perror("chdir");
00065     exit(1);
00066   }
00067 
00068   bufMgr = new BufMgr(NUMBUFS);
00069   relCat = new RelCatalog(bufMgr);
00070   attrCat = new AttrCatalog(bufMgr);
00071 
00072   if(newDB)
00073   {
00074     bootstrapCatalogs();
00075   }
00076 
00077   if(argc > 2)
00078   {
00079     if(!(yyin = fopen (argv[2], "r")))
00080     {
00081       cerr << "Error in opening file: " << argv[2] << endl;
00082       exit (-1);
00083     }
00084   }
00085 
00086   //Launch the command prompt
00087   parse();
00088 
00089   //If quit command not used.
00090   delete relCat;
00091   delete attrCat;
00092   delete bufMgr;
00093 
00094   return 0;
00095 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends