// // 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; using namespace std; int main(int argc, char* argv[]) { try { std::wstring provider(L"OSGeo.PostGIS.3.2"); // Connection string with datastore specified std::wstring ds(L"public"); std::wstring connStr(L"service=poland;username=mloskot;password=pantera;"); // Connect FdoPtr conn = fdoutility::create_connection(provider); connStr += L"datastore=" + ds; conn->SetConnectionString(connStr.c_str()); FdoConnectionState state = conn->Open(); cout << "Connection state: " << state << endl; // Create command FdoPtr cmd; cmd = static_cast(conn->CreateCommand(FdoCommandType_SelectAggregates)); assert(0 != cmd); // Set feature class cout << "Executing FdoISelect command...\n"; std::wstring className(L"FdoPostGIS:"); className += ds.c_str(); className += L"~"; className += L"districts"; cmd->SetFeatureClassName(className.c_str()); // Create expression // How to concatenate with blanks: // CONCAT(id_wojewod, \" \", wojewodztw) // or // CONCAT(id_wojewod, ' ', wojewodztw) FdoPtr idCol = cmd->GetPropertyNames(); idCol->Add( FdoPtr( FdoComputedIdentifier::Create( L"MyConcatString_1", FdoPtr( FdoExpression::Parse(L"CONCAT(id_wojewod, \" \", wojewodztw)"))))); idCol->Add( FdoPtr( FdoComputedIdentifier::Create( L"MyConcatString_2", FdoPtr( FdoExpression::Parse(L"CONCAT(mezczyzni, ' ', kobiety)"))))); // Execute command FdoPtr reader = cmd->Execute(); cout << "Reading features...\n"; FdoInt32 cnt = 0; while (reader->ReadNext()) { for (FdoInt32 i = 0; i < reader->GetPropertyCount(); i++) { FdoStringP name(reader->GetPropertyName(i)); std::wcout << name << L" = "; if (FdoDataType_Int16 == reader->GetDataType(name)) std::cout << reader->GetInt16(name); if (FdoDataType_Int32 == reader->GetDataType(name)) std::cout << reader->GetInt32(name); if (FdoDataType_Int64 == reader->GetDataType(name)) std::cout << reader->GetInt64(name); else if (FdoDataType_Double == reader->GetDataType(name) || FdoDataType_Decimal == reader->GetDataType(name)) std::cout << std::fixed << std::showpoint << std::setprecision(6) << reader->GetDouble(name); else if (FdoDataType_String == reader->GetDataType(name)) { FdoStringP fs(reader->GetString(name)); std::wstring ws(static_cast(fs)); std::string s(static_cast(fs)); std::cout << s << std::endl; } std::cout << std::endl; } std::cout << "---------------------------------\n"; } // Close reader and connection object. reader->Close(); conn->Close(); cout << "Connection State: " << conn->GetConnectionState() << endl; } catch (FdoException* ex) { std::wcout << L"*** FDO Error:\n"; int i = 5; FdoException* nex = ex; while (NULL != nex) { const wchar_t* msg = nex->GetExceptionMessage(); if (NULL == msg) { msg = L"NO MESSAGE"; } std::wcout << std::setw(++i) << L"*** " << msg << std::endl; FdoException* p = nex; nex = nex->GetCause(); p->Release(); } } catch(std::exception& ex) { std::cout << "*** Std Error: " << ex.what() << std::endl; } catch(...) { std::cout << "*** Undefined error!\n" << std::endl; } return 0; }