All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSet.cpp
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/postgis/DataSet.cpp
22 
23  \brief Implementation of a dataset for the PostGIS driver.
24 */
25 
26 // TerraLib
27 #include "../Defines.h"
28 #include "../common/ByteSwapUtils.h"
29 #include "../common/Globals.h"
30 #include "../common/StringUtils.h"
31 #include "../common/Translator.h"
32 #include "../dataaccess/dataset/DataSetType.h"
33 #include "../datatype/Array.h"
34 #include "../datatype/ByteArray.h"
35 #include "../datatype/DateTime.h"
36 #include "../datatype/SimpleData.h"
37 #include "../geometry/Geometry.h"
38 #include "Connection.h"
39 #include "ConnectionPool.h"
40 //#include "CatalogLoader.h"
41 #include "DataSet.h"
42 #include "DataSource.h"
43 #include "EWKBReader.h"
44 #include "Exception.h"
45 #include "Utils.h"
46 
47 // STL
48 #include <cassert>
49 #include <memory>
50 
51 // Boost
52 #include <boost/dynamic_bitset.hpp>
53 
54 // libpq
55 #include <libpq-fe.h>
56 
57 namespace te
58 {
59  namespace pgis
60  {
61  /*!
62  \brief It retrieves information from an unidimensional array.
63 
64  Requirements on types:
65  <ul>
66  <li>T: the type of basic elements of the array.</li>
67  <li>ALIGN: the size in bytes of pointer alignment for the type T.</li>
68  </ul>
69 
70  \param i The row.
71  \param j The column.
72  \param result The result to extract the array.
73  \param a The output vector.
74 
75  \warning Don't call this method for multidimensional arrays!
76  */
77  template<class T, class ALIGN> inline void GetArray(int i, int j, PGresult* result, std::vector<T>& a)
78  {
79  char* value = PQgetvalue(result, i, j);
80 
81  int ndim = *((int*)value);
82  value += sizeof(int);
83 
84  int dataoffset = *((int*)value);
85  value += sizeof(int);
86 
87  unsigned int elemtype = *((unsigned int*)value);
88  value += sizeof(unsigned int);
89 
90  int dimension = *((int*)value);
91  value += sizeof(int);
92 
93  int lowerbnds = *((int*)value);
94  value += (2 * sizeof(int)); //jump null-bitmap field
95 
97  {
99  te::common::SwapBytes(dataoffset);
100  te::common::SwapBytes(elemtype);
101  te::common::SwapBytes(dimension);
102  te::common::SwapBytes(lowerbnds);
103 
104  a.reserve(dimension);
105 
106  for(int k = 0; k < dimension; ++k)
107  {
108  T v = *((T*)value);
110  a.push_back(v);
111  value += sizeof(ALIGN);
112  }
113  }
114  else
115  {
116  a.reserve(dimension);
117 
118  for(int k = 0; k < dimension; ++k)
119  {
120  T v = *((T*)value);
121  a.push_back(v);
122  value += sizeof(ALIGN);
123  }
124  }
125  }
126 
127  } // end namespace pgis
128 } // end namespace te
129 
131  const std::vector<int>& ptypes,
132  bool timeIsInteger,
133  const te::common::CharEncoding& ce)
134  : m_i(-1),
135  m_result(result),
136  m_ptypes(ptypes),
137  m_mbr(0),
138  m_timeIsInteger(timeIsInteger),
139  m_ce(ce)
140 {
141  m_size = PQntuples(m_result);
142 }
143 
145 {
146  PQclear(m_result);
147 }
148 
150 {
151  return te::common::RANDOM;
152 }
153 
155 {
156  return te::common::RAccess;
157 }
158 
160 {
161  return PQnfields(m_result);
162 }
163 
165 {
166  return m_ptypes[i];
167 }
168 
169 std::string te::pgis::DataSet::getPropertyName(std::size_t i) const
170 {
171  return PQfname(m_result, i);
172 }
173 
175 {
176  assert(i < m_ptypes.size());
177  assert(m_ptypes[i] == te::dt::STRING_TYPE);
178 
179  return m_ce;
180 }
181 
182 std::string te::pgis::DataSet::getDatasetNameOfProperty(std::size_t i) const
183 {
184  throw Exception(TE_TR("Not implemented yet!"));
185 }
186 
188 {
189  return (m_size == 0);
190 }
191 
193 {
194  return false;
195 }
196 
197 std::size_t te::pgis::DataSet::size() const
198 {
199  return m_size;
200 }
201 
202 std::auto_ptr<te::gm::Envelope> te::pgis::DataSet::getExtent(std::size_t i)
203 {
204  if(!m_mbr)
205  {
206  if(m_ptypes[i] != te::dt::GEOMETRY_TYPE)
207  throw Exception(TE_TR("This driver only supports the getExtent method over a geometry column!"));
208 
209  m_mbr = new te::gm::Envelope;
210 
211  m_i = -1;
212  while(moveNext())
213  {
214  std::auto_ptr<te::gm::Geometry> geom(getGeometry(i));
215  m_mbr->Union(*(geom->getMBR()));
216  }
217  }
218 
219  m_i = -1;
220 
221  te::gm::Envelope* mbr = new te::gm::Envelope(*m_mbr);
222 
223  return std::auto_ptr<te::gm::Envelope>(mbr);
224 }
225 
227 {
228  ++m_i;
229  return (m_i < m_size);
230 }
231 
233 {
234  --m_i;
235  return (m_i > -1);
236 }
237 
239 {
240  m_i = 0;
241  return m_size != 0;
242 }
243 
245 {
246  m_i = m_size - 1;
247  return (m_i < m_size);
248 }
249 
251 {
252  m_i = -1;
253  return m_size != 0;;
254 }
255 
256 bool te::pgis::DataSet::move(std::size_t i)
257 {
258  m_i = static_cast<int>(i);
259  return (m_i < m_size);
260 }
261 
263 {
264  return m_i == 0;
265 }
266 
268 {
269  return m_i < 0;
270 }
271 
273 {
274  return m_i == (m_size - 1);
275 }
276 
278 {
279  return m_i >= m_size;
280 }
281 
282 char te::pgis::DataSet::getChar(std::size_t i) const
283 {
284  char cval = *(PQgetvalue(m_result, m_i, i));
285  return cval;
286 }
287 
288 unsigned char te::pgis::DataSet::getUChar(std::size_t i) const
289 {
290  unsigned char cval = *(PQgetvalue(m_result, m_i, i));
291  return cval;
292 }
293 
294 boost::int16_t te::pgis::DataSet::getInt16(std::size_t i) const
295 {
296  short int ival = *((short int*)(PQgetvalue(m_result, m_i, i)));
297 
298 #if TE_MACHINE_BYTE_ORDER == TE_NDR
299  te::common::SwapBytes(ival);
300 #endif
301 
302  return ival;
303 }
304 
305 boost::int32_t te::pgis::DataSet::getInt32(std::size_t i) const
306 {
307  int ival = *((int*)(PQgetvalue(m_result, m_i, i)));
308 
309 #if TE_MACHINE_BYTE_ORDER == TE_NDR
310  te::common::SwapBytes(ival);
311 #endif
312 
313  return ival;
314 }
315 
316 boost::int64_t te::pgis::DataSet::getInt64(std::size_t i) const
317 {
318  long long int ival = *((long long int*)(PQgetvalue(m_result, m_i, i)));
319 
320 #if TE_MACHINE_BYTE_ORDER == TE_NDR
321  te::common::SwapBytes(ival);
322 #endif
323 
324  return ival;
325 }
326 
327 bool te::pgis::DataSet::getBool(std::size_t i) const
328 {
329  char bval = *(PQgetvalue(m_result, m_i, i));
330  return bval != 0;
331 }
332 
333 float te::pgis::DataSet::getFloat(std::size_t i) const
334 {
335  float fval = *((float*)(PQgetvalue(m_result, m_i, i)));
336 
337 #if TE_MACHINE_BYTE_ORDER == TE_NDR
338  te::common::SwapBytes(fval);
339 #endif
340 
341  return fval;
342 }
343 
344 double te::pgis::DataSet::getDouble(std::size_t i) const
345 {
346  double dval = *((double*)(PQgetvalue(m_result, m_i, i)));
347 
348 #if TE_MACHINE_BYTE_ORDER == TE_NDR
349  te::common::SwapBytes(dval);
350 #endif
351 
352  return dval;
353 }
354 
355 std::string te::pgis::DataSet::getNumeric(std::size_t i) const
356 {
357  char* val = PQgetvalue(m_result, m_i, i);
358 
359 // get number of groups of 2 bytes used to represent the numeric number
360 // each 2 bytes represents 4 digits (ex: 2345678.87654 needs 4 groups. 2 to integer and 2 to decimals)
361  unsigned short totalGroups; // total number of groups
362 
363  totalGroups = *((unsigned short*)val);
364 
365 #if TE_MACHINE_BYTE_ORDER == TE_NDR
366  te::common::SwapBytes(totalGroups);
367 #endif
368 
369  if(totalGroups == 0)
370  return "0";
371 
372 // get number of groups of 2 bytes used to represent the decimal part of the number
373  unsigned short decimalGroups; // total number of groups
374 
375  decimalGroups = *((unsigned short*)(val+2));
376 
377 #if TE_MACHINE_BYTE_ORDER == TE_NDR
378  te::common::SwapBytes(decimalGroups);
379 #endif
380 
381  ++decimalGroups;
382 
383  decimalGroups = totalGroups - decimalGroups;
384 
385 // get sign of the number
386  unsigned short sign; // sign of the number (positive: sign = 0, negative: sign = 0x4000)
387 
388  sign = *((unsigned short*)(val+4));
389 
390 #if TE_MACHINE_BYTE_ORDER == TE_NDR
391  te::common::SwapBytes(sign);
392 #endif
393 
394  if(!(sign == 0 || sign == 0x4000))
395  return "";
396 
397  std::string intVal;
398 
399  if(sign != 0)
400  intVal = "-";
401 
402 //get integer part
403  unsigned short n;
404 
405  short ii = 0;
406 
407  while(ii < ((totalGroups - decimalGroups) * 2))
408  {
409  n = *((unsigned short*)(val + ii + 8));
410 
411 #if TE_MACHINE_BYTE_ORDER == TE_NDR
413 #endif
414 
415  intVal += te::common::Convert2String(n);
416 
417  ii += 2;
418  }
419 
420  if(ii == 0)
421  intVal += "0";
422 
423 //get decimal part
424  std::string decVal;
425 
426  if(decimalGroups == 0)
427  decVal = "0";
428  else
429  {
430  while(ii < (totalGroups * 2))
431  {
432  n = *((unsigned short*)(val + ii + 8));
433 
434 #if TE_MACHINE_BYTE_ORDER == TE_NDR
436 #endif
437 
438  std::string newVal = te::common::Convert2String(n);
439 
440  while (newVal.length() < 4) //fill with zeros (ex: .0700 was "700")
441  newVal = "0" + newVal;
442 
443  decVal += newVal;
444 
445  ii += 2;
446  }
447 
448  while((decVal.empty() == false) && (decVal[decVal.length() - 1] == '0'))
449  decVal.erase(decVal.length() - 1);
450  }
451 
452  return intVal + "." + decVal;
453 }
454 
455 std::string te::pgis::DataSet::getString(std::size_t i) const
456 {
457  std::string value(PQgetvalue(m_result, m_i, i));
458  return value;
459 }
460 
461 std::auto_ptr<te::dt::ByteArray> te::pgis::DataSet::getByteArray(std::size_t i) const
462 {
463  int size = PQgetlength(m_result, m_i, i);
464 
465  te::dt::ByteArray* b = new te::dt::ByteArray(size);
466  b->copy(PQgetvalue(m_result, m_i, i), size);
467  return std::auto_ptr<te::dt::ByteArray>(b);
468 }
469 
470 std::auto_ptr<te::gm::Geometry> te::pgis::DataSet::getGeometry(std::size_t i) const
471 {
472  return std::auto_ptr<te::gm::Geometry>(EWKBReader::read(PQgetvalue(m_result, m_i, i)));
473 }
474 
475 std::auto_ptr<te::rst::Raster> te::pgis::DataSet::getRaster(std::size_t /*i*/) const
476 {
477  return std::auto_ptr<te::rst::Raster>(0);
478 }
479 
480 std::auto_ptr<te::dt::DateTime> te::pgis::DataSet::getDateTime(std::size_t i) const
481 {
482  Oid tid = PQftype(m_result, i);
483  boost::int64_t ival = 0;
484  int iz;
485  double dval;
486  long int lval;
487 
488  switch(tid)
489  {
490  case PG_TIME_TYPE:
491  {
492  if(m_timeIsInteger)
493  {
494  ival = getInt64(i);
495  }
496  else
497  {
498  dval = getDouble(i);
499  ival = (boost::int64_t)(dval * 1000000);
500  }
501 
502  return std::auto_ptr<te::dt::DateTime>(Internal2Time(ival));
503  }
504 
505  case PG_DATE_TYPE:
506  {
507  char* val = PQgetvalue(m_result, m_i, i);
508  lval = *((long int*)val);
509 
510 #if TE_MACHINE_BYTE_ORDER == TE_NDR
511  te::common::SwapBytes(lval);
512 #endif
513 
514  return std::auto_ptr<te::dt::DateTime>(Internal2Date(lval));
515  }
516 
517  case PG_TIMESTAMP_TYPE:
518  {
519  if(m_timeIsInteger)
520  ival = getInt64(i);
521  else
522  {
523  dval = getDouble(i);
524  ival = (boost::int64_t)(dval * 1000000);
525  }
526 
527  return std::auto_ptr<te::dt::DateTime>(Internal2TimeStamp(ival));
528  }
529 
530  case PG_TIMESTAMPTZ_TYPE:
531  {
532  if(m_timeIsInteger)
533  ival = getInt64(i);
534  else
535  {
536  char* c = (char*)PQgetvalue(m_result, m_i, i);
537  dval = *((double*)c);
538 
539  #if TE_MACHINE_BYTE_ORDER == TE_NDR
540  te::common::SwapBytes(dval);
541  #endif
542 
543  ival = (boost::int64_t)(dval * 1000000);
544  }
545  return std::auto_ptr<te::dt::DateTime>(Internal2TimeStamp(ival));
546  }
547  case PG_TIMETZ_TYPE:
548  {
549  if(m_timeIsInteger)
550  {
551  ival = getInt64(i);
552  iz = 0;
553  }
554  else
555  {
556  char* c = (char*)PQgetvalue(m_result, m_i, i);
557  dval = *((double*)c);
558  c += 8;
559  iz = *((int*)c);
560 
561  #if TE_MACHINE_BYTE_ORDER == TE_NDR
562  te::common::SwapBytes(dval);
564  #endif
565 
566  ival = (boost::int64_t)(dval * 1000000);
567  }
568  iz /= 3600;
569  if(iz < -12)
570  iz = -12;
571  if(iz > 14)
572  iz = 14;
573  return std::auto_ptr<te::dt::DateTime>(Internal2TimeTZ(ival, iz));
574  }
575 
576  default:
577  throw Exception(TE_TR("This type is not supported by TerraLib!"));
578  }
579 }
580 
581 std::auto_ptr<te::dt::Array> te::pgis::DataSet::getArray(std::size_t i) const
582 {
583  char* value = PQgetvalue(m_result, m_i, i);
584 
585  int ndim = *((int*)value);
586  value += sizeof(int);
587 
588 #if TE_MACHINE_BYTE_ORDER == TE_NDR
589  te::common::SwapBytes(ndim);
590 #endif
591 
592  int dataoffset = *((int*)value);
593  value += sizeof(int);
594 
595 #if TE_MACHINE_BYTE_ORDER == TE_NDR
596  te::common::SwapBytes(dataoffset);
597 #endif
598 
599  unsigned int elemtype = *((unsigned int*)value);
600  value += sizeof(unsigned int);
601 
602 #if TE_MACHINE_BYTE_ORDER == TE_NDR
603  te::common::SwapBytes(elemtype);
604 #endif
605 
606  int* dimensions = (int*)value;
607  value += ndim * sizeof(int);
608 
609  int* lowerbounds = (int*)value;
610  value += ndim * sizeof(int);
611 
612  uint32_t* null_bitmap = (unsigned int*)value;
613 
614  boost::dynamic_bitset<> mask;
615 
616  if(dataoffset != 0)
617  {
618  int nmasks = (dataoffset + 3) / 4;
619 
620  mask.resize(nmasks * 8 * sizeof(uint32_t));
621 
622  int pos = 0;
623 
624  for(int i = 0; i != nmasks; ++i)
625  {
626  value += sizeof(uint32_t);
627 
628  uint32_t umask = null_bitmap[i];
629 
630 #if TE_MACHINE_BYTE_ORDER == TE_NDR
631  te::common::SwapBytes(umask);
632 #endif
633 
634  for(int j = 0; j != 32; ++j)
635  {
636  mask[pos] = ((umask >> j) & 1) == 0;
637  ++pos;
638  }
639  }
640  }
641  else
642  {
643  value += sizeof(uint32_t);
644  }
645 
646  switch(elemtype)
647  {
648  case PG_TEXT_TYPE:
649  case PG_VARCHAR_TYPE:
650  case PG_NAME_TYPE:
651  {
652  std::auto_ptr<te::dt::Array> arr(new te::dt::Array(ndim, te::dt::STRING_TYPE));
653 
654  std::vector<std::size_t> pos(ndim, 0);
655 
656  for(int d = 0; d != ndim; ++d)
657  {
658  int d_size = dimensions[d];
659 
660 #if TE_MACHINE_BYTE_ORDER == TE_NDR
661  te::common::SwapBytes(d_size);
662 #endif
663  int d_lower_boundary = lowerbounds[d];
664 
665 #if TE_MACHINE_BYTE_ORDER == TE_NDR
666  te::common::SwapBytes(d_lower_boundary);
667 #endif
668 
669  for(i = 0; i != d_size; ++i)
670  {
671  if((dataoffset != 0) && (mask[i] == false))
672  {
673  arr->insert(0, pos);
674  continue;
675  }
676 
677  pos[d] = i;
678 
679  int text_size = *(int*)value;
680 
681 #if TE_MACHINE_BYTE_ORDER == TE_NDR
682  te::common::SwapBytes(text_size);
683 #endif
684  value += sizeof(int);
685 
686  arr->insert(new te::dt::String(value), pos);
687 
688  value += text_size;
689  }
690  }
691 
692  return std::auto_ptr<te::dt::Array>(arr.release());
693  }
694  break;
695 
696  case PG_FLOAT8_TYPE:
697  {
698  std::auto_ptr<te::dt::Array> arr(new te::dt::Array(ndim, te::dt::DOUBLE_TYPE));
699 
700  std::vector<std::size_t> pos(ndim, 0);
701 
702  for(int d = 0; d != ndim; ++d)
703  {
704  int d_size = dimensions[d];
705 
706 #if TE_MACHINE_BYTE_ORDER == TE_NDR
707  te::common::SwapBytes(d_size);
708 #endif
709  int d_lower_boundary = lowerbounds[d];
710 
711 #if TE_MACHINE_BYTE_ORDER == TE_NDR
712  te::common::SwapBytes(d_lower_boundary);
713 #endif
714 
715  for(i = 0; i != d_size; ++i)
716  {
717  if((dataoffset != 0) && (mask[i] == false))
718  {
719  arr->insert(0, pos);
720  continue;
721  }
722 
723  pos[d] = i;
724 
725  double val = *(double*)value;
726 
727 #if TE_MACHINE_BYTE_ORDER == TE_NDR
729 #endif
730 
731  arr->insert(new te::dt::Double(val), pos);
732 
733  value += sizeof(double);
734  }
735  }
736 
737  return std::auto_ptr<te::dt::Array>(arr.release());
738  }
739  break;
740 
741  case PG_INT2_TYPE:
742  {
743  std::auto_ptr<te::dt::Array> arr(new te::dt::Array(ndim, te::dt::INT16_TYPE));
744 
745  std::vector<std::size_t> pos(ndim, 0);
746 
747  for(int d = 0; d != ndim; ++d)
748  {
749  int d_size = dimensions[d];
750 
751 #if TE_MACHINE_BYTE_ORDER == TE_NDR
752  te::common::SwapBytes(d_size);
753 #endif
754  int d_lower_boundary = lowerbounds[d];
755 
756 #if TE_MACHINE_BYTE_ORDER == TE_NDR
757  te::common::SwapBytes(d_lower_boundary);
758 #endif
759 
760  for(i = 0; i != d_size; ++i)
761  {
762  if((dataoffset != 0) && (mask[i] == false))
763  {
764  arr->insert(0, pos);
765  continue;
766  }
767 
768  pos[d] = i;
769 
770  boost::uint16_t val = *(boost::uint16_t*)value;
771 
772 #if TE_MACHINE_BYTE_ORDER == TE_NDR
774 #endif
775 
776  arr->insert(new te::dt::Int16(val), pos);
777 
778  value += sizeof(uint32_t);
779  }
780  }
781 
782  return std::auto_ptr<te::dt::Array>(arr.release());
783  }
784  break;
785 
786  default:
787  throw Exception(TE_TR("The array element type is not supported yet!"));
788  }
789 
790  // {
791  // te::common::SwapBytes(ndim);
792  // te::common::SwapBytes(dataoffset);
793  // te::common::SwapBytes(elemtype);
794  // te::common::SwapBytes(dimension);
795  // te::common::SwapBytes(lowerbnds);
796 
797  // a.reserve(dimension);
798 
799  // for(int k = 0; k < dimension; ++k)
800  // {
801  // T v = *((T*)value);
802  // te::common::SwapBytes(v);
803  // a.push_back(v);
804  // value += sizeof(ALIGN);
805  // }
806  // }
807  // else
808  // {
809  // a.reserve(dimension);
810 
811  // for(int k = 0; k < dimension; ++k)
812  // {
813  // T v = *((T*)value);
814  // a.push_back(v);
815  // value += sizeof(ALIGN);
816  // }
817  // }
818 }
819 
820 bool te::pgis::DataSet::isNull(std::size_t i) const
821 {
822  return PQgetisnull(m_result, m_i, i) == 1;
823 }
An utility class for reading a PostGIS EWKB.
static te::gm::Geometry * read(const char *ewkb)
It returns a valid geometry from a given EWKB.
Definition: EWKBReader.cpp:134
CharEncoding
Supported charsets (character encoding).
te::common::CharEncoding getPropertyCharEncoding(std::size_t i) const
It returns the property character encoding at position pos.
Definition: DataSet.cpp:174
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
Definition: DataSet.cpp:256
#define PG_FLOAT8_TYPE
Definition: Config.h:111
bool moveFirst()
It moves the internal pointer to the first item in the collection.
Definition: DataSet.cpp:238
te::dt::DateTime * Internal2TimeTZ(boost::int64_t tval, int z)
Definition: Utils.h:377
te::dt::DateTime * Internal2Date(const long dDate)
It returns a DateTime type from a date loaded by PostgreSQL.
Definition: Utils.h:343
int m_size
The number of datasets in the collection.
Definition: DataSet.h:171
DataSet()
Default constructor.
Definition: DataSet.h:117
#define PG_INT2_TYPE
Definition: Config.h:105
double getDouble(const std::string &value, std::vector< std::string > &sVector)
Definition: Utils.cpp:59
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
Definition: DataSet.cpp:232
struct pg_result PGresult
Definition: Connection.h:48
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
Definition: Globals.h:54
#define PG_TEXT_TYPE
Definition: Config.h:108
te::dt::DateTime * Internal2TimeStamp(boost::int64_t ival)
It returns a DateTime type from a timestamp loaded by PostgreSQL.
Definition: Utils.h:413
#define PG_TIME_TYPE
Definition: Config.h:115
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:345
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
Definition: DataSet.cpp:154
std::string getPropertyName(std::size_t i) const
It returns the property name at position pos.
Definition: DataSet.cpp:169
int getPropertyDataType(std::size_t i) const
It returns the underlying data type of the property at position pos.
Definition: DataSet.cpp:164
~DataSet()
The destructor will clear the internal PGresult.
Definition: DataSet.cpp:144
#define PG_TIMESTAMP_TYPE
Definition: Config.h:117
#define PG_TIMETZ_TYPE
Definition: Config.h:116
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
Definition: DataSet.cpp:294
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
Definition: DataSet.cpp:277
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
Definition: DataSet.cpp:272
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
Definition: DataSet.cpp:267
std::string getDatasetNameOfProperty(std::size_t i) const
It returns the underlying dataset name of the property at position pos.
Definition: DataSet.cpp:182
The type for variable-length multidimensional arrays.
Definition: Array.h:59
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not...
Definition: DataSet.cpp:262
Utility functions for PostgreSQL.
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
Definition: DataSet.cpp:344
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
Definition: DataSet.cpp:461
Implementation of a dataset for the PostGIS driver.
PGresult * m_result
The internal buffer with the result query.
Definition: DataSet.h:172
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
Definition: DataSet.cpp:355
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
Definition: DataSet.cpp:149
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
Definition: DataSet.cpp:192
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
Definition: DataSet.cpp:333
A class that implements a connection to a PostgreSQL database.
void GetArray(int i, int j, PGresult *result, std::vector< T > &a)
It retrieves information from an unidimensional array.
Definition: DataSet.cpp:77
#define PG_DATE_TYPE
Definition: Config.h:114
std::size_t size() const
It returns the collection size, if it is known.
Definition: DataSet.cpp:197
bool isEmpty() const
It returns true if the collection is empty.
Definition: DataSet.cpp:187
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
Definition: DataSet.cpp:244
Implementation of the data source for the PostGIS driver.
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.
Definition: DataSet.cpp:820
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
Definition: DataSet.cpp:470
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
Definition: DataSet.cpp:305
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
Definition: DataSet.cpp:316
An exception class for the PostGIS driver.
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
Definition: DataSet.cpp:475
#define PG_NAME_TYPE
Definition: Config.h:103
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
Definition: DataSet.cpp:581
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
Definition: DataSet.cpp:282
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
Definition: DataSet.cpp:455
#define PG_VARCHAR_TYPE
Definition: Config.h:113
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
Definition: DataSet.cpp:480
te::dt::DateTime * Internal2Time(boost::int64_t tval)
It returns a DateTime type from a time loaded by PostgreSQL.
Definition: Utils.h:362
bool moveNext()
It moves the internal pointer to the next item of the collection.
Definition: DataSet.cpp:226
A template for atomic data types (integers, floats, strings and others).
Definition: SimpleData.h:59
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:51
std::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
Definition: DataSet.cpp:202
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
Definition: DataSet.cpp:159
void copy(char *data, std::size_t size)
It copies the data from the given pointer to the byte array.
Definition: ByteArray.cpp:128
A class that implements a connection pool for PostGIS.
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
Definition: DataSet.cpp:288
void SwapBytes(T &v)
It swaps the bytes in local.
#define PG_TIMESTAMPTZ_TYPE
Definition: Config.h:118
A class for representing binary data.
Definition: ByteArray.h:51
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
Definition: DataSet.cpp:327
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
Definition: DataSet.cpp:250