Ejemplo n.º 1
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.º 2
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.º 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_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.º 5
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;
}