/***************************************************************************** * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2009 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ //$Id$ #include "pgsql2sqlite.hpp" #include #include #include "connection_manager.hpp" //#include "cursorresultset.hpp" // boost #include #include #include #include #include #include //#include #include //stl #include #include int main ( int argc, char** argv) { namespace po = boost::program_options; po::options_description desc("Postgresql/PostGIS to SQLite3 converter\n Options"); desc.add_options() ("help,?","Display this help screen.") ("host,h",po::value(),"Allows you to specify connection to a database on a machine other than the default.") ("port,p",po::value(),"Allows you to specify a database port other than the default.") ("user,u",po::value(),"Connect to the database as the specified user.") ("dbname,d",po::value(),"postgresql database name") ("password,P",po::value(),"Connect to the database with the specified password.") ("query,q",po::value(),"Name of the table/or query to pass to postmaster") ("table,t",po::value(),"Name of the table to create") ("file,f",po::value(),"Use this option to specify the name of the file to create.") ; po::positional_options_description p; p.add("table",1); po::variables_map vm; try { po::store(po::command_line_parser(argc,argv).options(desc).positional(p).run(),vm); po::notify(vm); if (vm.count("help") || !vm.count("file") || !vm.count("query")) { std::cout << desc << "\n"; return EXIT_SUCCESS; } } catch (...) { std::cout << desc << "\n"; return EXIT_FAILURE; } boost::optional host; boost::optional port ; boost::optional dbname; boost::optional user; boost::optional password; if (vm.count("host")) host = vm["host"].as(); if (vm.count("port")) port = vm["port"].as(); if (vm.count("dbname")) dbname = vm["dbname"].as(); if (vm.count("user")) user = vm["user"].as(); if (vm.count("password")) password = vm["password"].as(); ConnectionCreator creator(host,port,dbname,user,password); try { boost::shared_ptr conn(creator()); std::string query = vm["query"].as(); std::string output_table_name = vm.count("table") ? vm["table"].as() : mapnik::table_from_sql(query); std::string output_file = vm["file"].as(); std::cout << "output_table : " << output_table_name << "\n"; mapnik::pgsql2sqlite(conn,query,output_table_name,output_file); } catch (mapnik::datasource_exception & ex) { std::cerr << ex.what() << "\n"; } return EXIT_SUCCESS; }