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 
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 type to an ADO valid fiel type name.
113 
114  \terralib TerraLib data type.
115 
116  \return Valid ADO field type as string value.
117  */
118  std::string GetAdoStringType(const int& terralib);
119 
120  /*!
121  \brief Bind TerraLib geometry to ADO variant.
122 
123  \param geo TerraLib Geometry.
124  \param var Ado variant
125  */
126  void Convert2Ado(const te::gm::Geometry* geo, _variant_t & var);
127 
128  /*!
129  \brief Bind ADOX Type to TerraLib Type.
130 
131  \param adoType ADOX Type.
132 
133  \return TerraLib Type
134  */
135  int Convert2Terralib(ADOX::DataTypeEnum adoType);
136 
137  /*!
138  \brief Bind ADO Type to TerraLib Type.
139 
140  \param adoType Ado Type.
141 
142  \return TerraLib Type
143  */
144  int Convert2Terralib(::DataTypeEnum adoType);
145 
146  /*!
147  \brief Bind ADO column to Terralib property
148 
149  \param column Ado Column.
150 
151  \return TerraLib Property
152  */
153  te::dt::Property* Convert2Terralib(ADOX::_ColumnPtr column);
154 
155  /*!
156  \brief Bind ADO key to Terralib constraint
157 
158  \param key Ado key.
159 
160  \return TerraLib Constraint
161  */
162  te::da::Constraint* Convert2Terralib(ADOX::_KeyPtr key);
163 
164  /*!
165  \brief Bind ADO columns to vector of Terralib properties
166 
167  \param columns Ado columns.
168 
169  \return Vector of TerraLib properties
170  */
171  std::vector<te::dt::Property*> Convert2Terralib(ADOX::ColumnsPtr columns);
172 
173  /*!
174  \brief It returns the geometry OGC names.
175 
176  \param t The TerraLib geometry type.
177 
178  \return The geometry OGC names.
179  */
180  const std::string& GetGeometryName(te::gm::GeomType t);
181 
182  /*!
183  \brief It returns the geometry type concerning the OGC name
184 
185  \param t The OGC type name
186 
187  \return The Terralib geometry type
188  */
189  const te::gm::GeomType GetGeometryType(std::string t);
190 
191  /*!
192  \brief Read the geometry_columns table end return a SRID
193 
194  \param adoConn Ado connection.
195  \param tableName The table name.
196  \param geomPropName The geometry property name.
197 
198  \return SRID of the geometry
199  */
200  int GetSRID(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName);
201 
202  /*!
203  \brief Read the geometry_columns table end return a geometry type
204 
205  \param adoConn Ado connection.
206  \param tableName The table name.
207  \param geomPropName The geometry property name.
208 
209  \return The geometry type
210  */
211  te::gm::GeomType GetType(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName);
212 
213  /*!
214  \brief Verifies whether is in the geometry_columns table
215 
216  \param adoConn Ado connection
217  \param tableName Ado table name
218  \param columnName Ado column name
219 
220  \return if is in geometry_columns table
221  */
222  bool IsGeomProperty(_ConnectionPtr adoConn, std::string tableName, std::string columnName);
223 
224  /*!
225  \brief Verifies whether Z property
226 
227  \param type geometry type
228 
229  \return if is Z property
230  */
231  bool IsZProperty(te::gm::GeomType type);
232 
233  /*!
234  \brief It gets the system Date and Time format.
235 
236  \param indAM AM indicator string.
237  \param indPM PM indicator string.
238  \param sepD Date separator.
239  \param sepT Time separator.
240 
241  \return The full DateTime format.
242  */
243  std::string GetSystemDateTimeFormat(std::string& indAM, std::string& indPM, std::string& sepD, std::string& sepT);
244 
245  /*!
246  \brief It gets the DateTime TerraLib 5 from string.
247 
248  \param value String value to be read.
249  \param mask System DateTime mask;
250  \param sepD Date separator.
251  \param sepT Time separator.
252 
253  \return The TerraLib 5 DateTime.
254  */
255  std::auto_ptr<te::dt::DateTime> GetDateTime(std::string& value, std::string& mask, std::string& sepD, std::string& sepT);
256 
257  /*!
258  \brief It gets the index of a month.
259 
260  \param month Month name.
261 
262  \return The month index.
263  */
264  int GetMonth(const std::string& month);
265 
266  /*!
267  \brief It gets a formatted DateTime string for ADO
268 
269  \param dateTime TerraLib 5 DateTime.
270 
271  \return A formatted DateTime string.
272  */
273  std::string GetFormattedDateTime(te::dt::DateTime* dateTime);
274 
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 MakeConnectionStr(const std::map< std::string, std::string > &dsInfo)
Create a connection string based on a map.
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:73
const te::gm::GeomType GetGeometryType(std::string t)
It returns the geometry type concerning the OGC name.
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.
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.