56{
57
58
59
60 int verbose_level = 1;
61 std::string connect_string;
62 std::string working_schema;
63 std::string password;
65 std::string release;
66 int schema_version = -1;
67 bool remove_file = false;
68
69 for (int i = 1; i < argc; i++) {
70 const char* cp = argv[i];
71
72 if (!strcmp(cp, "-h") || !strcmp(cp, "--help")) {
74 return (EXIT_SUCCESS);
75 } else if (!strcmp(cp, "-v") || !strcmp(cp, "--verbose-level")) {
76 if (++i == argc) {
78 return (EXIT_FAILURE);
79 } else {
80 verbose_level = atoi(argv[i]);
81 }
82 } else if (!strcmp(cp, "-n") || !strcmp(cp, "--schema-version")) {
83 if (++i == argc) {
85 return (EXIT_FAILURE);
86 } else {
87 schema_version = atoi(argv[i]);
88 }
89 } else if (!strcmp(cp, "-e") || !strcmp(cp, "--head-schema-version")) {
90 schema_version = 0;
91 if (argc > (i + 1) && argv[i + 1][0] != '-') {
92 ++i;
93 release = argv[i];
94 }
95 } else if (!strcmp(cp, "-c") || !strcmp(cp, "--connect-string")) {
96 if (++i == argc) {
98 return (EXIT_FAILURE);
99 } else {
100 connect_string = argv[i];
101 }
102 } else if (!strcmp(cp, "-w") || !strcmp(cp, "--working-schema")) {
103 if (++i == argc) {
105 return (EXIT_FAILURE);
106 } else {
107 working_schema = argv[i];
108 }
109 } else if (!strcmp(cp, "-f") || !strcmp(cp, "--out-file")) {
110 if (++i == argc) {
112 return (EXIT_FAILURE);
113 } else {
115 }
116 } else {
117 std::cerr << "ERROR: Unexpected parameter: \"" << cp << "\"\n\n";
119 return (EXIT_FAILURE);
120 }
121 }
122
123 if (schema_version == -1) {
124 std::cerr << "ERROR: specify schema version or use -e parameter to get HEAD schema version\n";
126 return EXIT_FAILURE;
127 }
128
129 if (connect_string.empty()) {
130 std::cerr << "ERROR: the connect string is required\n";
132 return EXIT_FAILURE;
133 }
134
135 if (working_schema.empty()) {
136 std::cerr << "ERROR: the working schema is required\n";
138 return EXIT_FAILURE;
139 }
140
141
142
144
145 ::OksKernel kernel;
146
147 try {
148
150 file = kernel.get_tmp_file(
"/tmp/unknown.schema.xml");
151 VerboseMsg2(
"The name of output schema file was not provided.\n * use file \'" << file <<
'\'');
152 remove_file = true;
153 }
154
156 ::OksFile* fh = kernel.new_schema(file);
157
158 {
159 std::unique_ptr<coral::ConnectionService> connection;
160 {
161 std::unique_ptr<coral::ISessionProxy>
session(
163
164 if (schema_version == 0) {
165 schema_version =
167 if (schema_version < 0) {
168 throw std::runtime_error((schema_version == 0) ? "Cannot get head schema" : "Cannot get given schema");
169 }
170 }
171
173
175
177 session->transaction().commit();
178
180 }
181
183 }
184
185 if (remove_file) {
186 VerboseMsg2(
"Removing temporal schema file \'" << file <<
"\'...");
187 unlink(
file.c_str());
188 } else {
190 kernel.save_schema(fh);
191 }
192
194
195 }
196
197 catch (coral::Exception& e) {
198 std::cerr << "CORAL exception: " << e.what() << std::endl;
199 return 1;
200 }
201
202 catch (oks::exception& ex) {
203 std::cerr << "OKS exception:\n" << ex << std::endl;
204 return 2;
205 }
206
207 catch (std::exception& e) {
208 std::cerr << "Standard C++ exception : " << e.what() << std::endl;
209 return 3;
210 }
211
212 catch (...) {
213 std::cerr << "Exception caught (...)" << std::endl;
214 return 4;
215 }
216
217 return 0;
218}
static void usage(const char *s)
static void no_param(const char *s)
void get_schema(OksKernel &kernel, coral::ISessionProxy *session, const std::string &schema, int version, bool read_methods, int verbose_level)
Get schema by version number.
coral::ISessionProxy * start_coral_session(const std::string &connect_string, int mode, std::unique_ptr< coral::ConnectionService > &connection, int verbose_level)
Start coral session.
int get_head_schema_version(coral::ISessionProxy *session, const std::string &schema, const char *release=0, int verbose_level=1, const char *dx="")
Get HEAD schema version number.