All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FwDataSet.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/sqlite/FwDataSet.cpp
22 
23  \brief Implementation of a forward-only dataset for the TerraLib SQLite Data Access driver.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "../geometry/Geometry.h"
29 #include "Config.h"
30 #include "DataSourceTransactor.h"
31 #include "EWKBReader.h"
32 #include "FwDataSet.h"
33 #include "Utils.h"
34 
35 // STL
36 #include <memory>
37 
38 // SQLite
39 #include <sqlite3.h>
40 
42 {
43  public:
44 
46 
47  ~Impl();
48 
52 };
53 
55  : m_stmt(stmt), m_parent(t), m_dt(0)
56 {
57 }
58 
60 {
61  delete m_dt;
62 
63  int ret = SQLITE_OK;
64 
65  ret = sqlite3_finalize(m_stmt);
66 
67  assert(ret == SQLITE_OK);
68 }
69 
71  : m_pImpl(0)
72 {
73  m_pImpl= new Impl(stmt, t);
74 
76 }
77 
79 {
80  delete m_pImpl;
81 }
82 
84 {
86 }
87 
89 {
90  return te::common::RAccess;
91 }
92 
94 {
95  return m_pImpl->m_dt->size();
96 }
97 
99 {
100  return m_pImpl->m_dt->getProperty(i)->getType();
101 }
102 
103 std::string te::sqlite::FwDataSet::getPropertyName(std::size_t i) const
104 {
105  return m_pImpl->m_dt->getProperty(i)->getName();
106 }
107 
108 std::string te::sqlite::FwDataSet::getDatasetNameOfProperty(std::size_t i) const
109 {
110  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
111 }
112 
114 {
115  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
116 }
117 
119 {
120  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
121 }
122 
123 std::size_t te::sqlite::FwDataSet::size() const
124 {
125  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
126 }
127 
128 std::auto_ptr<te::gm::Envelope> te::sqlite::FwDataSet::getExtent(std::size_t i)
129 {
130  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
131 }
132 
134 {
135  return (sqlite3_step(m_pImpl->m_stmt) == SQLITE_ROW);
136 }
137 
139 {
140  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
141 }
142 
144 {
145  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
146 }
147 
149 {
150  int ret = sqlite3_reset(m_pImpl->m_stmt);
151 
152  if(ret != SQLITE_OK)
153  return false;
154 
155  return (sqlite3_step(m_pImpl->m_stmt) == SQLITE_ROW);
156 }
157 
159 {
160  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
161 }
162 
163 bool te::sqlite::FwDataSet::move(std::size_t i)
164 {
165  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
166 }
167 
169 {
170  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
171 }
172 
174 {
175  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
176 }
177 
179 {
180  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
181 }
182 
184 {
185  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
186 }
187 
188 char te::sqlite::FwDataSet::getChar(std::size_t i) const
189 {
190  int value = sqlite3_column_int(m_pImpl->m_stmt, i);
191 
192  return static_cast<char>(value);
193 }
194 
195 unsigned char te::sqlite::FwDataSet::getUChar(std::size_t i) const
196 {
197  int value = sqlite3_column_int(m_pImpl->m_stmt, i);
198 
199  return static_cast<unsigned char>(value);
200 }
201 
202 boost::int16_t te::sqlite::FwDataSet::getInt16(std::size_t i) const
203 {
204  return static_cast<boost::int16_t>(sqlite3_column_int(m_pImpl->m_stmt, i));
205 }
206 
207 boost::int32_t te::sqlite::FwDataSet::getInt32(std::size_t i) const
208 {
209  return sqlite3_column_int(m_pImpl->m_stmt, i);
210 }
211 
212 boost::int64_t te::sqlite::FwDataSet::getInt64(std::size_t i) const
213 {
214  return sqlite3_column_int64(m_pImpl->m_stmt, i);
215 }
216 
217 bool te::sqlite::FwDataSet::getBool(std::size_t i) const
218 {
219  return sqlite3_column_int(m_pImpl->m_stmt, i) == TE_SQLITE_BOOL_TRUE;
220 }
221 
222 float te::sqlite::FwDataSet::getFloat(std::size_t i) const
223 {
224  return static_cast<float>(sqlite3_column_double(m_pImpl->m_stmt, i));
225 }
226 
227 double te::sqlite::FwDataSet::getDouble(std::size_t i) const
228 {
229  return sqlite3_column_double(m_pImpl->m_stmt, i);
230 }
231 
232 std::string te::sqlite::FwDataSet::getNumeric(std::size_t i) const
233 {
234  std::string value((const char*)(sqlite3_column_text(m_pImpl->m_stmt, i)));
235 
236  return value;
237 }
238 
239 std::string te::sqlite::FwDataSet::getString(std::size_t i) const
240 {
241  return (const char*)(sqlite3_column_text(m_pImpl->m_stmt, i));
242 }
243 
244 std::auto_ptr<te::dt::ByteArray> te::sqlite::FwDataSet::getByteArray(std::size_t i) const
245 {
246  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
247 }
248 
249 std::auto_ptr<te::gm::Geometry> te::sqlite::FwDataSet::getGeometry(std::size_t i) const
250 {
251  unsigned char* ewkb = (unsigned char*)(sqlite3_column_blob(m_pImpl->m_stmt, i));
252  std::auto_ptr<te::gm::Geometry> g(EWKBReader::read(ewkb));
253  return g;
254 }
255 
256 std::auto_ptr<te::rst::Raster> te::sqlite::FwDataSet::getRaster(std::size_t i) const
257 {
258  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
259 }
260 
261 std::auto_ptr<te::dt::DateTime> te::sqlite::FwDataSet::getDateTime(std::size_t i) const
262 {
263  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
264 }
265 
266 std::auto_ptr<te::dt::Array> te::sqlite::FwDataSet::getArray(std::size_t i) const
267 {
268  throw te::common::Exception(TR_COMMON("Not supported by SQLite driver!"));
269 }
270 
271 bool te::sqlite::FwDataSet::isNull(std::size_t i) const
272 {
273  return sqlite3_column_type(m_pImpl->m_stmt, i) == SQLITE_NULL;
274 }
275 
te::common::AccessPolicy getAccessPolicy() const
It returns the read and write permission associated to the dataset.
Definition: FwDataSet.cpp:88
Configuration flags for the SQLite Data Access driver.
boost::int64_t getInt64(std::size_t i) const
Method for retrieving a 64-bit integer attribute value (8 bytes long).
Definition: FwDataSet.cpp:212
std::string getPropertyName(std::size_t i) const
It returns the property name at position pos.
Definition: FwDataSet.cpp:103
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
Definition: FwDataSet.cpp:143
char getChar(std::size_t i) const
Method for retrieving a signed character attribute value (1 byte long).
Definition: FwDataSet.cpp:188
bool moveNext()
It moves the internal pointer to the next item of the collection.
Definition: FwDataSet.cpp:133
A class that models the description of a dataset.
Definition: DataSetType.h:72
bool isAfterEnd() const
It tells if the dataset internal pointer is on the sentinel position after the last element of the co...
Definition: FwDataSet.cpp:183
bool getBool(std::size_t i) const
Method for retrieving a boolean attribute value.
Definition: FwDataSet.cpp:217
Impl(sqlite3_stmt *stmt, DataSourceTransactor *t)
Definition: FwDataSet.cpp:54
std::string getDatasetNameOfProperty(std::size_t i) const
It returns the underlying dataset name of the property at position pos.
Definition: FwDataSet.cpp:108
bool isAtBegin() const
It tells if the dataset internal pointer is on the first element of the collection or not...
Definition: FwDataSet.cpp:168
std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const
Method for retrieving a date and time attribute value.
Definition: FwDataSet.cpp:261
double getDouble(std::size_t i) const
Method for retrieving a double attribute value.
Definition: FwDataSet.cpp:227
FwDataSet(sqlite3_stmt *stmt, DataSourceTransactor *t)
Definition: FwDataSet.cpp:70
float getFloat(std::size_t i) const
Method for retrieving a float attribute value.
Definition: FwDataSet.cpp:222
std::size_t size() const
It returns the collection size, if it is known.
Definition: FwDataSet.cpp:123
bool isBeforeBegin() const
It tells if the dataset internal pointer is in a position before the first element of the collection ...
Definition: FwDataSet.cpp:173
boost::int16_t getInt16(std::size_t i) const
Method for retrieving a 16-bit integer attribute value (2 bytes long).
Definition: FwDataSet.cpp:202
DataSourceTransactor * m_parent
Definition: FwDataSet.cpp:50
std::auto_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const
Method for retrieving a byte array.
Definition: FwDataSet.cpp:244
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
std::string getString(std::size_t i) const
Method for retrieving a string value attribute.
Definition: FwDataSet.cpp:239
int getPropertyDataType(std::size_t i) const
It returns the underlying data type of the property at position pos.
Definition: FwDataSet.cpp:98
te::da::DataSetType * m_dt
Definition: FwDataSet.cpp:51
bool moveLast()
It sets the dataset internal pointer to the last item in the collection.
Definition: FwDataSet.cpp:158
unsigned char getUChar(std::size_t i) const
Method for retrieving an unsigned character attribute value (1 byte long).
Definition: FwDataSet.cpp:195
bool isConnected() const
It returns true if the dataset is connected and false if it is disconnected. A dataset can be connect...
Definition: FwDataSet.cpp:118
bool isEmpty() const
It returns true if the collection is empty.
Definition: FwDataSet.cpp:113
std::auto_ptr< te::dt::Array > getArray(std::size_t i) const
Method for retrieving an array.
Definition: FwDataSet.cpp:266
std::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
Definition: FwDataSet.cpp:128
Utility functions for the TerraLib SQLite Data Access driver.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
std::size_t getNumProperties() const
It returns the number of properties that composes an item of the dataset.
Definition: FwDataSet.cpp:93
te::common::TraverseType getTraverseType() const
It returns the traverse type associated to the dataset.
Definition: FwDataSet.cpp:83
bool movePrevious()
It moves the internal pointer to the previous item of the collection.
Definition: FwDataSet.cpp:138
bool isAtEnd() const
It tells if the dataset internal pointer is on the last element of the collection.
Definition: FwDataSet.cpp:178
bool move(std::size_t i)
It moves the dataset internal pointer to a given position.
Definition: FwDataSet.cpp:163
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
Definition: FwDataSet.cpp:249
struct sqlite3_stmt sqlite3_stmt
Definition: FwDataSet.h:35
An implementation of DataSourceTransactor class for the TerraLib SQLite Data Access Driver...
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.
Definition: FwDataSet.cpp:271
bool moveFirst()
It moves the internal pointer to the first item in the collection.
Definition: FwDataSet.cpp:148
std::string getNumeric(std::size_t i) const
Method for retrieving a numeric attribute value.
Definition: FwDataSet.cpp:232
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
Definition: FwDataSet.cpp:207
te::da::DataSetType * Convert2TerraLib(sqlite3_stmt *pStmt)
Definition: Utils.cpp:433
std::auto_ptr< te::rst::Raster > getRaster(std::size_t i) const
Method for retrieving a raster attribute value.
Definition: FwDataSet.cpp:256
#define TE_SQLITE_BOOL_TRUE
A flag that indicates a false value (boolean).
Definition: Config.h:42
Implementation of a forward-only dataset for the TerraLib SQLite Data Access driver.
An utility class for reading a SpatiaLite EWKB geometry.