src/terralib/postgis/Utils.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 terralib/postgis/Utils.cpp
22 
23  \brief Utility functions for PostgreSQL.
24 */
25 
26 // TerraLib
27 #include "../core/utils/HexUtils.h"
28 #include "../core/translator/Translator.h"
29 #include "../core/uri/URI.h"
30 #include "../core/uri/Utils.h"
31 #include "../dataaccess/dataset/DataSet.h"
32 #include "../dataaccess/dataset/DataSetType.h"
33 #include "../datatype/ByteArray.h"
34 #include "EWKBWriter.h"
35 #include "Exception.h"
36 #include "Globals.h"
37 #include "Utils.h"
38 
39 // Boost
40 #include <boost/lexical_cast.hpp>
41 
42 // libpq
43 #include <libpq-fe.h>
44 
45 // helper functions
46 namespace te
47 {
48  namespace pgis
49  {
50  inline bool SetColumnDef(std::string& s, const std::string& tname, const te::dt::SimpleProperty* p, bool justDataType = false)
51  {
52  if(p->isAutoNumber() && p->getType() == te::dt::INT32_TYPE)
53  s += "SERIAL";
54  else if(p->isAutoNumber() && p->getType() == te::dt::INT64_TYPE)
55  s += "BIGSERIAL";
56  else
57  s += tname;
58 
59  if(justDataType)
60  return false;
61 
62  if(p->isRequired())
63  s += " NOT NULL";
64 
65  if(p->getDefaultValue() && (p->isAutoNumber() == false))
66  {
67  s += " DEFAULT '";
68  s += *(p->getDefaultValue());
69  s += "'";
70  }
71 
72  return p->isAutoNumber();
73  }
74 
75  inline void SetColumnDef(std::string& s, const te::dt::NumericProperty* p, bool justDataType = false)
76  {
78 
79  if(p->getPrecision() > 0)
80  {
81  s += "(";
83  s += ", ";
85  s += ")";
86  }
87 
88  if(justDataType)
89  return;
90 
91  if(p->isRequired())
92  s += " NOT NULL";
93 
94  if(p->getDefaultValue())
95  {
96  s += " DEFAULT '";
97  s += *(p->getDefaultValue());
98  s += "'";
99  }
100  }
101 
102  inline void SetColumnDef(std::string& s, const std::string& tname, const te::dt::StringProperty* p, bool justDataType = false)
103  {
104  s += tname;
105 
106  if(p->size() > 0 && p->size() < 10485760)
107  {
108  s += "(";
109  s += te::common::Convert2String(static_cast<unsigned int>(p->size()));
110  s += ")";
111  }
112 
113  if(justDataType)
114  return;
115 
116  if(p->isRequired())
117  s += " NOT NULL";
118 
119  if(p->getDefaultValue())
120  {
121  s += " DEFAULT '";
122  s += *(p->getDefaultValue());
123  s += "'";
124  }
125  }
126 
127  inline void SetColumnDef(std::string& s, const te::dt::ArrayProperty* p, bool justDataType = false)
128  {
129  te::dt::Property* elementType = p->getElementType();
130  SetColumnDef(s, elementType, true);
131 
132  s += "[]";
133 
134  if(justDataType)
135  return;
136 
137  if(p->isRequired())
138  s += " NOT NULL";
139 
140  if(p->getDefaultValue())
141  {
142  s += " DEFAULT '";
143  s += *(p->getDefaultValue());
144  s += "'";
145  }
146  }
147 
148  inline bool SetColumnDef(std::string& s, const std::string& tname, const te::dt::DateTimeProperty* p, bool justDataType = false)
149  {
150  s += tname;
151 
152  if (p->getPrecision() > 0 && p->getSubType() != te::dt::DATE)
153  {
154  s += "(";
156  s += ")";
157  }
158 
159  if (justDataType)
160  return false;
161 
162  if (p->isRequired())
163  s += " NOT NULL";
164 
165  if (p->getDefaultValue() && (p->isAutoNumber() == false))
166  {
167  s += " DEFAULT '";
168  s += *(p->getDefaultValue());
169  s += "'";
170  }
171 
172  return p->isAutoNumber();
173  }
174  }
175 }
176 
177 // Utils implementation
179 {
180  switch(t)
181  {
182  case te::gm::PointType:
183  case te::gm::PointZType:
184  case te::gm::PointZMType:
186 
187  case te::gm::PointMType:
189 
194 
197 
198  case te::gm::PolygonType:
202 
203  case te::gm::PolygonMType:
205 
210 
213 
218 
221 
226 
229 
234 
237 
238  default:
240  }
241 }
242 
243 bool te::pgis::SetColumnDef(std::string& s, const te::dt::Property* p, bool justDataType)
244 {
245  int t = p->getType();
246 
247  bool ret = false;
248 
249  switch(t)
250  {
251  case te::dt::CHAR_TYPE:
252  ret = SetColumnDef(s, Globals::sm_charTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
253  break;
254 
255  case te::dt::INT16_TYPE:
256  ret = SetColumnDef(s, Globals::sm_int2TypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
257  break;
258 
259  case te::dt::INT32_TYPE:
260  ret = SetColumnDef(s, Globals::sm_intTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
261  break;
262 
263  case te::dt::INT64_TYPE:
264  ret = SetColumnDef(s, Globals::sm_int8TypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
265  break;
266 
268  {
269  SetColumnDef(s, static_cast<const te::dt::NumericProperty*>(p), justDataType);
270  }
271  break;
272 
274  {
275  const te::dt::DateTimeProperty* dtp = static_cast<const te::dt::DateTimeProperty*>(p);
276  if(dtp->getSubType() == te::dt::DATE)
277  SetColumnDef(s, Globals::sm_dateTypeName, dtp, justDataType);
278  else if(dtp->getSubType() == te::dt::TIME_DURATION)
279  SetColumnDef(s, Globals::sm_timeTypeName, dtp, justDataType);
280  else if(dtp->getSubType() == te::dt::TIME_INSTANT)
281  SetColumnDef(s, Globals::sm_timeStampTypeName, dtp, justDataType);
282  else if(dtp->getSubType() == te::dt::TIME_INSTANT_TZ)
283  SetColumnDef(s, Globals::sm_timeStampTZTypeName, dtp, justDataType);
284  }
285  break;
286 
287  case te::dt::FLOAT_TYPE:
288  SetColumnDef(s, Globals::sm_floatTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
289  break;
290 
291  case te::dt::DOUBLE_TYPE:
292  SetColumnDef(s, Globals::sm_doubleTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
293  break;
294 
295  case te::dt::STRING_TYPE:
296  {
297  const te::dt::StringProperty* sp = static_cast<const te::dt::StringProperty*>(p);
298 
299  if(sp->getSubType() == te::dt::FIXED_STRING)
300  SetColumnDef(s, Globals::sm_fixedcharTypeName, sp, justDataType);
301  else if(sp->getSubType() == te::dt::VAR_STRING)
302  {
303  if(sp->size() > 10485760)
304  {
305  SetColumnDef(s, Globals::sm_stringTypeName, sp, justDataType);
306  }
307  else
308  {
309  SetColumnDef(s, Globals::sm_varcharTypeName, sp, justDataType);
310  }
311  }
312  else
313  SetColumnDef(s, Globals::sm_stringTypeName, sp, justDataType);
314  }
315  break;
316 
318  SetColumnDef(s, Globals::sm_booleanTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
319  break;
320 
322  SetColumnDef(s, Globals::sm_byteArrayTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
323  break;
324 
326  SetColumnDef(s, Globals::sm_geometryTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
327  break;
328 
329  case te::dt::ARRAY_TYPE:
330  SetColumnDef(s, static_cast<const te::dt::ArrayProperty*>(p), justDataType);
331  break;
332 
333  default:
334  throw Exception(TE_TR("The informed type could not be mapped to PostgreSQL type system!"));
335  break;
336  }
337 
338  return ret;
339 }
340 
341 void te::pgis::Convert2PostGIS(PGconn* conn, const te::gm::Geometry* g, std::string& output)
342 {
343  std::size_t size = g->getWkbSize() + 4;
344  std::size_t tosize = 0;
345 
346  char* ewkb = new char[size];
347 
348  EWKBWriter::write(g, ewkb);
349  unsigned char* byteArray = PQescapeByteaConn(conn, (unsigned char*)ewkb, size, &tosize);
350  delete [] ewkb;
351 
352  output += "ST_GeomFromEWKB('";
353  output += (char*)byteArray;
354  output += "')";
355 
356  PQfreemem(byteArray);
357 }
358 
359 void te::pgis::ScapeString(PGconn* conn, const std::string& s, std::string& output)
360 {
361  std::size_t length = s.length() ;
362  char* to = new char[2 * length + 1];
363  PQescapeStringConn(conn, to, s.c_str(), length, nullptr);
364  output += to;
365  delete [] to;
366 }
367 
369  unsigned int pgisGeomTypeOid,
370  unsigned int pgisRasterTypeOid,
371  std::vector<int>& teTypes)
372 {
373  int ncols = PQnfields(result);
374 
375  for(int i = 0; i < ncols; ++i)
376  {
377  std::unique_ptr<te::dt::Property> p(Convert2TerraLib(i, PQfname(result, i), PQftype(result, i),
378  false, nullptr, false, nullptr, -1, pgisGeomTypeOid, pgisRasterTypeOid));
379 
380  teTypes.push_back(p->getType());
381  }
382 }
383 
384 std::string te::pgis::MakeConnectionStr(const te::core::URI& connInfo)
385 {
386  std::string connStr, aux;
387  std::map<std::string, std::string> kvp = te::core::Expand(connInfo.query());
388  std::map<std::string, std::string>::const_iterator it = kvp.begin();
389  std::map<std::string, std::string>::const_iterator itend = kvp.end();
390 
391  aux = connInfo.host();
392  if (!aux.empty())
393  connStr += " host = " + aux;
394 
395  it = kvp.find("PG_HOST_ADDR");
396  if (it != itend && !it->second.empty())
397  connStr += " hostaddr = " + it->second;
398 
399  aux = connInfo.port();
400  if (!aux.empty())
401  connStr += " port = " + aux;
402 
403  aux = te::core::URIDecode(connInfo.path().substr(1, connInfo.path().length()));
404  if (!aux.empty())
405  connStr += " dbname = " + aux;
406 
407  aux = connInfo.user();
408  if (!aux.empty())
409  connStr += " user = " + aux;
410 
411  aux = connInfo.password();
412  if (!aux.empty())
413  connStr += " password = " + aux;
414 
415  it = kvp.find("PG_CONNECT_TIMEOUT");
416  if (it != itend && !it->second.empty())
417  connStr += " connect_timeout = " + it->second;
418 
419  it = kvp.find("PG_OPTIONS");
420  if (it != itend && !it->second.empty())
421  connStr += " options = " + it->second;
422 
423  it = kvp.find("PG_SSL_MODE");
424  if (it != itend && !it->second.empty())
425  connStr += " sslmode = " + it->second;
426 
427  it = kvp.find("PG_KRBSRVNAME");
428  if (it != itend && !it->second.empty())
429  connStr += " krbsrvname = " + it->second;
430 
431  it = kvp.find("PG_GSSLIB");
432  if (it != itend && !it->second.empty())
433  connStr += " gsslib = " + it->second;
434 
435  it = kvp.find("PG_APPLICATION_NAME");
436  if (it != itend && !it->second.empty())
437  connStr += " application_name = " + it->second;
438 
439  return connStr;
440 }
441 
442 void te::pgis::SplitTableName(const std::string& fullName, const std::string* defaultSchema, std::string& schemaName, std::string& tableName)
443 {
444  assert(defaultSchema);
445 
446 // split schema-name.table-name if needed
447  size_t pos = fullName.find(".");
448 
449  if(pos == std::string::npos)
450  {
451  tableName = fullName;
452  schemaName = *defaultSchema;
453  }
454  else
455  {
456  tableName = fullName.substr(pos + 1);
457  schemaName = fullName.substr(0, pos);
458  }
459 }
460 
461 std::string te::pgis::GetBindableWhereSQL(const std::vector<te::dt::Property*>& properties, const std::size_t offset)
462 {
463  std::string wheresql;
464 
465  const std::size_t size = properties.size();
466 
467  for(std::size_t i = 0; i < size; ++i)
468  {
469  if(i != 0)
470  wheresql += " AND ";
471 
472  wheresql += properties[i]->getName();
473 
474  wheresql += " = $" + boost::lexical_cast<std::string>(i + 1 + offset);
475  }
476 
477  return wheresql;
478 }
479 
480 std::string te::pgis::GetSQLBindValues(std::size_t nproperties)
481 {
482  std::string valueNames("(");
483 
484  for(std::size_t i = 0; i < nproperties; ++i)
485  {
486  if(i != 0)
487  valueNames += ",";
488 
489  valueNames += "$" + boost::lexical_cast<std::string>(i + 1);
490  }
491 
492  valueNames += ")";
493 
494  return valueNames;
495 }
496 
497 std::string te::pgis::GetBindableUpdateSQL(const std::vector<te::dt::Property*>& properties)
498 {
499  std::string sql;
500 
501  const std::size_t size = properties.size();
502 
503  for(std::size_t i = 0; i < size; ++i)
504  {
505  if(i != 0)
506  sql += ", ";
507 
508  sql += properties[i]->getName();
509 
510  sql += " = $" + boost::lexical_cast<std::string>(i + 1);
511  }
512 
513  return sql;
514 }
515 
517 {
518  std::string values("(");
519 
520  const std::size_t np = dt->size();
521 
522  for(std::size_t i = 0; i < np; ++i)
523  {
524  if(i != 0)
525  values += ",";
526 
527  values += GetSQLValue(dt->getProperty(i), i, d, conn);
528  }
529 
530  values += ")";
531 
532  return values;
533 }
534 
535 std::string te::pgis::GetSQLValue(const te::dt::Property* p, std::size_t propertyPos, te::da::DataSet* d, PGconn *conn)
536 {
537  std::string value;
538 
539  switch(p->getType())
540  {
541  case te::dt::CHAR_TYPE :
542  value += d->getChar(propertyPos);
543  break;
544 
545  case te::dt::INT16_TYPE :
546  value += boost::lexical_cast<std::string>(d->getInt16(propertyPos));
547  break;
548 
549  case te::dt::INT32_TYPE :
550  value += boost::lexical_cast<std::string>(d->getInt32(propertyPos));
551  break;
552 
553  case te::dt::INT64_TYPE :
554  value += boost::lexical_cast<std::string>(d->getInt64(propertyPos));
555  break;
556 
557  case te::dt::BOOLEAN_TYPE :
558  value += d->getBool(propertyPos) ? "1" : "0";
559  break;
560 
561  case te::dt::FLOAT_TYPE :
562  value += boost::lexical_cast<std::string>(d->getFloat(propertyPos));
563  break;
564 
565  case te::dt::DOUBLE_TYPE :
566  value += boost::lexical_cast<std::string>(d->getDouble(propertyPos));
567  break;
568 
569  case te::dt::NUMERIC_TYPE :
570  value += d->getNumeric(propertyPos);
571  break;
572 
573  case te::dt::STRING_TYPE :
574  {
575  std::string dvalue = d->getString(propertyPos);
576 
577  char* valueto = new char[dvalue.length() * 2 + 1];
578 
579  int pgerror = 0;
580 
581  PQescapeStringConn(conn, valueto, dvalue.c_str(), dvalue.length(), &pgerror);
582 
583  if(pgerror != 0)
584  {
585  delete [] valueto;
586  throw Exception(TE_TR("Could not escape string!"));
587  }
588 
589  value += "'";
590  value += valueto;
591  value += "'";
592 
593  delete [] valueto;
594  }
595  break;
596 
598  {
599  //std::unique_ptr<te::dt::ByteArray> ba(d->getByteArray(propertyPos));
600  //char* hexba = new char[ba->bytesUsed() * 2 + 1];
601  //te::common::Binary2Hex(ba->getData(), ba->bytesUsed(), hexba);
602 
603  //value += "E'\\\\x";
604  //value += hexba;
605  //value += "'";
606 
607  //delete [] hexba;
608 
609  std::unique_ptr<te::dt::ByteArray> ba(d->getByteArray(propertyPos));
610 
611  std::size_t tolen;
612 
613  unsigned char* pgba = PQescapeByteaConn(conn, (const unsigned char*)(ba->getData()), ba->bytesUsed(), &tolen);
614 
615  value += "'";
616  value += (char*)pgba;
617  value += "'";
618 
619  PQfreemem(pgba);
620  }
621  break;
622 
623  case te::dt::GEOMETRY_TYPE :
624  {
625  std::unique_ptr<te::gm::Geometry> geom(d->getGeometry(propertyPos));
626 
627 // get ewkb
628  std::size_t ewkbsize = geom->getWkbSize() + 4;
629 
630  char* ewkb = new char[ewkbsize];
631 
632  EWKBWriter::write(geom.get(), ewkb);
633 
634  char* hewkb = new char[ewkbsize * 2 + 1];
635 
636  te::core::Binary2Hex(ewkb, ewkbsize, hewkb);
637 
638  //value += "GeomFromEWKB(E'\\\\x";
639  value += "'";
640  value += hewkb;
641  value += "'";
642  //value += "')";
643 
644  delete [] ewkb;
645  delete [] hewkb;
646  }
647  break;
648 
649  case te::dt::DATETIME_TYPE :
650  {
651  std::unique_ptr<te::dt::DateTime> dt(d->getDateTime(propertyPos));
652  value += "'";
653  value += dt->toString();
654  value += "'";
655  }
656  break;
657 
658  default :
659  throw Exception(TE_TR("The TerraLib data type is not supported by the PostgreSQL driver!"));
660  }
661 
662  return value;
663 }
664 
666 {
667  std::string values;
668 
669  const std::size_t np = dt->size();
670 
671  for(std::size_t i = 0; i < np; ++i)
672  {
673  if(i != 0)
674  values += ",";
675 
676  values += GetSQLValue(dt->getProperty(i), i, d, conn);
677  }
678 
679  values += "\n";
680 
681  return values;
682 }
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
Property * getProperty(std::size_t i) const
It returns the i-th property.
std::string path() const
Retrieving the path.
Definition: URI.cpp:118
std::string MakeConnectionStr(const te::core::URI &connInfo)
static const std::string sm_intTypeName
The string literal representation for the int type.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
void SplitTableName(const std::string &fullName, const std::string *defaultSchema, std::string &schemaName, std::string &tableName)
void ScapeString(PGconn *conn, const std::string &s, std::string &output)
It escapes a string for use within an SQL command.
static const std::string sm_doubleTypeName
The string literal representation for the double type.
static const std::string sm_pointTypeName
The string literal representation for PostGIS point geometry type.
virtual std::unique_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const =0
Method for retrieving a byte array.
An atomic property like an integer or double.
std::string GetBindableUpdateSQL(const std::vector< te::dt::Property * > &properties)
Given a list of properties it constructs a string with bindable parameters that can be used inside an...
StringType getSubType() const
It returns the string property sub type.
Base exception class for plugin module.
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
static const std::string sm_byteArrayTypeName
The string literal representation for the byte array type.
const std::string & GetGeometryName(te::gm::GeomType t)
It returns the geometry names as usual for PostGIS.
void write(const te::gm::Geometry *geom)
It serializes the geometry to an EWKB representation into the specified buffer.
std::string toString() const
It returns the time duration in the ISO textual format (hh:mm:ss,ss).
struct pg_result PGresult
An utility class for writing a PostGIS EWKB.
static const std::string sm_dateTypeName
The string literal representation for the date type.
static const std::string sm_timeTypeName
The string literal representation for the time type.
static const std::string sm_pointMTypeName
The string literal representation for PostGIS point geometry type.
std::string password() const
Retrieving the password information.
Definition: URI.cpp:103
std::string GetLoadDataRow(const te::da::DataSetType *dt, te::da::DataSet *d, PGconn *conn)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
static const std::string sm_lineStringTypeName
The string literal representation for PostGIS line string geometry type.
std::size_t getWkbSize() const _NOEXCEPT_OP(true)
It returns the size required by a WKB representation for this geometric object.
std::size_t size() const
It returns the maximum number of characters for a varying string, or the number of characters for a f...
It models a property definition.
Definition: Property.h:59
std::string query() const
Retrieving the query.
Definition: URI.cpp:123
std::string GetSQLValues(const te::da::DataSetType *dt, te::da::DataSet *d, PGconn *conn)
static const std::string sm_fixedcharTypeName
The string literal representation for the char type.
static const std::string sm_lineStringMTypeName
The string literal representation for PostGIS line string with m geometry type.
struct pg_conn PGconn
The type for arbitrary precison numbers, like numeric(p, q).
static const std::string sm_stringTypeName
The string literal representation for the string type.
An exception class for the PostGIS driver.
static const std::string sm_int2TypeName
The string literal representation for the int2 type.
static const std::string sm_geometryTypeName
The string literal representation for PostGIS base geometry type.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
static const std::string sm_geometryCollectionMTypeName
The string literal representation for PostGIS geometry collection with m geometry type...
unsigned int getPrecision() const
It returns the count of decimal digits in the fractional part, to the right of the decimal point...
static const std::string sm_floatTypeName
The string literal representation for the float type.
static const std::string sm_multiLineStringTypeName
The string literal representation for PostGIS multi-linestring geometry type.
void Convert2PostGIS(const te::gm::Envelope *e, int srid, std::string &output)
It converts the envelope into a PostGIS BOX3D.
URI C++ Library.
Definition: Attributes.h:37
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
static const std::string sm_multiPointTypeName
The string literal representation for PostGIS multi-point geometry type.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
static const std::string sm_multiLineStringMTypeName
The string literal representation for PostGIS multi-linestring with m geometry type.
static te::dt::TimeDuration dt(20, 30, 50, 11)
static const std::string sm_numericTypeName
The string literal representation for the numeric type.
std::string port() const
Retrieving the port.
Definition: URI.cpp:113
static const std::string sm_charTypeName
The string literal representation for the 1-byte character type.
std::string host() const
Retrieving the host.
Definition: URI.cpp:108
te::gm::Polygon * p
static const std::string sm_timeStampTZTypeName
The string literal representation for the time stamp with time zone type.
bool isRequired() const
It returns true if the attribute is required, otherwise it returns false.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
static const std::string sm_geometryCollectionTypeName
The string literal representation for PostGIS geometry collection geometry type.
std::size_t size() const
It returns the number of properties of the CompositeProperty.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
int getType() const
It returns the property data type.
Definition: Property.h:161
virtual std::unique_ptr< te::dt::DateTime > getDateTime(std::size_t i) const =0
Method for retrieving a date and time attribute value.
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual char getChar(std::size_t i) const =0
Method for retrieving a signed character attribute value (1 byte long).
Property * getElementType() const
It returns the type of array elements.
Definition: ArrayProperty.h:98
The type for variable-length multidimensional arrays.
Definition: ArrayProperty.h:45
This file contains utility functions used to manipulate data from a URI.
unsigned int getPrecision() const
It returns the total count of significant digits in the whole number, that is, the number of digits t...
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
The type for date and time types: date, date period, date duration, time duration, time instant, time period, time instant with time zone or time period with time zone.
static const std::string sm_multiPolygonTypeName
The string literal representation for PostGIS multi-polygon geometry type.
static const std::string sm_multiPointMTypeName
The string literal representation for PostGIS multi-point with m geometry type.
An static class with global definitions.
te::dt::Property * Convert2TerraLib(unsigned int attNum, const char *attName, unsigned int attType, bool attNotNull, const char *fmt, bool attHasDefault, const char *attDefValue, unsigned int pgisGeomTypeOid, unsigned int pgisRasterTypeOid)
It creates a PropertyType from a PostgreSQL attribute description.
virtual bool getBool(std::size_t i) const =0
Method for retrieving a boolean attribute value.
static const std::string sm_polygonTypeName
The string literal representation for PostGIS polygon geometry type.
std::string GetSQLValue(const te::dt::Property *p, std::size_t propertyPos, te::da::DataSet *d, PGconn *conn)
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56
TECOREEXPORT std::string URIDecode(const std::string &srcUri)
Decodes an encoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
std::string * getDefaultValue() const
It returns the default value associated to the property, or NULL if none is associated.
static const std::string sm_polygonMTypeName
The string literal representation for PostGIS polygon with m geometry type.
static const std::string sm_multiPolygonMTypeName
The string literal representation for PostGIS multi-polygon with m geometry type. ...
DateTimeType getSubType() const
It returns the date time property sub type.
bool isAutoNumber() const
It returns true if the attribute is an autonumber, otherwise it returns false.
static const std::string sm_varcharTypeName
The string literal representation for the varchar type.
static const std::string sm_timeStampTypeName
The string literal representation for the time stamp type.
unsigned int getScale() const
It returns the count of decimal digits in the fractional part, to the right of the decimal point...
char * Binary2Hex(const char *s, std::size_t size)
Each char from the array of characters in binary format is converted into a pair of hex characters...
Definition: HexUtils.h:602
std::string user() const
Retrieving the user information.
Definition: URI.cpp:98
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
std::string GetSQLBindValues(std::size_t nproperties)
static const std::string sm_booleanTypeName
The string literal representation for the boolean type.
bool SetColumnDef(std::string &s, const std::string &tname, const te::dt::SimpleProperty *p, bool justDataType=false)
std::string GetBindableWhereSQL(const std::vector< te::dt::Property * > &properties, const std::size_t offset=0)
Given a list of properties it creates an AND connected expression with bindable parameters ($n)...
static const std::string sm_int8TypeName
The string literal representation for the int8 type.