27 #include "../Defines.h" 28 #include "../common/StringUtils.h" 29 #include "../core/translator/Translator.h" 30 #include "../dataaccess/dataset/DataSet.h" 31 #include "../dataaccess/dataset/DataSetType.h" 32 #include "../dataaccess/query/Query.h" 33 #include "../datatype/ByteArray.h" 34 #include "../datatype/DateTime.h" 35 #include "../geometry/Geometry.h" 52 #include <boost/cstdint.hpp> 53 #include <boost/format.hpp> 54 #include <boost/lexical_cast.hpp> 70 switch(propertyDataType)
110 std::unique_ptr<te::dt::ByteArray> ba(d->
getByteArray(propertyPos));
111 pq->
bind((
int)i, *ba);
117 std::unique_ptr<te::gm::Geometry> geom(d->
getGeometry(propertyPos));
118 pq->
bind((
int)i, *geom);
124 std::unique_ptr<te::dt::DateTime>
dt(d->
getDateTime(propertyPos));
130 throw Exception(
TE_TR(
"The TerraLib data type is not supported by the PostgreSQL driver!"));
140 m_paramValues(nullptr),
141 m_paramLengths(nullptr),
142 m_paramFormats(nullptr),
179 const std::vector<te::dt::Property*>& )
194 for(std::size_t i = 0; i <
m_nparams; ++i)
202 if((PQresultStatus(m_result) != PGRES_COMMAND_OK) &&
203 (PQresultStatus(m_result) != PGRES_TUPLES_OK))
205 boost::format errmsg(
TE_TR(
"Could not execute the prepared query due to the following error: %1%."));
207 errmsg = errmsg % PQerrorMessage(scopedConnection->getConn());
220 std::vector<int> ptypes;
243 throw Exception(
TE_TR(
"The TerraLib unsigned char data type is not supported by PostgreSQL data access driver!"));
256 #if TE_MACHINE_BYTE_ORDER == TE_NDR 271 #if TE_MACHINE_BYTE_ORDER == TE_NDR 286 #if TE_MACHINE_BYTE_ORDER == TE_NDR 299 char bvalue = value ? 1 : 0;
314 #if TE_MACHINE_BYTE_ORDER == TE_NDR 329 #if TE_MACHINE_BYTE_ORDER == TE_NDR 378 std::size_t ewkbsize = value.
getWkbSize() + 4;
413 std::string dvalue = value.
toString();
417 memcpy(
m_paramValues[i], dvalue.c_str(), dvalue.length() + 1);
464 if((PQresultStatus(m_result) != PGRES_COMMAND_OK) &&
465 (PQresultStatus(m_result) != PGRES_TUPLES_OK))
467 boost::format errmsg(
TE_TR(
"Could not create the prepared query due to the following error: %1%."));
469 errmsg = errmsg % PQerrorMessage(scopedConnection->getConn());
477 const std::size_t nparams = propertiesPos.size();
479 for(std::size_t i = 0; i < nparams; ++i)
480 BindValue(
this, d, i + offset, propertiesPos[i]);
485 const std::size_t nparams = propertiesPos.size();
487 for(std::size_t i = 0; i < nparams; ++i)
493 for(std::size_t i = 0; i <
m_nparams; ++i)
511 for(std::size_t i = 0; i <
m_nparams; ++i)
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
~PreparedQuery()
Virtual destructor.
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
A visitor for building an SQL statement using PostGIS dialect.
virtual std::unique_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const =0
Method for retrieving a byte array.
A class that control the use of connection to a PostgreSQL database.
std::size_t bytesUsed() const
It returns the number of used bytes in the internal buffer.
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
Base exception class for plugin module.
void bindNumeric(int i, const std::string &value)
Binds the i-th parameter of the query to a value.
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.
void write(const te::gm::Geometry *geom)
It serializes the geometry to an EWKB representation into the specified buffer.
void Swap8Bytes(char *v)
It swaps an array of eight bytes in local.
An utility class for writing a PostGIS EWKB.
Utility functions for PostgreSQL.
unsigned int getRasterTypeId() const
It returns the type id associated to the PostGIS Raster type.
A visitor for building an SQL statement using PostGIS dialect.
void bind(int i, char value)
Binds the i-th parameter of the query to a value.
te::da::DataSourceTransactor * getTransactor() const
It returns a pointer to the underlying data source transactor.
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
static te::dt::Date ds(2010, 01, 01)
A Transactor can be viewed as a connection to the data source for reading/writing things into it...
#define TE_TR(message)
It marks a string in order to get translated.
std::size_t getWkbSize() const _NOEXCEPT_OP(true)
It returns the size required by a WKB representation for this geometric object.
te::da::DataSet * query(te::common::TraverseType travType=te::common::FORWARDONLY, te::common::AccessPolicy rwRole=te::common::RAccess)
void Swap2Bytes(T &v)
It swaps two bytes in local.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
The transactor class for the PostGIS driver.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
virtual std::string toString() const =0
It returns the data value in a string notation.
An exception class for the PostGIS driver.
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).
PGconn * getConn() const
It gets the underlying PGconn object.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
std::string getName() const
It returns the prepared query name.
void Swap4Bytes(T &v)
It swaps four bytes in local.
Implementation of a dataset for the PostGIS driver.
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)
A base class for values that can be retrieved from the data access module.
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A class that implements a connection to a PostgreSQL database.
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).
Connection * getConnection(const int &id=-1) const
It returns the underlying connection.
A class that control the use of the connection to a PostgreSQL database.
ConnectionPool * getConnPool() const
It returns a pointer to the internal connection pool.
int getConnectionID() const
It returns the underlying connection ID.
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).
te::dt::Property * Convert2TerraLib(unsigned int attNum, const char *attName, unsigned int attType, bool attNotNull, const char *fmt, bool attHasDefault, const char *attDefValue, unsigned int pgisGeomTypeOid, unsigned int pgisRasterTypeOid)
It creates a PropertyType from a PostgreSQL attribute description.
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
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.
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
void BindValue(te::pgis::PreparedQuery *pq, te::da::DataSet *d, std::size_t i, std::size_t propertyPos)
A dataset is the unit of information manipulated by the data access module of TerraLib.
A class that implements a prepared query for PostgreSQL data access driver.
Implementation of the data source for the PostGIS driver.
A class that implements a prepared query for PostgreSQL data access driver.
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.
unsigned int getGeomTypeId() const
It returns the type id associated to the PostGIS Geometry type.