PreparedQuery.h
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/PreparedQuery.h
22 
23  \brief A class that implements a prepared query for PostgreSQL data access driver.
24 */
25 
26 #ifndef __TERRALIB_POSTGIS_INTERNAL_PREPAREDQUERY_H
27 #define __TERRALIB_POSTGIS_INTERNAL_PREPAREDQUERY_H
28 
29 // TerraLib
30 #include "../dataaccess/datasource/PreparedQuery.h"
31 #include "Config.h"
32 
33 // Forward delcarations for libpq
34 extern "C"
35 {
36  struct pg_conn;
37  typedef struct pg_conn PGconn;
38 
39  struct pg_result;
40  typedef struct pg_result PGresult;
41 }
42 
43 namespace te
44 {
45 // Forward declarations
46  namespace da
47  {
48  class DataSetType;
49  }
50 
51  namespace pgis
52  {
53 // Forward declarations
54  class Transactor;
55 
56  /*!
57  \class PreparedQuery
58 
59  \brief A class that implements a prepared query for PostgreSQL data access driver.
60 
61  \note Some general notes:
62  - bind doesn't need to set length for fixed-size types.
63 
64  \note Review pending bind methods (raster, date, array, ...).
65 
66  \note We need a numeric type by tomorrow!
67  */
69  {
70  public:
71 
72  PreparedQuery(Transactor* t, const std::string& pqname);
73 
75 
76  std::string getName() const;
77 
78  void prepare(const te::da::Query& query, const std::vector<te::dt::Property*>& paramTypes);
79 
80  void prepare(const std::string& query, const std::vector<te::dt::Property*>& paramTypes);
81 
82  void execute(PGconn* pgConn);
83 
84  void execute();
85 
88 
89  void bind(int i, char value);
90 
91  void bind(int i, unsigned char value);
92 
93  void bind(int i, boost::int16_t value);
94 
95  void bind(int i, boost::int32_t value);
96 
97  void bind(int i, boost::int64_t value);
98 
99  void bind(int i, bool value);
100 
101  void bind(int i, float value);
102 
103  void bind(int i, double value);
104 
105  void bindNumeric(int i, const std::string& value);
106 
107  void bind(int i, const std::string& value);
108 
109  void bind(int i, const te::dt::ByteArray& value);
110 
111  void bind(int i, const te::gm::Geometry& value);
112 
113  void bind(int i, const te::rst::Raster& value);
114 
115  void bind(int i, const te::dt::DateTime& value);
116 
117  void bind(int i, const te::da::DataSet& value);
118 
119  void bind(int i, const te::dt::AbstractData& ad);
120 
122 
123  /*!
124  \note PostgeSQL driver extended method.
125  */
126  void prepare(const std::string& query, const std::vector<int>& paramTypes);
127 
128  /*!
129  \note PostgeSQL driver extended method.
130  */
131  void bind(const std::vector<std::size_t>& propertiesPos, std::size_t offset, te::da::DataSet* d);
132 
133  /*!
134  \note PostgeSQL driver extended method.
135  */
136  void bind(const std::vector<std::size_t>& propertiesPos, te::da::DataSet* d);
137 
138  /*!
139  \note PostgeSQL driver extended method.
140  */
142 
143  /*!
144  \note PostgeSQL driver extended method.
145  */
146  void clear();
147 
148  private:
149 
155  std::size_t m_nparams;
156  std::string m_qname;
157  };
158 
159  } // end namespace pgis
160 } // end namespace te
161 
162 
163 #endif // __TERRALIB_POSTGIS_INTERNAL_PREPAREDQUERY_H
te::dt::ByteArray
A class for representing binary data.
Definition: ByteArray.h:52
te::pgis::PreparedQuery::getTransactor
te::da::DataSourceTransactor * getTransactor() const
It returns a pointer to the underlying data source transactor.
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::pgis::PreparedQuery::execute
void execute()
te::pgis::PreparedQuery::prepare
void prepare(const te::da::Query &query, const std::vector< te::dt::Property * > &paramTypes)
It prepares the query that may be used for commands that are used mutiple times (select,...
PGresult
struct pg_result PGresult
Definition: Connection.h:48
te::pgis::PreparedQuery::PreparedQuery
PreparedQuery(Transactor *t, const std::string &pqname)
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::pgis::PreparedQuery::bind
void bind(int i, boost::int64_t value)
Binds the i-th parameter of the query to a value.
te::common::RAccess
@ RAccess
Definition: Enums.h:43
te::pgis::PreparedQuery::bind
void bind(int i, const te::rst::Raster &value)
Binds the i-th parameter of the query to a value.
te::dt::DateTime
Definition: DateTime.h:56
te::da::Query
A Query is independent from the data source language/dialect.
Definition: Query.h:47
te::pgis::PreparedQuery::bind
void bind(int i, const te::dt::DateTime &value)
Binds the i-th parameter of the query to a value.
te::pgis::Transactor
The transactor class for the PostGIS driver.
Definition: Transactor.h:64
te::common::TraverseType
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:54
te::pgis::PreparedQuery::bindNumeric
void bindNumeric(int i, const std::string &value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::m_qname
std::string m_qname
Definition: PreparedQuery.h:156
te::pgis::PreparedQuery::getName
std::string getName() const
It returns the prepared query name.
te::pgis::PreparedQuery::bind
void bind(int i, boost::int32_t value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::m_paramFormats
int * m_paramFormats
Definition: PreparedQuery.h:154
te::pgis::PreparedQuery::m_t
Transactor * m_t
Definition: PreparedQuery.h:150
te::pgis::PreparedQuery::m_paramLengths
int * m_paramLengths
Definition: PreparedQuery.h:153
te::pgis::PreparedQuery::bind
void bind(int i, float value)
Binds the i-th parameter of the query to a value.
PGconn
struct pg_conn PGconn
Definition: Connection.h:45
te::pgis::PreparedQuery::prepare
void prepare(const std::string &query, const std::vector< int > &paramTypes)
te::da::DataSourceTransactor
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
Definition: DataSourceTransactor.h:89
TEPGISEXPORT
#define TEPGISEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:195
te::pgis::PreparedQuery::~PreparedQuery
~PreparedQuery()
Virtual destructor.
te::pgis::PreparedQuery::bind
void bind(const std::vector< std::size_t > &propertiesPos, std::size_t offset, te::da::DataSet *d)
te::pgis::PreparedQuery::execute
void execute(PGconn *pgConn)
te::pgis::PreparedQuery::bind
void bind(int i, boost::int16_t value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::bind
void bind(int i, double value)
Binds the i-th parameter of the query to a value.
te::dt::AbstractData
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:56
te::pgis::PreparedQuery::bind
void bind(int i, const std::string &value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::bind
void bind(int i, const te::dt::ByteArray &value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::bind
void bind(int i, const te::dt::AbstractData &ad)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::m_paramValues
char ** m_paramValues
Definition: PreparedQuery.h:152
te::pgis::PreparedQuery::bind
void bind(te::da::DataSet *d)
te::pgis::PreparedQuery::bind
void bind(int i, bool value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::bind
void bind(const std::vector< std::size_t > &propertiesPos, te::da::DataSet *d)
te::da::DataSet
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:114
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::pgis::PreparedQuery::bind
void bind(int i, unsigned char value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::clear
void clear()
te::pgis::PreparedQuery::bind
void bind(int i, char value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::bind
void bind(int i, const te::da::DataSet &value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::query
te::da::DataSet * query(te::common::TraverseType travType=te::common::FORWARDONLY, te::common::AccessPolicy rwRole=te::common::RAccess)
te::gm::Geometry
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
te::pgis::PreparedQuery::prepare
void prepare(const std::string &query, const std::vector< te::dt::Property * > &paramTypes)
It prepares the query using native dialect.
te::pgis::PreparedQuery::bind
void bind(int i, const te::gm::Geometry &value)
Binds the i-th parameter of the query to a value.
te::pgis::PreparedQuery::m_nparams
std::size_t m_nparams
Definition: PreparedQuery.h:155
te::da::PreparedQuery
A class that model a prepared query.
Definition: PreparedQuery.h:70
te::pgis::PreparedQuery::m_result
PGresult * m_result
Definition: PreparedQuery.h:151
te::common::AccessPolicy
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
te::pgis::PreparedQuery
A class that implements a prepared query for PostgreSQL data access driver.
Definition: PreparedQuery.h:69
te::common::FORWARDONLY
@ FORWARDONLY
Definition: Enums.h:55