Ejemplo n.º 1
0
void repl() {
  SqlParser parser;
  while (true) {
    std::string command = read_command();
    std::string::size_type first_space = command.find_first_of(" ");
    std::string fst_token = first_space == string::npos ? command : command.substr(0, first_space);
    capitalize(&fst_token);

#ifdef MAIN_DBG
    Utils::info("[REPL] execute \"" + command +"\"");
#endif
    if (fst_token.compare("QUIT") == 0 || fst_token.compare("EXIT") == 0) {
      return;
    } else if (fst_token.compare("PURGE") == 0) {
      BufferManager &bm = BufferManager::get_instance();
      bm.purge();
      std::cout << "Purge has been done" << std::endl;
    } else if (fst_token.compare("BMST") == 0) {
      std::cout << "BufferManager state:" << std::endl;
      std::cout << "  Pinned pages: " + std::to_string(BufferManager::get_instance().get_pinned_page_count()) << std::endl;
      BufferManager::get_instance().print_pinned_page();
    } else if (fst_token.compare("ABOUT") == 0) {
      std::string table_name = command.substr(6);
#ifdef MAIN_DBG
      Utils::info("[REPL] 'about' was called for " + table_name);
#endif
      describe_table(table_name);
    } else {
      SqlStatement const * stmt = parser.parse(command);

      DBFacade::get_instance()->execute_statement(stmt);
      delete stmt;
    }
  }
}
Ejemplo n.º 2
0
  void test_createindex()
  {
    cout << "Begining create index test ... " << endl;
    std::string sqlbuf = "CREATE  INDEX test1_idx ON tpch.nation (n_nationkey)";
    cout << sqlbuf << endl;
 
    SqlParser parser;
    parser.Parse(sqlbuf.c_str());
    if (parser.Good())
      {
	const ParseTree &ptree = parser.GetParseTree();

        cout << "Parser succeeded." << endl;
        cout << ptree.fList.size() << " " << "SQL statements" << endl;
        cout << ptree.fSqlText << endl;

	try
	  {
	    CreateIndexProcessor processor;
	    processor.setDebugLevel(CreateIndexProcessor::VERBOSE);
	    SqlStatement &stmt = *ptree.fList[0];
	    CreateIndexProcessor::DDLResult result;
	    DISPLAY(stmt.fSessionID);

	    result = processor.processPackage(dynamic_cast<CreateIndexStatement&>(stmt));

	    std::cout << "return: " << result.result << std::endl;
	  }
	catch(...)
	  {
	    throw;
	  }
      }
  }
Ejemplo n.º 3
0
  void test_altertable_addtablenullconstraint()
  {
//sql syntax error?  (Does not build index test.)
    cout << "Begining Alter Table add table not null constraint test ... " << endl;
    std::string sqlbuf = "ALTER TABLE tpch.region add CONSTRAINT not null(r_regionkey);";
    cout << sqlbuf << endl;

    SqlParser parser;
    parser.Parse(sqlbuf.c_str());
    if (parser.Good())
      {
	const ParseTree &ptree = parser.GetParseTree();
	cout << ptree.fSqlText << endl;
	try
	  {
	    AlterTableProcessor processor;
	    processor.setDebugLevel(AlterTableProcessor::VERBOSE);

	    SqlStatement &stmt = *ptree.fList[0];
	    AlterTableProcessor::DDLResult result;

	    result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
	    std::cout << "return: " << result.result << std::endl;
	  }
	catch(...)
	  {
	    throw;
	  }
      }
  }
Ejemplo n.º 4
0
  void test_altertable_addtableconstraint(std::string& sqlbuf)
  {
    cout << "Begining Alter Table add table constraint test ... " << endl;
    cout << sqlbuf << endl;

    SqlParser parser;
    parser.Parse(sqlbuf.c_str());
    if (parser.Good())
      {
	const ParseTree &ptree = parser.GetParseTree();
	cout << ptree.fSqlText << endl;
	try
	  {
	    AlterTableProcessor processor;
	    processor.setDebugLevel(AlterTableProcessor::VERBOSE);

	    SqlStatement &stmt = *ptree.fList[0];
	    AlterTableProcessor::DDLResult result;
		
	    result = processor.processPackage(dynamic_cast<AlterTableStatement&>(stmt));
	    std::cout << "return: " << result.result << std::endl;
	  }
	catch(...)
	  {
	    throw;
	  }
      }
  }
Ejemplo n.º 5
0
    void test_createtabletest(const string& sqlbuf)
    {
	cout << "Begining create table test: " << sqlbuf << endl;
        SqlParser parser;
        parser.Parse(sqlbuf.c_str());
        if (parser.Good())
        {
            const ParseTree &ptree = parser.GetParseTree();
	    cout << ptree.fSqlText << endl;
            try
            {
                CreateTableProcessor processor;
                processor.setDebugLevel(CreateTableProcessor::VERBOSE);

                SqlStatement &stmt = *ptree.fList[0];
                CreateTableProcessor::DDLResult result;

                result  = processor.processPackage(dynamic_cast<CreateTableStatement&>(stmt));
                std::cout << "return: " << result.result << std::endl;
            }
            catch(...)
            {
                throw;
            }
        }
    }
Ejemplo n.º 6
0
int main(int argc, char** argv)
{
	int c;

	opterr = 0;

	while ((c = getopt(argc, argv, "h")) != EOF)
		switch (c)
		{
		case 'h':
		case '?':
		default:
			usage();
			return (c == 'h' ? 0 : 1);
			break;
		}

	if (argc - optind < 2)
	{
		usage();
		return 1;
	}

	string owner(toupper_(argv[optind++]));

	SqlParser parser;
	parser.setDefaultSchema(owner);

	string stmtStr(toupper_(argv[optind++]));
	parser.Parse(stmtStr.c_str());

	if (!parser.Good())
	{
		cerr << "Failed to parse statement: " << stmtStr << endl;
		return 1;
	}

	const ParseTree &ptree = parser.GetParseTree();
	SqlStatement& stmt = *ptree.fList[0];

	stmt.fSessionID = 1;
	stmt.fSql = stmtStr;
	stmt.fOwner = owner;

	ByteStream bytestream;
	bytestream << stmt.fSessionID;
	stmt.serialize(bytestream);
	MessageQueueClient mq("DDLProc");
	ByteStream::byte b;
	string errorMsg;
	try
	{
		mq.write(bytestream);
		bytestream = mq.read();
		bytestream >> b;
		bytestream >> errorMsg;
	}
	catch (runtime_error& rex)
	{
		cerr << "runtime_error in engine: " << rex.what() << endl;
		return 1;
	}
	catch (...)
	{
		cerr << "uknown error in engine" << endl;
		return 1;
	}

	if (b != 0)
	{
		cerr << "DDLProc error: " << errorMsg << endl;
		return 1;
	}

	return 0;
}