// // 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 (argc != 2) //{ // std::cout << "Usage: connect \n"; // return 0; //} std::wstring provider(L"OSGeo.PostGIS.3.2"); // Connection string with datastore specified //std::string tmp(argv[1]); //std::wstring connStr(fdoutility::towstring(tmp)); std::wstring connStr(L"service=world@192.168.1.101;username=mloskot;password=pantera;datastore=public"); std::wcout << L"Connection string:\n" << connStr << std::endl; // Create connection FdoPtr conn = fdoutility::create_connection(provider); // Configure connection conn->SetConnectionString(connStr.c_str()); // Open connection FdoConnectionState state = conn->Open(); std::wcout << "FdoIConnection::Open()\n"; std::wcout << " State: " << conn->GetConnectionState() << std::endl; // Close connection (usually optional) conn->Close(); std::wcout << "FdoIConnection::Close()\n"; std::wcout << " State: " << conn->GetConnectionState() << std::endl; } catch (FdoException* ex) { std::wcout << L"*** FDO Error:\n"; int i = 5; FdoException* nex = ex; while (nex) { const wchar_t* 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::exception& ex) { std::cout << "*** Std Error: " << ex.what() << std::endl; } catch(...) { std::cout << "*** Undefined error!\n" << std::endl; } return 0; }