GetADOConnection.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file examples/ado/CopyDataSet.cpp
22 
23  \brief It copy a DataSet
24 */
25 
26 // Example
27 #include "ADOExamples.h"
28 
29 // TerraLib
30 #include <terralib/common.h>
33 
34 // STL
35 #include <iostream>
36 
37 std::unique_ptr<te::da::DataSource> GetADOConnection()
38 {
39  // Set the minimum server connection information needed to connect to the database server
40  std::string connInfo("file://");
41  std::string data_dir = TERRALIB_DATA_DIR;
42  std::string user, pass, path;
43 
44  std::cout << "Inform the location of your Microsoft Access database (ENTER to accept default \'" << (data_dir + "/ado/ADODataSource.mdb") << "\'): ";
45  std::getline(std::cin, path);
46 
47  std::cout << "Inform the user to access your Microsoft Access database (ENTER if there is none): ";
48  std::getline(std::cin, user);
49 
50  std::cout << "Inform the Password to access Microsoft Access database (ENTER if there is none): ";
51  std::getline(std::cin, pass);
52 
53  connInfo += user.empty() ? "" : user + ":";
54  connInfo += pass.empty() ? "" : pass + "@";
55  connInfo += path.empty() ? (data_dir + "/ado/ADODataSource.mdb") : path;
56 
57 #ifdef _M_IX86
58  connInfo += "?PROVIDER=Microsoft.Jet.OLEDB.4.0";
59 #else
60  connInfo += "?PROVIDER=Microsoft.ACE.OLEDB.12.0";
61 #endif
62 
63  // Create a data source using the data source factory
64  std::unique_ptr<te::da::DataSource> ds(te::da::DataSourceFactory::make("ADO", connInfo));
65 
66  try
67  {
68  //Open the data source using the connection information given above
69  ds->open();
70  return ds;
71  }
72  catch (const std::exception& e)
73  {
74  std::cout << std::endl << "An exception has occurred: " << e.what() << std::endl;
75  }
76  catch (...)
77  {
78  std::cout << std::endl << "An unexpected exception has occurred!" << std::endl;
79  }
80 }
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
Examples that show how to access/manipulate an ADO data source.
static te::dt::Date ds(2010, 01, 01)
std::unique_ptr< te::da::DataSource > GetADOConnection()
A factory for data sources.
Utility functions for the data access module.
This file contains include headers for the TerraLib Common Runtime module.