00001 #include "config.h"
00002 #include "Options.h"
00003 #include "Priority.h"
00004 #include "Parameter.h"
00005 #include <rcudb/Server.h>
00006 #include <rcudb/Sql.h>
00007 #include <iostream>
00008 #include <sstream>
00009 #include <stdexcept>
00010
00011
00012
00013 int
00014 main(int argc, char** argv)
00015 {
00016 using namespace RcuConf;
00017 Option<bool> hOpt('h', "help", "Show this help", false,false);
00018 Option<bool> VOpt('V', "version", "Show version number", false,false);
00019 Option<std::string> cOpt('c', "connection", "Database connection url",
00020 "mysql://config@localhost/RCU");
00021 CommandLine cl("");
00022 cl.Add(hOpt);
00023 cl.Add(VOpt);
00024 cl.Add(cOpt);
00025
00026 if (!cl.Process(argc, argv)) return 1;
00027 if (hOpt.IsSet()) {
00028 cl.Help();
00029 return 0;
00030 }
00031 if (VOpt.IsSet()) {
00032 std::cout << "raw2root version " << VERSION << std::endl;
00033 return 0;
00034 }
00035
00036
00037 std::string con = cOpt;
00038 try {
00039 RcuDb::Server* server = RcuDb::Server::Connect(con);
00040 if (!server)
00041 throw std::runtime_error("Failed to open connection to server!");
00042
00043
00044 Parameter::List params;
00045 if (!Parameter::Select(params, *server, "")) {
00046 std::stringstream s;
00047 s << "Failed to get parameters: " << server->ErrorString();
00048 throw std::runtime_error(s.str());
00049 }
00050
00051 std::vector<int> order;
00052 for (Parameter::List::iterator i = params.begin(); i != params.end(); ++i)
00053 order.push_back((*i)->Id());
00054 Priority p("default", order);
00055
00056 if (!p.Insert(*server)) {
00057 std::stringstream s;
00058 s << "Failed to get parameters: " << server->ErrorString();
00059 throw std::runtime_error(s.str());
00060 }
00061
00062 Priority::List orders;
00063 if (!Priority::Select(orders, *server, "")) {
00064 std::stringstream s;
00065 s << "Failed to get priorities: " << server->ErrorString();
00066 throw std::runtime_error(s.str());
00067 }
00068 for (Priority::List::iterator i = orders.begin(); i != orders.end(); ++i)
00069 (*i)->Print();
00070 }
00071 catch (std::exception& e) {
00072 std::cerr << e.what() << std::endl;
00073 return 1;
00074 }
00075 return 0;
00076 }
00077
00078
00079
00080