27 #include "../common/StringUtils.h"
28 #include "../common/Translator.h"
29 #include "../dataaccess/dataset/CheckConstraint.h"
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "../dataaccess/dataset/ForeignKey.h"
32 #include "../dataaccess/dataset/Index.h"
33 #include "../dataaccess/dataset/PrimaryKey.h"
34 #include "../dataaccess/dataset/Sequence.h"
35 #include "../dataaccess/dataset/UniqueKey.h"
36 #include "../dataaccess/datasource/ScopedTransaction.h"
37 #include "../dataaccess/query/Select.h"
38 #include "../dataaccess/query/SQLDialect.h"
39 #include "../dataaccess/utils/Utils.h"
40 #include "../datatype/Array.h"
41 #include "../datatype/Property.h"
42 #include "../datatype/SimpleData.h"
43 #include "../geometry/GeometryProperty.h"
44 #include "../geometry/Utils.h"
45 #include "../raster/Grid.h"
46 #include "../raster/BandProperty.h"
47 #include "../raster/RasterProperty.h"
48 #include "../geometry/Geometry.h"
67 #include <boost/format.hpp>
100 m_connInfo = connInfo;
112 return m_pool->getConnection();
117 m_pool->release(conn);
122 return m_timeIsInteger;
127 m_timeIsInteger = timeIsInteger;
135 m_pool->initialize();
137 std::auto_ptr<te::da::DataSourceTransactor> t = getTransactor();
155 return m_pool->isInitialized();
160 return m_pool->isValid();
175 return m_geomTypeOid;
180 return m_rasterTypeOid;
185 return m_currentSchema;
196 std::auto_ptr<DataSource> ds(
new DataSource());
198 ds->setConnectionInfo(dsInfo);
203 std::string sql =
"CREATE DATABASE ";
205 std::map<std::string, std::string>::const_iterator it = dsInfo.find(
"PG_NEWDB_NAME");
206 std::map<std::string, std::string>::const_iterator it_end = dsInfo.end();
211 throw Exception(
TR_PGIS(
"The database could not be created due the missing parameter: PG_NEWDB_NAME!"));
213 it = dsInfo.find(
"PG_NEWDB_TEMPLATE");
216 sql +=
" TEMPLATE = " + it->second;
218 it = dsInfo.find(
"PG_NEWDB_OWNER");
221 sql +=
" OWNER = " + it->second;
223 it = dsInfo.find(
"PG_NEWDB_ENCODING");
226 sql +=
" ENCODING = " + it->second;
228 it = dsInfo.find(
"PG_NEWDB_TABLESPACE");
231 sql +=
" TABLESPACE = " + it->second;
233 it = dsInfo.find(
"PG_NEWDB_CONN_LIMIT");
236 sql +=
" CONNECTION LIMIT = " + it->second;
243 it = dsInfo.find(
"PG_NEWDB_HOST");
246 it = dsInfo.find(
"PG_HOST");
249 m_connInfo[
"PG_HOST"] = it->second;
251 it = dsInfo.find(
"PG_NEWDB_HOSTADDR");
254 it = dsInfo.find(
"PG_HOST_ADDR");
257 m_connInfo[
"PG_HOST_ADDR"] = it->second;
259 it = dsInfo.find(
"PG_NEWDB_PORT");
262 it = dsInfo.find(
"PG_PORT");
265 m_connInfo[
"PG_PORT"] = it->second;
267 it = dsInfo.find(
"PG_NEWDB_NAME");
270 m_connInfo[
"PG_DB_NAME"] = it->second;
272 it = dsInfo.find(
"PG_NEWDB_USER");
275 it = dsInfo.find(
"PG_USER");
278 m_connInfo[
"PG_USER"] = it->second;
280 it = dsInfo.find(
"PG_NEWDB_PASSWORD");
283 it = dsInfo.find(
"PG_PASSWORD");
286 m_connInfo[
"PG_PASSWORD"] = it->second;
288 it = dsInfo.find(
"PG_NEWDB_CONNECT_TIMEOUT");
291 it = dsInfo.find(
"PG_CONNECT_TIMEOUT");
294 m_connInfo[
"PG_CONNECT_TIMEOUT"] = it->second;
296 it = dsInfo.find(
"PG_NEWDB_OPTIONS");
299 it = dsInfo.find(
"PG_OPTIONS");
302 m_connInfo[
"PG_OPTIONS"] = it->second;
304 it = dsInfo.find(
"PG_NEWDB_SSL_MODE");
307 it = dsInfo.find(
"PG_SSL_MODE");
310 m_connInfo[
"PG_SSL_MODE"] = it->second;
312 it = dsInfo.find(
"PG_NEWDB_KRBSRVNAME");
315 it = dsInfo.find(
"PG_KRBSRVNAME");
318 m_connInfo[
"PG_KRBSRVNAME"] = it->second;
320 it = dsInfo.find(
"PG_NEWDB_GSSLIB");
323 it = dsInfo.find(
"PG_GSSLIB");
326 m_connInfo[
"PG_GSSLIB"] = it->second;
328 it = dsInfo.find(
"PG_NEWDB_INITIAL_POOL_SIZE");
331 it = dsInfo.find(
"PG_INITIAL_POOL_SIZE");
334 m_connInfo[
"PG_INITIAL_POOL_SIZE"] = it->second;
336 it = dsInfo.find(
"PG_NEWDB_MIN_POOL_SIZE");
339 it = dsInfo.find(
"PG_MIN_POOL_SIZE");
342 m_connInfo[
"PG_MIN_POOL_SIZE"] = it->second;
344 it = dsInfo.find(
"PG_NEW_DB_MAX_POOL_SIZE");
347 it = dsInfo.find(
"PG_MAX_POOL_SIZE");
350 m_connInfo[
"PG_MAX_POOL_SIZE"] = it->second;
352 it = dsInfo.find(
"PG_NEWDB_MAX_IDLE_TIME");
355 it = dsInfo.find(
"PG_MAX_IDLE_TIME");
358 m_connInfo[
"PG_MAX_IDLE_TIME"] = it->second;
360 it = dsInfo.find(
"PG_NEWDB_CLIENT_ENCODING");
363 it = dsInfo.find(
"PG_CLIENT_ENCODING");
366 m_connInfo[
"PG_CLIENT_ENCODING"] = it->second;
372 std::auto_ptr<DataSource> ds(
new DataSource());
374 ds->setConnectionInfo(dsInfo);
379 std::string sql =
"DROP DATABASE ";
381 std::map<std::string, std::string>::const_iterator it = dsInfo.find(
"PG_DB_TO_DROP");
383 if(it == dsInfo.end())
384 throw Exception(
TR_PGIS(
"Could not drop the database due the missing parameter: PG_DB_TO_DROP!"));
386 if((it->second ==
"postgres") || (it->second ==
"template_postgis"))
387 throw Exception(
TR_PGIS(
"The database postgres or template_postgis is not allowed to be dropped!"));
398 if(dsInfo.count(
"PG_CHECK_DB_EXISTENCE") == 0)
399 throw Exception(
TR_PGIS(
"Could not check the PostgreSQL database existence due the missing parameter: PG_CHECK_DB_EXISTENCE!"));
401 const std::string& dbName = dsInfo.find(
"PG_CHECK_DB_EXISTENCE")->second;
404 std::auto_ptr<DataSource> ds(
new DataSource());
406 ds->setConnectionInfo(dsInfo);
410 std::string sql(
"SELECT * FROM pg_database WHERE datname = '");
414 std::auto_ptr<te::da::DataSet> database(ds->query(sql));
418 return database->moveNext();
424 std::auto_ptr<DataSource> ds(
new DataSource());
426 ds->setConnectionInfo(dsInfo);
430 std::string sql(
"SELECT datname FROM pg_database");
432 std::auto_ptr<te::da::DataSet> dataset(ds->query(sql));
434 std::vector<std::string> dataSourceNames;
436 while(dataset->moveNext())
437 dataSourceNames.push_back(dataset->getString(0));
441 return dataSourceNames;
447 std::vector<std::string> encodings;
450 std::auto_ptr<DataSource> ds(
new DataSource());
452 ds->setConnectionInfo(dsInfo);
456 std::string sql(
"SELECT DISTINCT pg_catalog.pg_encoding_to_char(conforencoding) FROM pg_catalog.pg_conversion ORDER BY pg_catalog.pg_encoding_to_char(conforencoding)");
458 std::auto_ptr<te::da::DataSet> encs(ds->query(sql));
460 while(encs->moveNext())
461 encodings.push_back(encs->getString(0));
unsigned int getGeomTypeId() const
It returns the type id associated to the PostGIS Geometry type.
A class that implements a prepared query for PostgreSQL data access driver.
unsigned int getRasterTypeId()
It will check in the database catalog the number that identifies the PostGIS Raster type...
#define PGIS_DRIVER_IDENTIFIER
The PostGIS driver identifier string.
const std::map< std::string, std::string > & getConnectionInfo() const
It returns the set of parameters used to set up the access channel to the underlying repository...
An static class with global definitions.
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
const std::string & getCurrentSchema() const
It returns the current schema associated to the database connection, or NULL, if none is set...
void create(const std::map< std::string, std::string > &dsInfo)
It creates a new data source.
void closeConnection(Connection *conn)
A class that implements a connection pool for PostGIS.
void close()
It closes the data source and clears all the resources used by its internal communication channel...
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
This class implements a connection pool for the PostGIS driver.
void drop(const std::map< std::string, std::string > &dsInfo)
It removes the data source with the connection information from a driver.
te::pgis::Connection * getConnection()
void open()
It opens the connection(s) to the PostgreSQL database server.
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
bool exists(const std::map< std::string, std::string > &dsInfo)
Check the existence of a data source in a driver.
void setTimeAsInteger(bool timeIsInteger)
An exception class for the PostGIS driver.
ConnectionPool * getConnPool() const
It returns a pointer to the internal connection pool.
#define TR_PGIS(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
bool isValid() const
It checks if the data source is valid (available for using).
It represents the SQL query dialect accepted by a given data source.
void setConnectionInfo(const std::map< std::string, std::string > &connInfo)
It sets the connection information to be used when connecting to the data source. ...
Utility functions for the data access module.
std::vector< std::string > getEncodings(const std::map< std::string, std::string > &dsInfo)
It gets the encodings for the data source.
A visitor for building an SQL statement using PostGIS dialect.
static te::da::DataSourceCapabilities * sm_capabilities
The query dialect supported by PostGIS driver.
unsigned int getGeomTypeId()
It will check in the database catalog the number that identifies the PostGIS Geometry type...
A class that implements a connection to a PostgreSQL database.
A class that implements a connection to a PostgreSQL database.
A Transactor can be viewed as a connection to the data source for reading/writing things into it...
The transactor class for the PostGIS driver.
std::vector< std::string > getDataSourceNames(const std::map< std::string, std::string > &dsInfo)
It gets the data source names available in a driver.
unsigned int getRasterTypeId() const
It returns the type id associated to the PostGIS Raster type.
ConnectionPool * m_pool
The connection pool.
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns an object that can execute transactions in the context of a data source.
A dataset is the unit of information manipulated by the data access module of TerraLib.
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
static te::da::SQLDialect * sm_queryDialect
The query dialect supported by PostGIS driver.
~DataSource()
Virtual destructor.
void getDatabaseInfo(std::string ¤tSchema)
It retrieves some information about the database such as the default schema used when no one is provi...
Implementation of the data source for the PostGIS driver.