// // Copyright (C) 2007 Refractions Research, Inc. // // This library is free software; you can redistribute it and/or // modify it under the terms of version 2.1 of the GNU Lesser // General Public License as published by the Free Software Foundation. // // 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 // #include #include #include #include #include #include #include "fdoutility.h" using namespace fdoutility; int main(int argc, char* argv[]) { try { if (2 != argc) { throw std::runtime_error("Connection string parameter is missing"); } std::string cs(argv[1]); if (cs.empty()) { throw std::runtime_error("Connection string is empty"); } std::wstring provider(L"OSGeo.PostGIS.3.2"); // Connection string without specified a datastore std::wstring connStr(fdoutility::towstring(cs)); std::wcout << "Connection string: " << connStr << std::endl; // Open connection FdoPtr conn = fdoutility::create_connection(provider); conn->SetConnectionString(connStr.c_str()); FdoConnectionState state = conn->Open(); std::wcout << "Connection state: " << state << std::endl; // Create command FdoPtr cmd = static_cast( conn->CreateCommand(FdoCommandType_ListDataStores)); // Configure command cmd->SetIncludeNonFdoEnabledDatastores(true); // Execute command FdoPtr reader = cmd->Execute(); // Read command execution results int cnt = 0; while (reader->ReadNext()) { ++cnt; std::wcout << std::setw(2) << cnt << L". " << reader->GetName() << std::endl << std::make_pair("IsFdoEnabled", reader->GetIsFdoEnabled()) << std::make_pair("Description", reader->GetDescription()) << std::endl; } std::cout << "Number of datastores: " << cnt << std::endl; // Close reader (optional) reader->Close(); // Close connection (optional) conn->Close(); } catch (FdoException* ex) { std::wcout << L"*** FDO Error:\n"; int i = 5; FdoException* nex = ex; while (nex) { wchar_t const* msg = nex->GetExceptionMessage(); if (NULL == msg) { msg = L"NO MESSAGE"; } std::wcout << std::setw(++i) << L"*** " << msg << std::endl; nex = nex->GetCause(); } ex->Release(); } catch(std::runtime_error& ex) { std::cout << "*** ERROR: " << ex.what() << "\n\n"; std::cout << "Usage: list_datastores \nConnection string example:\n" << "\"service=db@host;username=john;password=xxx;\"" << std::endl; } catch(std::exception& ex) { std::cout << "*** STD ERROR: " << ex.what() << std::endl; } catch(...) { std::cout << "*** Undefined Error!\n" << std::endl; } return 0; }