dropTables.cxx

00001 #include "config.h"
00002 #include "Options.h"
00003 #include "Sequence.h"
00004 #include "Config.h"
00005 #include "Priority.h"
00006 #include "Parameter.h"
00007 #include "SingleValue.h"
00008 #include "BlobValue.h"
00009 #include "Address.h"
00010 #include <rcudb/Server.h>
00011 #include <rcudb/Result.h>
00012 #include <rcudb/Sql.h>
00013 #include <iostream>
00014 #include <sstream>
00015 #include <stdexcept>
00016 
00017 //____________________________________________________________________
00018 template <typename T>
00019 void dropTable(RcuDb::Server& s, const std::string& name) 
00020 {
00021   if (T::Drop(s)) return;
00022   std::stringstream errstr;
00023   errstr << "Failed to drop the " << name << " table: " 
00024          << s.ErrorString();
00025   std::cerr << errstr.str() << std::endl;
00026   // throw std::runtime_error(errstr.str());
00027 }
00028 
00029 //____________________________________________________________________
00030 int 
00031 main(int argc, char** argv)
00032 {
00033   using namespace RcuConf;
00034   Option<bool>        hOpt('h', "help",    "Show this help", false,false);
00035   Option<bool>        VOpt('V', "version", "Show version number", false,false);
00036   Option<std::string> cOpt('c', "connection", "Database connection url", 
00037                            "mysql://config@localhost/RCU");
00038   CommandLine cl("");
00039   cl.Add(hOpt);
00040   cl.Add(VOpt);
00041   cl.Add(cOpt);
00042 
00043   if (!cl.Process(argc, argv)) return 1;
00044   if (hOpt.IsSet()) {
00045     cl.Help();
00046     return 0;
00047   }
00048   if (VOpt.IsSet()) {
00049     std::cout << "raw2root version " << VERSION << std::endl;
00050     return 0;
00051   }
00052 
00053   try {
00054     std::string con = cOpt;
00055     RcuDb::Server* server = RcuDb::Server::Connect(con);
00056     if (!server) 
00057       throw std::runtime_error("Failed to open connection to server!");
00058 
00059     RcuDb::Result* res = server->Query("SHOW TABLES");
00060     if (!res) {
00061       std::stringstream s;
00062       s << "Failed to get tables: " << server->ErrorString();
00063       std::cerr << s.str() << std::endl;
00064       // throw std::runtime_error(s.str());
00065     }
00066     res->Print();
00067   
00068     dropTable<Address>(*server,     "Address");
00069     dropTable<BlobValue>(*server,   "BlobValue");
00070     dropTable<SingleValue>(*server, "SingleValue");
00071     dropTable<Parameter>(*server,   "Parameter");
00072     dropTable<Priority>(*server,       "Priority");
00073     dropTable<Config>(*server,      "Config");
00074     if (!Sequence::Drop(*server)) {
00075       std::stringstream errstr;
00076       errstr << "Failed to drop Sequence table: " 
00077              << server->ErrorString() << std::endl;
00078       std::cerr << errstr.str() << std::endl;
00079       // throw std::runtime_error(errstr.str());
00080     }
00081   }
00082   catch (std::exception& e) {
00083     std::cerr << e.what() << std::endl;
00084     return 1;
00085   }
00086     
00087   return 0;
00088 }
00089 
00090       
00091 
00092 
Top of page Last update Fri Apr 27 01:54:15 2007
Copyright © 2004 Christian Holm Created by DoxyGen 1.3.5