All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Utils.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 terralib/ado/Utils.h
22 
23  \brief Utility functions for ADO.
24 */
25 
26 #ifndef __TERRALIB_ADO_INTERNAL_UTILS_H
27 #define __TERRALIB_ADO_INTERNAL_UTILS_H
28 
29 // TerraLib
30 #include "../common/StringUtils.h"
31 #include "../geometry/Geometry.h"
32 #include "Config.h"
33 
34 // STL
35 #include <cstdlib>
36 #include <cstring>
37 #include <vector>
38 
39 // ADO
40 #import "msado15.dll" \
41  no_namespace rename("EOF", "EndOfFile")
42 #import "msadox.dll"
43 
44 namespace te
45 {
46 
47  namespace da
48  {
49  class DataSet;
50  class DataSetType;
51  class PrimaryKey;
52  class ForeignKey;
53  class UniqueKey;
54  class Constraint;
55  }
56 
57  namespace dt
58  {
59  class Property;
60  }
61 
62  namespace gm
63  {
64  class GeometryProperty;
65  }
66 
67  namespace mem
68  {
69  class DataSetItem;
70  }
71 
72  namespace ado
73  {
74 
75  /*!
76  \brief Convert a blob to a variant
77 
78  \param blob Blob
79  \param size Blob size
80  \param var Result variant
81  */
82  void Blob2Variant(const char* blob, int size, _variant_t & var);
83 
84  /*!
85  \brief Create a connection string based on a map
86 
87  \param dsInfo Information Map.
88 
89  \return ADO connection string
90  */
91  std::string MakeConnectionStr(const std::map<std::string, std::string>& dsInfo);
92 
93  /*!
94  \brief Convert a variant to a blob
95 
96  \param var Variant
97  \param size Variant size
98  \param blob Result variant
99  */
100  void Variant2Blob(const _variant_t var, int size, char* & blob);
101 
102  /*!
103  \brief Bind TerraLib Type to ADO Type.
104 
105  \param terralib TerraLib Type.
106 
107  \return ADO Type
108  */
109  ADOX::DataTypeEnum Convert2Ado(int terralib);
110 
111  /*!
112  \brief Bind TerraLib geometry to ADO variant.
113 
114  \param geo TerraLib Geometry.
115  \param var Ado variant
116  */
117  void Convert2Ado(const te::gm::Geometry* geo, _variant_t & var);
118 
119  /*!
120  \brief Bind ADOX Type to TerraLib Type.
121 
122  \param adoType ADOX Type.
123 
124  \return TerraLib Type
125  */
126  int Convert2Terralib(ADOX::DataTypeEnum adoType);
127 
128  /*!
129  \brief Bind ADO Type to TerraLib Type.
130 
131  \param adoType Ado Type.
132 
133  \return TerraLib Type
134  */
135  int Convert2Terralib(::DataTypeEnum adoType);
136 
137  /*!
138  \brief Bind ADO column to Terralib property
139 
140  \param column Ado Column.
141 
142  \return TerraLib Property
143  */
144  te::dt::Property* Convert2Terralib(ADOX::_ColumnPtr column);
145 
146  /*!
147  \brief Bind ADO key to Terralib constraint
148 
149  \param key Ado key.
150 
151  \return TerraLib Constraint
152  */
153  te::da::Constraint* Convert2Terralib(ADOX::_KeyPtr key);
154 
155  /*!
156  \brief Bind ADO columns to vector of Terralib properties
157 
158  \param columns Ado columns.
159 
160  \return Vector of TerraLib properties
161  */
162  std::vector<te::dt::Property*> Convert2Terralib(ADOX::ColumnsPtr columns);
163 
164  /*!
165  \brief It returns the geometry OGC names.
166 
167  \param t The TerraLib geometry type.
168 
169  \return The geometry OGC names.
170  */
171  const std::string& GetGeometryName(te::gm::GeomType t);
172 
173  /*!
174  \brief It returns the geometry type concerning the OGC name
175 
176  \param t The OGC type name
177 
178  \return The Terralib geometry type
179  */
180  const te::gm::GeomType GetGeometryType(std::string t);
181 
182  /*!
183  \brief Read the geometry_columns table end return a SRID
184 
185  \param adoConn Ado connection.
186  \param tableName The table name.
187  \param geomPropName The geometry property name.
188 
189  \return SRID of the geometry
190  */
191  int GetSRID(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName);
192 
193  /*!
194  \brief Read the geometry_columns table end return a geometry type
195 
196  \param adoConn Ado connection.
197  \param tableName The table name.
198  \param geomPropName The geometry property name.
199 
200  \return The geometry type
201  */
202  te::gm::GeomType GetType(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName);
203 
204  /*!
205  \brief Verifies whether is in the geometry_columns table
206 
207  \param adoConn Ado connection
208  \param tableName Ado table name
209  \param columnName Ado column name
210 
211  \return if is in geometry_columns table
212  */
213  bool IsGeomProperty(_ConnectionPtr adoConn, std::string tableName, std::string columnName);
214 
215  /*!
216  \brief Verifies whether Z property
217 
218  \param type geometry type
219 
220  \return if is Z property
221  */
222  bool IsZProperty(te::gm::GeomType type);
223 
224  /*!
225  \brief It gets the system Date and Time format.
226 
227  \param indAM AM indicator string.
228  \param indPM PM indicator string.
229  \param sepD Date separator.
230  \param sepT Time separator.
231 
232  \return The full DateTime format.
233  */
234  std::string GetSystemDateTimeFormat(std::string& indAM, std::string& indPM, std::string& sepD, std::string& sepT);
235 
236  /*!
237  \brief It gets the DateTime TerraLib 5 from string.
238 
239  \param value String value to be read.
240  \param mask System DateTime mask;
241  \param sepD Date separator.
242  \param sepT Time separator.
243 
244  \return The TerraLib 5 DateTime.
245  */
246  std::auto_ptr<te::dt::DateTime> GetDateTime(std::string& value, std::string& mask, std::string& sepD, std::string& sepT);
247 
248  /*!
249  \brief It gets the index of a month.
250 
251  \param month Month name.
252 
253  \return The month index.
254  */
255  int GetMonth(const std::string& month);
256 
257  /*!
258  \brief It gets a formatted DateTime string for ADO
259 
260  \param dateTime TerraLib 5 DateTime.
261 
262  \return A formatted DateTime string.
263  */
264  std::string GetFormattedDateTime(te::dt::DateTime* dateTime);
265 
266  } // end namespace ado
267 } // end namespace te
268 
269 #endif // __TERRALIB_ADO_INTERNAL_UTILS_H
int Convert2Terralib(ADOX::DataTypeEnum adoType)
Bind ADOX Type to TerraLib Type.
Definition: Utils.cpp:202
te::gm::GeomType GetType(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName)
Read the geometry_columns table end return a geometry type.
Definition: Utils.cpp:825
bool IsGeomProperty(_ConnectionPtr adoConn, std::string tableName, std::string columnName)
Verifies whether is in the geometry_columns table.
Definition: Utils.cpp:851
std::string GetFormattedDateTime(te::dt::DateTime *dateTime)
It gets a formatted DateTime string for ADO.
Definition: Utils.cpp:1228
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Definition: DataSetItem.h:56
ADOX::DataTypeEnum Convert2Ado(int terralib)
Bind TerraLib Type to ADO Type.
Definition: Utils.cpp:128
int GetSRID(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName)
Read the geometry_columns table end return a SRID.
Definition: Utils.cpp:801
Configuration flags for the TerraLib ADO Data Access driver.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
std::string MakeConnectionStr(const std::map< std::string, std::string > &dsInfo)
Create a connection string based on a map.
Definition: Utils.cpp:82
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
void Variant2Blob(const _variant_t var, int size, char *&blob)
Convert a variant to a blob.
Definition: Utils.cpp:109
std::string GetSystemDateTimeFormat(std::string &indAM, std::string &indPM, std::string &sepD, std::string &sepT)
It gets the system Date and Time format.
Definition: Utils.cpp:897
It models a property definition.
Definition: Property.h:59
void Blob2Variant(const char *blob, int size, _variant_t &var)
Convert a blob to a variant.
Definition: Utils.cpp:56
int GetMonth(const std::string &month)
It gets the index of a month.
Definition: Utils.cpp:1035
bool IsZProperty(te::gm::GeomType type)
Verifies whether Z property.
Definition: Utils.cpp:890
Spatial reference system transformation function.
const std::string & GetGeometryName(te::gm::GeomType t)
It returns the geometry OGC names.
Definition: Utils.cpp:498
std::auto_ptr< te::dt::DateTime > GetDateTime(std::string &value, std::string &mask, std::string &sepD, std::string &sepT)
It gets the DateTime TerraLib 5 from string.
Definition: Utils.cpp:1066
const te::gm::GeomType GetGeometryType(std::string t)
It returns the geometry type concerning the OGC name.
Definition: Utils.cpp:651