27 #include "../common/Globals.h" 28 #include "../core/translator/Translator.h" 29 #include "../dataaccess/dataset/DataSet.h" 30 #include "../dataaccess/dataset/DataSetType.h" 31 #include "../dataaccess/query/Query.h" 32 #include "../datatype/ByteArray.h" 33 #include "../datatype/DateTime.h" 34 #include "../geometry/Geometry.h" 35 #include "../memory/DataSet.h" 48 #include <boost/date_time.hpp> 49 #include <boost/format.hpp> 61 int retval = SQLITE_OK;
67 retval = sqlite3_bind_null(stmt, i + 1);
69 if(retval != SQLITE_OK)
75 switch(propertyDataType)
78 retval = sqlite3_bind_int(stmt, i + 1, d->
getChar(propertyPos));
82 retval = sqlite3_bind_int(stmt, i + 1, d->
getUChar(propertyPos));
86 retval = sqlite3_bind_int(stmt, i + 1, d->
getInt16(propertyPos));
90 retval = sqlite3_bind_int(stmt, i + 1, d->
getInt32(propertyPos));
94 retval = sqlite3_bind_int64(stmt, i + 1, d->
getInt64(propertyPos));
102 retval = sqlite3_bind_double(stmt, i + 1, static_cast<double>(d->
getFloat(propertyPos)));
106 retval = sqlite3_bind_double(stmt, i + 1, d->
getDouble(propertyPos));
111 std::string value = d->
getNumeric(propertyPos);
112 retval = sqlite3_bind_text(stmt, i + 1, value.c_str(), value.size(), SQLITE_TRANSIENT);
118 std::string value = d->
getString(propertyPos);
119 retval = sqlite3_bind_text(stmt, i + 1, value.c_str(), value.size(), SQLITE_TRANSIENT);
133 std::auto_ptr<te::gm::Geometry> g(d->
getGeometry(propertyPos));
137 unsigned char* ewkb =
new unsigned char[ewkbSize];
141 retval = sqlite3_bind_blob(stmt, i + 1, ewkb, ewkbSize, SQLITE_TRANSIENT);
149 std::auto_ptr<te::dt::DateTime>
dt(d->
getDateTime(propertyPos));
153 retval = sqlite3_bind_text(stmt, i + 1, sdate.c_str(), sdate.size(), SQLITE_TRANSIENT);
169 throw te::common::Exception(TR_COMMON(
"There is a TerraLib data type that can not be mapped to SQLite type system!"));
172 if(retval != SQLITE_OK)
213 int ret = sqlite3_prepare_v2(
m_db, query.c_str(), -1, &
m_stmt, 0);
222 throw te::common::Exception((boost::format(TR_COMMON(
"Could not excute the given query due to the following error: %1%.")) % sqlite3_errmsg(
m_db)).str());
228 int retval = sqlite3_step(
m_stmt);
230 if(retval != SQLITE_DONE)
232 boost::format errmsg(TR_COMMON(
"Could not execute prepared query due to the following error: %1%."));
234 const char* litemsg = sqlite3_errmsg(
m_db);
237 errmsg = errmsg % litemsg;
242 retval = sqlite3_reset(
m_stmt);
244 if(retval != SQLITE_OK)
246 boost::format errmsg(TR_COMMON(
"Could not reset the prepared query to its initial state due to the following error: %1%."));
248 const char* litemsg = sqlite3_errmsg(
m_db);
251 errmsg = errmsg % litemsg;
305 int retval = sqlite3_bind_int(
m_stmt, i + 1, value);
307 if(retval != SQLITE_OK)
313 int retval = sqlite3_bind_int(
m_stmt, i + 1, value);
315 if(retval != SQLITE_OK)
321 int retval = sqlite3_bind_int(
m_stmt, i + 1, value);
323 if(retval != SQLITE_OK)
329 int retval = sqlite3_bind_int(
m_stmt, i + 1, value);
331 if(retval != SQLITE_OK)
337 int retval = sqlite3_bind_int64(
m_stmt, i + 1, value);
339 if(retval != SQLITE_OK)
347 if(retval != SQLITE_OK)
353 int retval = sqlite3_bind_double(
m_stmt, i + 1, static_cast<double>(value));
355 if(retval != SQLITE_OK)
361 int retval = sqlite3_bind_double(
m_stmt, i + 1, value);
363 if(retval != SQLITE_OK)
369 int retval = sqlite3_bind_text(
m_stmt, i + 1, value.c_str(), value.size(), SQLITE_TRANSIENT);
371 if(retval != SQLITE_OK)
377 int retval = sqlite3_bind_text(
m_stmt, i + 1, value.c_str(), value.size(), SQLITE_TRANSIENT);
379 if(retval != SQLITE_OK)
387 if(retval != SQLITE_OK)
395 unsigned char* ewkb =
new unsigned char[ewkbSize];
399 int retval = sqlite3_bind_blob(
m_stmt, i + 1, ewkb, ewkbSize, SQLITE_TRANSIENT);
403 if(retval != SQLITE_OK)
414 std::string sdate = value.
toString();
416 int retval = sqlite3_bind_text(
m_stmt, i + 1, sdate.c_str(), sdate.size(), SQLITE_TRANSIENT);
418 if(retval != SQLITE_OK)
448 int ret = sqlite3_prepare_v2(
m_db, query.c_str(), -1, &
m_stmt, 0);
457 throw te::common::Exception((boost::format(TR_COMMON(
"Could not excute the given query due to the following error: %1%.")) % sqlite3_errmsg(
m_db)).str());
465 const std::size_t nparams = propertiesPos.size();
467 for(std::size_t i = 0; i != nparams; ++i)
474 const std::size_t nparams = propertiesPos.size();
476 for(std::size_t i = 0; i != nparams; ++i)
484 for(std::size_t i = 0; i != nparams; ++i)
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
virtual unsigned char getUChar(std::size_t i) const =0
Method for retrieving an unsigned character attribute value (1 byte long).
void BindValue(sqlite3_stmt *stmt, te::da::DataSet *d, std::size_t i, std::size_t propertyPos)
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
std::size_t bytesUsed() const
It returns the number of used bytes in the internal buffer.
void prepare(const te::da::Query &query, const std::vector< te::dt::Property * > ¶mTypes)
It prepares the query that may be used for commands that are used mutiple times (select, insert, update and delete).
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
te::da::DataSet * query(te::common::TraverseType travType=te::common::FORWARDONLY, te::common::AccessPolicy rwRole=te::common::RAccess)
std::string toString() const
It returns the time duration in the ISO textual format (hh:mm:ss,ss).
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
virtual std::string toString() const =0
It returns the data value in a string notation.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
PreparedQuery()
Constructor.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
An abstract class for raster data strucutures.
char * getData() const
It returns the data array.
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::string getName() const
It returns the prepared query name.
#define TE_SQLITE_BOOL_FALSE
A flag that indicates a false value (boolean).
A base class for values that can be retrieved from the data access module.
void bind(int i, char value)
Binds the i-th parameter of the query to a value.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
DataSourceTransactor * m_t
A visitor for building an SQL statement using SQLite dialect.
virtual std::unique_ptr< te::dt::DateTime > getDateTime(std::size_t i) const =0
Method for retrieving a date and time attribute value.
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual char getChar(std::size_t i) const =0
Method for retrieving a signed character attribute value (1 byte long).
~PreparedQuery()
Virtual destructor.
virtual const SQLDialect * getDialect() const =0
It returns the data source SQL dialect, if there is one.
void bindNumeric(int i, const std::string &value)
Binds the i-th parameter of the query to a value.
virtual bool getBool(std::size_t i) const =0
Method for retrieving a boolean attribute value.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
struct sqlite3_stmt sqlite3_stmt
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
#define TE_SQLITE_BOOL_TRUE
A flag that indicates a false value (boolean).
static std::size_t getEWKBSize(const te::gm::Geometry *g)
te::da::DataSourceTransactor * getTransactor() const
It returns a pointer to the underlying data source transactor.
A Query is independent from the data source language/dialect.
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
A class for representing binary data.