All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "../common/HexUtils.h"
28 #include "../common/Translator.h"
29 #include "../dataaccess/dataset/DataSet.h"
30 #include "../dataaccess/dataset/DataSetType.h"
31 #include "../datatype/ByteArray.h"
32 #include "EWKBWriter.h"
33 #include "Exception.h"
34 #include "Globals.h"
35 #include "Utils.h"
36 
37 // Boost
38 #include <boost/lexical_cast.hpp>
39 
40 // libpq
41 #include <libpq-fe.h>
42 
43 // helper functions
44 namespace te
45 {
46  namespace pgis
47  {
48  inline bool SetColumnDef(std::string& s, const std::string& tname, const te::dt::SimpleProperty* p, bool justDataType = false)
49  {
50  if(p->isAutoNumber() && p->getType() == te::dt::INT32_TYPE)
51  s += "SERIAL";
52  else if(p->isAutoNumber() && p->getType() == te::dt::INT64_TYPE)
53  s += "BIGSERIAL";
54  else
55  s += tname;
56 
57  if(justDataType)
58  return false;
59 
60  if(p->isRequired())
61  s += " NOT NULL";
62 
63  if(p->getDefaultValue() && (p->isAutoNumber() == false))
64  {
65  s += " DEFAULT '";
66  s += *(p->getDefaultValue());
67  s += "'";
68  }
69 
70  return p->isAutoNumber();
71  }
72 
73  inline void SetColumnDef(std::string& s, const te::dt::NumericProperty* p, bool justDataType = false)
74  {
76 
77  if(p->getPrecision() > 0)
78  {
79  s += "(";
81  s += ", ";
83  s += ")";
84  }
85 
86  if(justDataType)
87  return;
88 
89  if(p->isRequired())
90  s += " NOT NULL";
91 
92  if(p->getDefaultValue())
93  {
94  s += " DEFAULT '";
95  s += *(p->getDefaultValue());
96  s += "'";
97  }
98  }
99 
100  inline void SetColumnDef(std::string& s, const std::string& tname, const te::dt::StringProperty* p, bool justDataType = false)
101  {
102  s += tname;
103 
104  if(p->size() > 0 && p->size() < 10485760)
105  {
106  s += "(";
107  s += te::common::Convert2String(static_cast<unsigned int>(p->size()));
108  s += ")";
109  }
110 
111  if(justDataType)
112  return;
113 
114  if(p->isRequired())
115  s += " NOT NULL";
116 
117  if(p->getDefaultValue())
118  {
119  s += " DEFAULT '";
120  s += *(p->getDefaultValue());
121  s += "'";
122  }
123  }
124 
125  inline void SetColumnDef(std::string& s, const te::dt::ArrayProperty* p, bool justDataType = false)
126  {
127  te::dt::Property* elementType = p->getElementType();
128  SetColumnDef(s, elementType, true);
129 
130  s += "[]";
131 
132  if(justDataType)
133  return;
134 
135  if(p->isRequired())
136  s += " NOT NULL";
137 
138  if(p->getDefaultValue())
139  {
140  s += " DEFAULT '";
141  s += *(p->getDefaultValue());
142  s += "'";
143  }
144  }
145  }
146 }
147 
148 // Utils implementation
150 {
151  switch(t)
152  {
153  case te::gm::PointType:
154  case te::gm::PointZType:
155  case te::gm::PointZMType:
156  return Globals::sm_pointTypeName;
157 
158  case te::gm::PointMType:
159  return Globals::sm_pointMTypeName;
160 
164  return Globals::sm_lineStringTypeName;
165 
167  return Globals::sm_lineStringMTypeName;
168 
169  case te::gm::PolygonType:
172  return Globals::sm_polygonTypeName;
173 
174  case te::gm::PolygonMType:
175  return Globals::sm_polygonMTypeName;
176 
180  return Globals::sm_geometryCollectionTypeName;
181 
183  return Globals::sm_geometryCollectionMTypeName;
184 
188  return Globals::sm_multiPointTypeName;
189 
191  return Globals::sm_multiPointMTypeName;
192 
196  return Globals::sm_multiLineStringTypeName;
197 
199  return Globals::sm_multiLineStringMTypeName;
200 
204  return Globals::sm_multiPolygonTypeName;
205 
207  return Globals::sm_multiPolygonMTypeName;
208 
209  default:
210  return Globals::sm_geometryTypeName;
211  }
212 }
213 
214 bool te::pgis::SetColumnDef(std::string& s, const te::dt::Property* p, bool justDataType)
215 {
216  int t = p->getType();
217 
218  bool ret = false;
219 
220  switch(t)
221  {
222  case te::dt::CHAR_TYPE:
223  ret = SetColumnDef(s, Globals::sm_charTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
224  break;
225 
226  case te::dt::INT16_TYPE:
227  ret = SetColumnDef(s, Globals::sm_int2TypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
228  break;
229 
230  case te::dt::INT32_TYPE:
231  ret = SetColumnDef(s, Globals::sm_intTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
232  break;
233 
234  case te::dt::INT64_TYPE:
235  ret = SetColumnDef(s, Globals::sm_int8TypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
236  break;
237 
239  {
240  SetColumnDef(s, static_cast<const te::dt::NumericProperty*>(p), justDataType);
241  }
242  break;
243 
245  {
246  const te::dt::DateTimeProperty* dtp = static_cast<const te::dt::DateTimeProperty*>(p);
247  if(dtp->getSubType() == te::dt::DATE)
248  SetColumnDef(s, Globals::sm_dateTypeName, dtp, justDataType);
249  else if(dtp->getSubType() == te::dt::TIME_DURATION)
250  SetColumnDef(s, Globals::sm_timeTypeName, dtp, justDataType);
251  else if(dtp->getSubType() == te::dt::TIME_INSTANT)
252  SetColumnDef(s, Globals::sm_timeStampTypeName, dtp, justDataType);
253  else if(dtp->getSubType() == te::dt::TIME_INSTANT_TZ)
254  SetColumnDef(s, Globals::sm_timeStampTZTypeName, dtp, justDataType);
255  }
256  break;
257 
258  case te::dt::FLOAT_TYPE:
259  SetColumnDef(s, Globals::sm_floatTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
260  break;
261 
262  case te::dt::DOUBLE_TYPE:
263  SetColumnDef(s, Globals::sm_doubleTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
264  break;
265 
266  case te::dt::STRING_TYPE:
267  {
268  const te::dt::StringProperty* sp = static_cast<const te::dt::StringProperty*>(p);
269 
270  if(sp->getSubType() == te::dt::FIXED_STRING)
271  SetColumnDef(s, Globals::sm_fixedcharTypeName, sp, justDataType);
272  else if(sp->getSubType() == te::dt::VAR_STRING)
273  {
274  if(sp->size() > 10485760)
275  {
276  SetColumnDef(s, Globals::sm_stringTypeName, sp, justDataType);
277  }
278  else
279  {
280  SetColumnDef(s, Globals::sm_varcharTypeName, sp, justDataType);
281  }
282  }
283  else
284  SetColumnDef(s, Globals::sm_stringTypeName, sp, justDataType);
285  }
286  break;
287 
289  SetColumnDef(s, Globals::sm_booleanTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
290  break;
291 
293  SetColumnDef(s, Globals::sm_byteArrayTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
294  break;
295 
297  SetColumnDef(s, Globals::sm_geometryTypeName, static_cast<const te::dt::SimpleProperty*>(p), justDataType);
298  break;
299 
300  case te::dt::ARRAY_TYPE:
301  SetColumnDef(s, static_cast<const te::dt::ArrayProperty*>(p), justDataType);
302  break;
303 
304  default:
305  throw Exception(TE_TR("The informed type could not be mapped to PostgreSQL type system!"));
306  break;
307  }
308 
309  return ret;
310 }
311 
312 void te::pgis::Convert2PostGIS(PGconn* conn, const te::gm::Geometry* g, std::string& output)
313 {
314  std::size_t size = g->getWkbSize() + 4;
315  std::size_t tosize = 0;
316 
317  char* ewkb = new char[size];
318 
319  EWKBWriter::write(g, ewkb);
320  unsigned char* byteArray = PQescapeByteaConn(conn, (unsigned char*)ewkb, size, &tosize);
321  delete [] ewkb;
322 
323  output += "ST_GeomFromEWKB('";
324  output += (char*)byteArray;
325  output += "')";
326 
327  PQfreemem(byteArray);
328 }
329 
330 void te::pgis::ScapeString(PGconn* conn, const std::string& s, std::string& output)
331 {
332  std::size_t length = s.length() ;
333  char* to = new char[2 * length + 1];
334  PQescapeStringConn(conn, to, s.c_str(), length, 0);
335  output += to;
336  delete [] to;
337 }
338 
340  unsigned int pgisGeomTypeOid,
341  unsigned int pgisRasterTypeOid,
342  std::vector<int>& teTypes)
343 {
344  int ncols = PQnfields(result);
345 
346  for(int i = 0; i < ncols; ++i)
347  {
348  std::auto_ptr<te::dt::Property> p(Convert2TerraLib(i, PQfname(result, i), PQftype(result, i),
349  false, 0, false, 0, -1, pgisGeomTypeOid, pgisRasterTypeOid));
350 
351  teTypes.push_back(p->getType());
352  }
353 }
354 
355 std::string te::pgis::MakeConnectionStr(const std::map<std::string, std::string>& dsInfo)
356 {
357  std::map<std::string, std::string>::const_iterator it = dsInfo.find("PG_HOST");
358  std::map<std::string, std::string>::const_iterator it_end = dsInfo.end();
359  std::string connInfo;
360 
361  if(it != it_end)
362  connInfo += " host = " + it->second;
363 
364  it = dsInfo.find("PG_HOST_ADDR");
365 
366  if(it != it_end)
367  connInfo += " hostaddr = " + it->second;
368 
369  it = dsInfo.find("PG_PORT");
370 
371  if(it != it_end)
372  connInfo += " port = " + it->second;
373 
374  it = dsInfo.find("PG_DB_NAME");
375 
376  if(it != it_end)
377  connInfo += " dbname = " + it->second;
378 
379  it = dsInfo.find("PG_USER");
380 
381  if(it != it_end)
382  connInfo += " user = " + it->second;
383 
384  it = dsInfo.find("PG_PASSWORD");
385 
386  if((it != it_end) && (!it->second.empty()))
387  connInfo += " password = " + it->second;
388 
389  it = dsInfo.find("PG_CONNECT_TIMEOUT");
390 
391  if(it != it_end)
392  connInfo += " connect_timeout = " + it->second;
393 
394  it = dsInfo.find("PG_OPTIONS");
395 
396  if(it != it_end)
397  connInfo += " options = " + it->second;
398 
399  it = dsInfo.find("PG_SSL_MODE");
400 
401  if(it != it_end)
402  connInfo += " sslmode = " + it->second;
403 
404  it = dsInfo.find("PG_KRBSRVNAME");
405 
406  if(it != it_end)
407  connInfo += " krbsrvname = " + it->second;
408 
409  it = dsInfo.find("PG_GSSLIB");
410 
411  if(it != it_end)
412  connInfo += " gsslib = " + it->second;
413 
414  return connInfo;
415 }
416 
417 void te::pgis::SplitTableName(const std::string& fullName, const std::string* defaultSchema, std::string& schemaName, std::string& tableName)
418 {
419  assert(defaultSchema);
420 
421 // split schema-name.table-name if needed
422  size_t pos = fullName.find(".");
423 
424  if(pos == std::string::npos)
425  {
426  tableName = fullName;
427  schemaName = *defaultSchema;
428  }
429  else
430  {
431  tableName = fullName.substr(pos + 1);
432  schemaName = fullName.substr(0, pos);
433  }
434 }
435 
436 std::string te::pgis::GetBindableWhereSQL(const std::vector<te::dt::Property*>& properties, const std::size_t offset)
437 {
438  std::string wheresql;
439 
440  const std::size_t size = properties.size();
441 
442  for(std::size_t i = 0; i < size; ++i)
443  {
444  if(i != 0)
445  wheresql += " AND ";
446 
447  wheresql += properties[i]->getName();
448 
449  wheresql += " = $" + boost::lexical_cast<std::string>(i + 1 + offset);
450  }
451 
452  return wheresql;
453 }
454 
455 std::string te::pgis::GetSQLBindValues(std::size_t nproperties)
456 {
457  std::string valueNames("(");
458 
459  for(std::size_t i = 0; i < nproperties; ++i)
460  {
461  if(i != 0)
462  valueNames += ",";
463 
464  valueNames += "$" + boost::lexical_cast<std::string>(i + 1);
465  }
466 
467  valueNames += ")";
468 
469  return valueNames;
470 }
471 
472 std::string te::pgis::GetBindableUpdateSQL(const std::vector<te::dt::Property*>& properties)
473 {
474  std::string sql;
475 
476  const std::size_t size = properties.size();
477 
478  for(std::size_t i = 0; i < size; ++i)
479  {
480  if(i != 0)
481  sql += ", ";
482 
483  sql += properties[i]->getName();
484 
485  sql += " = $" + boost::lexical_cast<std::string>(i + 1);
486  }
487 
488  return sql;
489 }
490 
492 {
493  std::string values("(");
494 
495  const std::size_t np = dt->size();
496 
497  for(std::size_t i = 0; i < np; ++i)
498  {
499  if(i != 0)
500  values += ",";
501 
502  values += GetSQLValue(dt->getProperty(i), i, d, conn);
503  }
504 
505  values += ")";
506 
507  return values;
508 }
509 
510 std::string te::pgis::GetSQLValue(const te::dt::Property* p, std::size_t propertyPos, te::da::DataSet* d, PGconn *conn)
511 {
512  std::string value;
513 
514  switch(p->getType())
515  {
516  case te::dt::CHAR_TYPE :
517  value += d->getChar(propertyPos);
518  break;
519 
520  case te::dt::INT16_TYPE :
521  value += boost::lexical_cast<std::string>(d->getInt16(propertyPos));
522  break;
523 
524  case te::dt::INT32_TYPE :
525  value += boost::lexical_cast<std::string>(d->getInt32(propertyPos));
526  break;
527 
528  case te::dt::INT64_TYPE :
529  value += boost::lexical_cast<std::string>(d->getInt64(propertyPos));
530  break;
531 
532  case te::dt::BOOLEAN_TYPE :
533  value += d->getBool(propertyPos) ? "1" : "0";
534  break;
535 
536  case te::dt::FLOAT_TYPE :
537  value += boost::lexical_cast<std::string>(d->getFloat(propertyPos));
538  break;
539 
540  case te::dt::DOUBLE_TYPE :
541  value += boost::lexical_cast<std::string>(d->getDouble(propertyPos));
542  break;
543 
544  case te::dt::NUMERIC_TYPE :
545  value += d->getNumeric(propertyPos);
546  break;
547 
548  case te::dt::STRING_TYPE :
549  {
550  std::string dvalue = d->getString(propertyPos);
551 
552  char* valueto = new char[dvalue.length() * 2 + 1];
553 
554  int pgerror = 0;
555 
556  PQescapeStringConn(conn, valueto, dvalue.c_str(), dvalue.length(), &pgerror);
557 
558  if(pgerror != 0)
559  {
560  delete [] valueto;
561  throw Exception(TE_TR("Could not escape string!"));
562  }
563 
564  value += "'";
565  value += valueto;
566  value += "'";
567 
568  delete [] valueto;
569  }
570  break;
571 
573  {
574  //std::auto_ptr<te::dt::ByteArray> ba(d->getByteArray(propertyPos));
575  //char* hexba = new char[ba->bytesUsed() * 2 + 1];
576  //te::common::Binary2Hex(ba->getData(), ba->bytesUsed(), hexba);
577 
578  //value += "E'\\\\x";
579  //value += hexba;
580  //value += "'";
581 
582  //delete [] hexba;
583 
584  std::auto_ptr<te::dt::ByteArray> ba(d->getByteArray(propertyPos));
585 
586  std::size_t tolen;
587 
588  unsigned char* pgba = PQescapeByteaConn(conn, (const unsigned char*)(ba->getData()), ba->bytesUsed(), &tolen);
589 
590  value += "'";
591  value += (char*)pgba;
592  value += "'";
593 
594  PQfreemem(pgba);
595  }
596  break;
597 
598  case te::dt::GEOMETRY_TYPE :
599  {
600  std::auto_ptr<te::gm::Geometry> geom(d->getGeometry(propertyPos));
601 
602 // get ewkb
603  std::size_t ewkbsize = geom->getWkbSize() + 4;
604 
605  char* ewkb = new char[ewkbsize];
606 
607  EWKBWriter::write(geom.get(), ewkb);
608 
609  char* hewkb = new char[ewkbsize * 2 + 1];
610 
611  te::common::Binary2Hex(ewkb, ewkbsize, hewkb);
612 
613  //value += "GeomFromEWKB(E'\\\\x";
614  value += "'";
615  value += hewkb;
616  value += "'";
617  //value += "')";
618 
619  delete [] ewkb;
620  delete [] hewkb;
621  }
622  break;
623 
624  case te::dt::DATETIME_TYPE :
625  {
626  std::auto_ptr<te::dt::DateTime> dt(d->getDateTime(propertyPos));
627  value += "'";
628  value += dt->toString();
629  value += "'";
630  }
631  break;
632 
633  default :
634  throw Exception(TE_TR("The TerraLib data type is not supported by the PostgreSQL driver!"));
635  }
636 
637  return value;
638 }
639 
641 {
642  std::string values;
643 
644  const std::size_t np = dt->size();
645 
646  for(std::size_t i = 0; i < np; ++i)
647  {
648  if(i != 0)
649  values += ",";
650 
651  values += GetSQLValue(dt->getProperty(i), i, d, conn);
652  }
653 
654  values += "\n";
655 
656  return values;
657 }
658 
659 static std::size_t sg_n_encoding = 8;
660 static const char* sg_pg_encoding [] = {"UTF8", "WIN1250", "WIN1251", "WIN1252", "WIN1253", "WIN1254", "WIN1257", "LATIN1"};
661 
663 {
664  return sg_pg_encoding[encoding];
665 }
666 
668 {
669  for(std::size_t i = 0; i < sg_n_encoding; ++i)
670  {
671  if(strcmp(sg_pg_encoding[i],encoding) == 0)
672  return (te::common::CharEncoding)i;
673  }
674 
676 }
Property * getProperty(std::size_t i) const
It returns the i-th property.
virtual std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const =0
Method for retrieving a date and time attribute value.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
std::string MakeConnectionStr(const std::map< std::string, std::string > &dsInfo)
Definition: Utils.cpp:355
void SplitTableName(const std::string &fullName, const std::string *defaultSchema, std::string &schemaName, std::string &tableName)
Definition: Utils.cpp:417
void ScapeString(PGconn *conn, const std::string &s, std::string &output)
It escapes a string for use within an SQL command.
Definition: Utils.cpp:330
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
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...
Definition: Utils.cpp:472
CharEncoding
Supported charsets (character encoding).
StringType getSubType() const
It returns the string property sub type.
virtual char getChar(std::size_t i) const =0
Method for retrieving a signed character attribute value (1 byte long).
virtual bool getBool(std::size_t i) const =0
Method for retrieving a boolean attribute value.
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
const std::string & GetGeometryName(te::gm::GeomType t)
It returns the geometry names as usual for PostGIS.
Definition: Utils.cpp:149
struct pg_result PGresult
Definition: Connection.h:48
An static class with global definitions.
virtual std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const =0
Method for retrieving a byte array.
std::string GetLoadDataRow(const te::da::DataSetType *dt, te::da::DataSet *d, PGconn *conn)
Definition: Utils.cpp:640
const char * GetPGEncoding(te::common::CharEncoding encoding)
Definition: Utils.cpp:662
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
std::size_t getWkbSize() const
It returns the size required by a WKB representation for this geometric object.
Definition: Geometry.cpp:134
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
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
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
std::string GetSQLValues(const te::da::DataSetType *dt, te::da::DataSet *d, PGconn *conn)
Definition: Utils.cpp:491
struct pg_conn PGconn
Definition: Connection.h:45
The type for arbitrary precison numbers, like numeric(p, q).
An utility class for writing a PostGIS EWKB.
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
Utility functions for PostgreSQL.
void Convert2PostGIS(const te::gm::Envelope *e, int srid, std::string &output)
It converts the envelope into a PostGIS BOX3D.
Definition: Utils.h:225
TEOGREXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
Definition: Utils.cpp:55
static const char * sg_pg_encoding[]
Definition: Utils.cpp:660
static const std::string sm_numericTypeName
The string literal representation for the numeric type.
Definition: Globals.h:62
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.
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.
Definition: Geometry.h:73
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
int getType() const
It returns the property data type.
Definition: Property.h:161
void SetColumnDef(std::string &s, const te::dt::ArrayProperty *p, bool justDataType=false)
Definition: Utils.cpp:125
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
te::common::CharEncoding GetTeEncoding(const char *const encoding)
Definition: Utils.cpp:667
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
static std::size_t sg_n_encoding
Definition: Utils.cpp:659
An exception class for the PostGIS driver.
unsigned int getPrecision() const
It returns the total count of significant digits in the whole number, that is, the number of digits t...
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.
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.
Definition: Utils.h:456
std::string GetSQLValue(const te::dt::Property *p, std::size_t propertyPos, te::da::DataSet *d, PGconn *conn)
Definition: Utils.cpp:510
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:51
std::string * getDefaultValue() const
It returns the default value associated to the property, or NULL if none is associated.
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.
unsigned int getScale() const
It returns the count of decimal digits in the fractional part, to the right of the decimal point...
std::string GetSQLBindValues(std::size_t nproperties)
Definition: Utils.cpp:455
bool SetColumnDef(std::string &s, const std::string &tname, const te::dt::SimpleProperty *p, bool justDataType=false)
Definition: Utils.cpp:48
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)...
Definition: Utils.cpp:436