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