Wt: Wt::Dbo::backend::Postgres Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::Dbo::backend::Postgres Class Reference
Database Objects (Wt::Dbo)

A PostgreSQL connection. More...

`#include <Wt/Dbo/backend/Postgres.h>`

Inheritance diagram for Wt::Dbo::backend::Postgres:
[legend]

## Public Member Functions
| Postgres ()
| Creates new PostgreSQL backend connection.
| Postgres (const std::string &db)
| Opens a new PostgreSQL backend connection.
| Postgres (const Postgres &other)
| Copies a PostgreSQL connection.
| ~Postgres ()
| Destructor.
virtual std::unique_ptr< SqlConnection > | clone () const override
| Clones the connection.
bool | connect (const std::string &db)
| Tries to connect.
void | disconnect ()
| Disconnects.
bool | reconnect ()
| Reconnect.
PGconn * | connection ()
| Returns the underlying connection.
void | setTimeout (std::chrono::microseconds timeout)
| Sets a timeout.
std::chrono::microseconds | timeout () const
| Returns the timeout.
void | setMaximumLifetime (std::chrono::seconds seconds)
| Sets the maximum lifetime for the underlying connection.
virtual void | executeSql (const std::string &sql) override
| Executes an SQL statement.
virtual void | startTransaction () override
| Starts a transaction.
virtual void | commitTransaction () override
| Commits a transaction.
virtual void | rollbackTransaction () override
| Rolls back a transaction.
virtual std::unique_ptr< SqlStatement > | prepareStatement (const std::string &sql) override
| Prepares a statement.
Methods that return dialect information
virtual std::string | autoincrementSql () const override
| Returns the 'autoincrement' SQL type modifier.
virtual std::vector< std::string > | autoincrementCreateSequenceSql (const std::string &table, const std::string &id) const override
| Returns the SQL statement(s) required to create an id sequence.
virtual std::vector< std::string > | autoincrementDropSequenceSql (const std::string &table, const std::string &id) const override
| Returns the SQL statement(s) required to drop an id sequence.
virtual std::string | autoincrementType () const override
| Returns the 'autoincrement' SQL type.
virtual std::string | autoincrementInsertSuffix (const std::string &id) const override
| Returns the suffix for an 'autoincrement' insert statement.
virtual const char * | dateTimeType (SqlDateTimeType type) const override
| Returns the date/time type.
virtual const char * | blobType () const override
| Returns the blob type.
virtual bool | supportAlterTable () const override
| Returns true if the backend support Alter Table.
virtual bool | supportDeferrableFKConstraint () const override
| Returns true if the backend supports "deferrable initially deferred" foreign key constraints.
virtual bool | requireSubqueryAlias () const override
| Returns the true if the database require subquery alias.
Public Member Functions inherited from Wt::Dbo::SqlConnection
virtual | ~SqlConnection ()
| Destructor.
virtual void | executeSqlStateful (const std::string &sql)
| Executes a connection-stateful SQL statement.
virtual SqlStatement * | getStatement (const std::string &id) const
| Returns the statement with the given id.
virtual void | saveStatement (const std::string &id, std::unique_ptr< SqlStatement > statement)
| Saves a statement with the given id.
void | setProperty (const std::string &name, const std::string &value)
| Sets a property.
std::string | property (const std::string &name) const
| Returns a property.
virtual std::string | autoincrementInsertInfix (const std::string &id) const
| Returns the infix for an 'autoincrement' insert statement.
virtual void | prepareForDropTables ()
| Execute code before dropping the tables.
virtual std::string | textType (int size) const
| Returns the text type.
virtual std::string | longLongType () const
| Returns the 64-bit integer type.
virtual const char * | booleanType () const
| Returns the boolean type.
virtual bool | supportUpdateCascade () const
| Returns true if the database supports Update Cascade.
virtual bool | usesRowsFromTo () const
| Returns whether the SQL dialect uses 'ROWS ? TO ?', limit or rownum for partial select results.
virtual const char * | alterTableConstraintString () const
| Returns the command used in alter table .. drop constraint ..

## Detailed Description

A PostgreSQL connection.

This class provides the backend implementation for PostgreSQL databases.

When applicable, exceptions from the backend will return the five-character SQLSTATE error codes, as in http://www.postgresql.org/docs/8.1/static/errcodes-appendix.html, in Exception::code().

## Constructor & Destructor Documentation

## ◆ Postgres() [1/3]

Wt::Dbo::backend::Postgres::Postgres | ( |  | ) |

Creates new PostgreSQL backend connection.

The connection is not yet open, and requires a connect() before it can be used.

## ◆ Postgres() [2/3]

Wt::Dbo::backend::Postgres::Postgres | ( | const std::string & | db | ) |

Opens a new PostgreSQL backend connection.

The `db` may be any of the values supported by PQconnectdb().

## ◆ Postgres() [3/3]

Wt::Dbo::backend::Postgres::Postgres | ( | const Postgres & | other | ) |

Copies a PostgreSQL connection.

This creates a new connection with the same settings as another connection.

See also
  clone()

## ◆ ~Postgres()

Wt::Dbo::backend::Postgres::~Postgres | ( |  | ) |

Destructor.

Closes the connection.

## Member Function Documentation

## ◆ autoincrementCreateSequenceSql()

virtual std::vector< std::string > Wt::Dbo::backend::Postgres::autoincrementCreateSequenceSql | ( | const std::string & | table,
|  | const std::string & | id ) const
| overridevirtual

Returns the SQL statement(s) required to create an id sequence.

This is used by Session::createTables() to create the id sequence for a table. The table's name and primary key are passed as arguments to this function and can be used to construct an SQL sequence that is unique for the table.

Implements Wt::Dbo::SqlConnection.

## ◆ autoincrementDropSequenceSql()

virtual std::vector< std::string > Wt::Dbo::backend::Postgres::autoincrementDropSequenceSql | ( | const std::string & | table,
|  | const std::string & | id ) const
| overridevirtual

Returns the SQL statement(s) required to drop an id sequence.

This is used by Session::dropTables() to drop the id sequence for a table. The table's name and primary key are passed as arguments to this function and can be used to construct an SQL sequence that is unique for the table.

Implements Wt::Dbo::SqlConnection.

## ◆ autoincrementInsertSuffix()

virtual std::string Wt::Dbo::backend::Postgres::autoincrementInsertSuffix | ( | const std::string & | id | ) | const
| overridevirtual

Returns the suffix for an 'autoincrement' insert statement.

This is appended to the `insert` statement, since some back-ends need to be indicated that they should return the autoincrement id.

Implements Wt::Dbo::SqlConnection.

## ◆ autoincrementSql()

virtual std::string Wt::Dbo::backend::Postgres::autoincrementSql | ( |  | ) | const
| overridevirtual

Returns the 'autoincrement' SQL type modifier.

This is used by Session::createTables() to create the id column.

Implements Wt::Dbo::SqlConnection.

## ◆ autoincrementType()

virtual std::string Wt::Dbo::backend::Postgres::autoincrementType | ( |  | ) | const
| overridevirtual

Returns the 'autoincrement' SQL type.

This is used by Session::createTables() to create the id column.

Implements Wt::Dbo::SqlConnection.

## ◆ blobType()

virtual const char * Wt::Dbo::backend::Postgres::blobType | ( |  | ) | const
| overridevirtual

Returns the blob type.

See also
  SqlStatement::bind(int, const std::vector<unsigned char>&)

Implements Wt::Dbo::SqlConnection.

## ◆ clone()

virtual std::unique_ptr< SqlConnection > Wt::Dbo::backend::Postgres::clone | ( |  | ) | const
| overridevirtual

Clones the connection.

Returns a new connection object that is configured like this object. This is used by connection pool implementations to create its connections.

Implements Wt::Dbo::SqlConnection.

## ◆ commitTransaction()

virtual void Wt::Dbo::backend::Postgres::commitTransaction | ( |  | ) |
| overridevirtual

Commits a transaction.

This function commits a transaction.

Implements Wt::Dbo::SqlConnection.

## ◆ connect()

bool Wt::Dbo::backend::Postgres::connect | ( | const std::string & | db | ) |

Tries to connect.

Throws an exception if there was a problem, otherwise true. An example connecion string could be: "host=127.0.0.1 user=test password=test port=5432 dbname=test"

## ◆ dateTimeType()

virtual const char * Wt::Dbo::backend::Postgres::dateTimeType | ( | SqlDateTimeType | type | ) | const
| overridevirtual

Returns the date/time type.

See also
  SqlStatement::bind(int, const std::chrono::system_clock::time_point&, SqlDateTimeType)

Implements Wt::Dbo::SqlConnection.

## ◆ disconnect()

void Wt::Dbo::backend::Postgres::disconnect | ( |  | ) |

Disconnects.

This disconnects from the server. Any subsequent action on the connection will result in an automatic reconnect.

See also
  reconnect()

## ◆ executeSql()

virtual void Wt::Dbo::backend::Postgres::executeSql | ( | const std::string & | sql | ) |
| overridevirtual

Executes an SQL statement.

This is a convenience method for preparing a statement, executing it, and deleting it.

Reimplemented from Wt::Dbo::SqlConnection.

## ◆ prepareStatement()

virtual std::unique_ptr< SqlStatement > Wt::Dbo::backend::Postgres::prepareStatement | ( | const std::string & | sql | ) |
| overridevirtual

Prepares a statement.

Returns the prepared statement.

Implements Wt::Dbo::SqlConnection.

## ◆ reconnect()

bool Wt::Dbo::backend::Postgres::reconnect | ( |  | ) |

Reconnect.

This will try to reconnect a previously disconnected connection. If the connection is still open, it will first disconnect.

## ◆ requireSubqueryAlias()

virtual bool Wt::Dbo::backend::Postgres::requireSubqueryAlias | ( |  | ) | const
| overridevirtual

Returns the true if the database require subquery alias.

This method will return false by default.

Reimplemented from Wt::Dbo::SqlConnection.

## ◆ rollbackTransaction()

virtual void Wt::Dbo::backend::Postgres::rollbackTransaction | ( |  | ) |
| overridevirtual

Rolls back a transaction.

This function rolls back a transaction.

Implements Wt::Dbo::SqlConnection.

## ◆ setMaximumLifetime()

void Wt::Dbo::backend::Postgres::setMaximumLifetime | ( | std::chrono::seconds | seconds | ) |

Sets the maximum lifetime for the underlying connection.

The maximum lifetime is specified in seconds. If set to a value > 0, then the underlying connection object will be closed and reopened when the connection has been open longer than this lifetime.

The default value is -1 (unlimited lifetime).

## ◆ setTimeout()

void Wt::Dbo::backend::Postgres::setTimeout | ( | std::chrono::microseconds | timeout | ) |

Sets a timeout.

Sets a timeout for queries. When the query exceeds this timeout, the connection is closed using disconnect() and an exception is thrown.

In practice, as a result, the connection (and statements) can still be used again when a successful reconnect() is performed.

A value of 0 disables the timeout handling, allowing operations to take as much time is they require.

The default value is 0.

## ◆ startTransaction()

virtual void Wt::Dbo::backend::Postgres::startTransaction | ( |  | ) |
| overridevirtual

Starts a transaction.

This function starts a transaction.

Implements Wt::Dbo::SqlConnection.

## ◆ supportAlterTable()

virtual bool Wt::Dbo::backend::Postgres::supportAlterTable | ( |  | ) | const
| overridevirtual

Returns true if the backend support Alter Table.

This method will return false by default.

Reimplemented from Wt::Dbo::SqlConnection.

## ◆ supportDeferrableFKConstraint()

virtual bool Wt::Dbo::backend::Postgres::supportDeferrableFKConstraint | ( |  | ) | const
| overridevirtual

Returns true if the backend supports "deferrable initially deferred" foreign key constraints.

This method will return false by default.

Reimplemented from Wt::Dbo::SqlConnection.

## ◆ timeout()

std::chrono::microseconds Wt::Dbo::backend::Postgres::timeout | ( |  | ) | const

Returns the timeout.

See also
  setTimeout()