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 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  std::string v = te::common::Convert2String(n);
416  if(intVal.empty() == false)
417  {
418  if(n < 10)
419  v = "000" + v;
420  else if(n < 100)
421  v = "00" + v;
422  else if(n < 1000)
423  v = "0" + v;
424  }
425 
426  intVal += v;
427  ii += 2;
428  }
429 
430  if(ii == 0)
431  intVal += "0";
432 
433 //get decimal part
434  std::string decVal;
435 
436  if(decimalGroups == 0)
437  decVal = "0";
438  else
439  {
440  while(ii < (totalGroups * 2))
441  {
442  n = *((unsigned short*)(val + ii + 8));
443 
444 #if TE_MACHINE_BYTE_ORDER == TE_NDR
446 #endif
447 
448  std::string newVal = te::common::Convert2String(n);
449 
450  while (newVal.length() < 4) //fill with zeros (ex: .0700 was "700")
451  newVal = "0" + newVal;
452 
453  decVal += newVal;
454 
455  ii += 2;
456  }
457 
458  while((decVal.empty() == false) && (decVal[decVal.length() - 1] == '0'))
459  decVal.erase(decVal.length() - 1);
460  }
461 
462  return intVal + "." + decVal;
463 }
464 
465 std::string te::pgis::DataSet::getString(std::size_t i) const
466 {
467  std::string value(PQgetvalue(m_result, m_i, i));
468  return value;
469 }
470 
471 std::auto_ptr<te::dt::ByteArray> te::pgis::DataSet::getByteArray(std::size_t i) const
472 {
473  int size = PQgetlength(m_result, m_i, i);
474 
475  te::dt::ByteArray* b = new te::dt::ByteArray(size);
476  b->copy(PQgetvalue(m_result, m_i, i), size);
477  return std::auto_ptr<te::dt::ByteArray>(b);
478 }
479 
480 std::auto_ptr<te::gm::Geometry> te::pgis::DataSet::getGeometry(std::size_t i) const
481 {
482  return std::auto_ptr<te::gm::Geometry>(EWKBReader::read(PQgetvalue(m_result, m_i, i)));
483 }
484 
485 std::auto_ptr<te::rst::Raster> te::pgis::DataSet::getRaster(std::size_t /*i*/) const
486 {
487  return std::auto_ptr<te::rst::Raster>(0);
488 }
489 
490 std::auto_ptr<te::dt::DateTime> te::pgis::DataSet::getDateTime(std::size_t i) const
491 {
492  Oid tid = PQftype(m_result, i);
493  boost::int64_t ival = 0;
494  int iz;
495  double dval;
496  long int lval;
497 
498  switch(tid)
499  {
500  case PG_TIME_TYPE:
501  {
502  if(m_timeIsInteger)
503  {
504  ival = getInt64(i);
505  }
506  else
507  {
508  dval = getDouble(i);
509  ival = (boost::int64_t)(dval * 1000000);
510  }
511 
512  return std::auto_ptr<te::dt::DateTime>(Internal2Time(ival));
513  }
514 
515  case PG_DATE_TYPE:
516  {
517  char* val = PQgetvalue(m_result, m_i, i);
518  lval = *((long int*)val);
519 
520 #if TE_MACHINE_BYTE_ORDER == TE_NDR
521  te::common::SwapBytes(lval);
522 #endif
523 
524  return std::auto_ptr<te::dt::DateTime>(Internal2Date(lval));
525  }
526 
527  case PG_TIMESTAMP_TYPE:
528  {
529  if(m_timeIsInteger)
530  ival = getInt64(i);
531  else
532  {
533  dval = getDouble(i);
534  ival = (boost::int64_t)(dval * 1000000);
535  }
536 
537  return std::auto_ptr<te::dt::DateTime>(Internal2TimeStamp(ival));
538  }
539 
540  case PG_TIMESTAMPTZ_TYPE:
541  {
542  if(m_timeIsInteger)
543  ival = getInt64(i);
544  else
545  {
546  char* c = (char*)PQgetvalue(m_result, m_i, i);
547  dval = *((double*)c);
548 
549  #if TE_MACHINE_BYTE_ORDER == TE_NDR
550  te::common::SwapBytes(dval);
551  #endif
552 
553  ival = (boost::int64_t)(dval * 1000000);
554  }
555  return std::auto_ptr<te::dt::DateTime>(Internal2TimeStamp(ival));
556  }
557  case PG_TIMETZ_TYPE:
558  {
559  if(m_timeIsInteger)
560  {
561  ival = getInt64(i);
562  iz = 0;
563  }
564  else
565  {
566  char* c = (char*)PQgetvalue(m_result, m_i, i);
567  dval = *((double*)c);
568  c += 8;
569  iz = *((int*)c);
570 
571  #if TE_MACHINE_BYTE_ORDER == TE_NDR
572  te::common::SwapBytes(dval);
574  #endif
575 
576  ival = (boost::int64_t)(dval * 1000000);
577  }
578  iz /= 3600;
579  if(iz < -12)
580  iz = -12;
581  if(iz > 14)
582  iz = 14;
583  return std::auto_ptr<te::dt::DateTime>(Internal2TimeTZ(ival, iz));
584  }
585 
586  default:
587  throw Exception(TE_TR("This type is not supported by TerraLib!"));
588  }
589 }
590 
591 std::auto_ptr<te::dt::Array> te::pgis::DataSet::getArray(std::size_t i) const
592 {
593  char* value = PQgetvalue(m_result, m_i, i);
594 
595  int ndim = *((int*)value);
596  value += sizeof(int);
597 
598 #if TE_MACHINE_BYTE_ORDER == TE_NDR
599  te::common::SwapBytes(ndim);
600 #endif
601 
602  int dataoffset = *((int*)value);
603  value += sizeof(int);
604 
605 #if TE_MACHINE_BYTE_ORDER == TE_NDR
606  te::common::SwapBytes(dataoffset);
607 #endif
608 
609  unsigned int elemtype = *((unsigned int*)value);
610  value += sizeof(unsigned int);
611 
612 #if TE_MACHINE_BYTE_ORDER == TE_NDR
613  te::common::SwapBytes(elemtype);
614 #endif
615 
616  int* dimensions = (int*)value;
617  value += ndim * sizeof(int);
618 
619  int* lowerbounds = (int*)value;
620  value += ndim * sizeof(int);
621 
622  uint32_t* null_bitmap = (unsigned int*)value;
623 
624  boost::dynamic_bitset<> mask;
625 
626  if(dataoffset != 0)
627  {
628  int nmasks = (dataoffset + 3) / 4;
629 
630  mask.resize(nmasks * 8 * sizeof(uint32_t));
631 
632  int pos = 0;
633 
634  for(int i = 0; i != nmasks; ++i)
635  {
636  value += sizeof(uint32_t);
637 
638  uint32_t umask = null_bitmap[i];
639 
640 #if TE_MACHINE_BYTE_ORDER == TE_NDR
641  te::common::SwapBytes(umask);
642 #endif
643 
644  for(int j = 0; j != 32; ++j)
645  {
646  mask[pos] = ((umask >> j) & 1) == 0;
647  ++pos;
648  }
649  }
650  }
651  else
652  {
653  value += sizeof(uint32_t);
654  }
655 
656  switch(elemtype)
657  {
658  case PG_TEXT_TYPE:
659  case PG_VARCHAR_TYPE:
660  case PG_NAME_TYPE:
661  {
662  std::auto_ptr<te::dt::Array> arr(new te::dt::Array(ndim, te::dt::STRING_TYPE));
663 
664  std::vector<std::size_t> pos(ndim, 0);
665 
666  for(int d = 0; d != ndim; ++d)
667  {
668  int d_size = dimensions[d];
669 
670 #if TE_MACHINE_BYTE_ORDER == TE_NDR
671  te::common::SwapBytes(d_size);
672 #endif
673  int d_lower_boundary = lowerbounds[d];
674 
675 #if TE_MACHINE_BYTE_ORDER == TE_NDR
676  te::common::SwapBytes(d_lower_boundary);
677 #endif
678 
679  for(i = 0; i != d_size; ++i)
680  {
681  if((dataoffset != 0) && (mask[i] == false))
682  {
683  arr->insert(0, pos);
684  continue;
685  }
686 
687  pos[d] = i;
688 
689  int text_size = *(int*)value;
690 
691 #if TE_MACHINE_BYTE_ORDER == TE_NDR
692  te::common::SwapBytes(text_size);
693 #endif
694  value += sizeof(int);
695 
696  arr->insert(new te::dt::String(value), pos);
697 
698  value += text_size;
699  }
700  }
701 
702  return std::auto_ptr<te::dt::Array>(arr.release());
703  }
704  break;
705 
706  case PG_FLOAT8_TYPE:
707  {
708  std::auto_ptr<te::dt::Array> arr(new te::dt::Array(ndim, te::dt::DOUBLE_TYPE));
709 
710  std::vector<std::size_t> pos(ndim, 0);
711 
712  for(int d = 0; d != ndim; ++d)
713  {
714  int d_size = dimensions[d];
715 
716 #if TE_MACHINE_BYTE_ORDER == TE_NDR
717  te::common::SwapBytes(d_size);
718 #endif
719  int d_lower_boundary = lowerbounds[d];
720 
721 #if TE_MACHINE_BYTE_ORDER == TE_NDR
722  te::common::SwapBytes(d_lower_boundary);
723 #endif
724 
725  for(i = 0; i != d_size; ++i)
726  {
727  if((dataoffset != 0) && (mask[i] == false))
728  {
729  arr->insert(0, pos);
730  continue;
731  }
732 
733  pos[d] = i;
734 
735  double val = *(double*)value;
736 
737 #if TE_MACHINE_BYTE_ORDER == TE_NDR
739 #endif
740 
741  arr->insert(new te::dt::Double(val), pos);
742 
743  value += sizeof(double);
744  }
745  }
746 
747  return std::auto_ptr<te::dt::Array>(arr.release());
748  }
749  break;
750 
751  case PG_INT2_TYPE:
752  {
753  std::auto_ptr<te::dt::Array> arr(new te::dt::Array(ndim, te::dt::INT16_TYPE));
754 
755  std::vector<std::size_t> pos(ndim, 0);
756 
757  for(int d = 0; d != ndim; ++d)
758  {
759  int d_size = dimensions[d];
760 
761 #if TE_MACHINE_BYTE_ORDER == TE_NDR
762  te::common::SwapBytes(d_size);
763 #endif
764  int d_lower_boundary = lowerbounds[d];
765 
766 #if TE_MACHINE_BYTE_ORDER == TE_NDR
767  te::common::SwapBytes(d_lower_boundary);
768 #endif
769 
770  for(i = 0; i != d_size; ++i)
771  {
772  if((dataoffset != 0) && (mask[i] == false))
773  {
774  arr->insert(0, pos);
775  continue;
776  }
777 
778  pos[d] = i;
779 
780  boost::uint16_t val = *(boost::uint16_t*)value;
781 
782 #if TE_MACHINE_BYTE_ORDER == TE_NDR
784 #endif
785 
786  arr->insert(new te::dt::Int16(val), pos);
787 
788  value += sizeof(uint32_t);
789  }
790  }
791 
792  return std::auto_ptr<te::dt::Array>(arr.release());
793  }
794  break;
795 
796  default:
797  throw Exception(TE_TR("The array element type is not supported yet!"));
798  }
799 
800  // {
801  // te::common::SwapBytes(ndim);
802  // te::common::SwapBytes(dataoffset);
803  // te::common::SwapBytes(elemtype);
804  // te::common::SwapBytes(dimension);
805  // te::common::SwapBytes(lowerbnds);
806 
807  // a.reserve(dimension);
808 
809  // for(int k = 0; k < dimension; ++k)
810  // {
811  // T v = *((T*)value);
812  // te::common::SwapBytes(v);
813  // a.push_back(v);
814  // value += sizeof(ALIGN);
815  // }
816  // }
817  // else
818  // {
819  // a.reserve(dimension);
820 
821  // for(int k = 0; k < dimension; ++k)
822  // {
823  // T v = *((T*)value);
824  // a.push_back(v);
825  // value += sizeof(ALIGN);
826  // }
827  // }
828 }
829 
830 bool te::pgis::DataSet::isNull(std::size_t i) const
831 {
832  return PQgetisnull(m_result, m_i, i) == 1;
833 }
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:122
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:116
double getDouble(const std::string &value, std::vector< std::string > &sVector)
Definition: Utils.cpp:179
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:119
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:126
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
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:128
#define PG_TIMETZ_TYPE
Definition: Config.h:127
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:471
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:125
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:830
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
Definition: DataSet.cpp:480
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:485
#define PG_NAME_TYPE
Definition: Config.h:114
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
Definition: DataSet.cpp:591
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:465
#define PG_VARCHAR_TYPE
Definition: Config.h:124
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
Definition: DataSet.cpp:490
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:129
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