PrintDataSetValues.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 examples/ado/PrintDatasetValues.cpp
22 
23  \brief It displays the values of a dataset
24 */
25 
26 // Example
27 #include "ADOExamples.h"
28 
29 // TerraLib
30 #include <terralib/common.h>
33 
34 // STL
35 #include <iostream>
36 
37 
38 void PrintDataSetValues(const std::string& datasetName, te::da::DataSet* dataset)
39 {
40 
41  dataset->isConnected(); //teste
42  if(dataset == 0)
43  {
44  std::cout << "The informed dataset is NULL!" << std::endl;
45  return;
46  }
47 
48  std::size_t numProperties = dataset->getNumProperties();
49 
50  // This will be used just to count the items in the dataset
51  int item = 0;
52 
53  std::cout << std::endl << "===========================================================" << std::endl;
54  std::cout << std::endl << "===========================================================" << std::endl;
55  std::cout << "Printing information about the dataset: " << datasetName << std::endl;
56 
57  // Traverse the dataset and print each dataset item
58  while(dataset->moveNext())
59  {
60  std::cout << std::endl << "Row Number: " << item++ << " =======================" << std::endl;
61 
62  for(std::size_t i = 0; i < numProperties; ++i)
63  {
64  std::cout << dataset->getPropertyName(i) << ": " ;
65 
66  // Check if the value is not null
67  if(dataset->isNull(i))
68  {
69  std::cout << std::endl;
70  continue;
71  }
72 
73  std::string value;
74  // Get the data value if it is not binary
75  int colType = dataset->getPropertyDataType(i);
76  if(colType == te::dt::BYTE_ARRAY_TYPE)
77  value = "Binary Type";
78  else if(colType == te::dt::UNKNOWN_TYPE)
79  value = "Unknown column type";
80  else if(colType == te::dt::DATETIME_TYPE)
81  value = "Not implemented yet";
82  else
83  value = dataset->getAsString(i);
84 
85  std::cout << value << std::endl;
86  }
87  }
88 }
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
void PrintDataSetValues(const std::string &datasetName, te::da::DataSet *dataset)
It prints the data of a given dataset.
Examples that show how to access/manipulate an ADO data source.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
virtual std::string getAsString(std::size_t i, int precision=0) const
Method for retrieving a data value as a string plain representation.
A dataset is the unit of information manipulated by the data access module of TerraLib.
This file contains include headers for the TerraLib Common Runtime module.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual bool isConnected() const =0
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.