-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathddldriver.cpp
More file actions
133 lines (109 loc) · 2.55 KB
/
Copy pathddldriver.cpp
File metadata and controls
133 lines (109 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* Copyright (C) 2014 InfiniDB, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
// $Id: ddldriver.cpp 2101 2013-01-21 14:12:52Z rdempsey $
#include <unistd.h>
#include <cstdio>
#include <iostream>
#include <cctype>
#include <sstream>
using namespace std;
#include "ddlpkg.h"
#include "sqlparser.h"
using namespace ddlpackage;
#include "bytestream.h"
#include "messagequeue.h"
using namespace messageqcpp;
namespace
{
void usage()
{
cout << "usage: ddlriver [-h] schema sql_text" << endl;
}
const string toupper_(const string& in)
{
string::const_iterator iter = in.begin();
string::const_iterator end = in.end();
ostringstream oss;
while (iter != end)
{
oss << static_cast<char>(toupper(*iter));
++iter;
}
return oss.str();
}
}
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;
}