KDb

PostgresqlConnection.h
1 /* This file is part of the KDE project
2  Copyright (C) 2003 Adam Pigg <[email protected]>
3  Copyright (C) 2010-2016 JarosÅ‚aw Staniek <[email protected]>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This program 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 GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this program; see the file COPYING. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef KDB_POSTGRESQLCONNECTION_H
22 #define KDB_POSTGRESQLCONNECTION_H
23 
24 #include "KDbConnection.h"
25 #include "KDbTransactionData.h"
26 
27 #include <libpq-fe.h>
28 
29 class PostgresqlConnectionInternal;
30 
31 //! @internal
33 {
34 public:
37 private:
38  Q_DISABLE_COPY(PostgresqlTransactionData)
39 };
40 
41 class PostgresqlConnection : public KDbConnection
42 {
43  Q_DECLARE_TR_FUNCTIONS(PostgresqlConnection)
44 public:
45  ~PostgresqlConnection() override;
46 
47  //! @return a new query based on a query statement
48  Q_REQUIRED_RESULT KDbCursor *prepareQuery(const KDbEscapedString &sql,
49  KDbCursor::Options options
50  = KDbCursor::Option::None) override;
51 
52  //! @return a new query based on a query object
53  Q_REQUIRED_RESULT KDbCursor *prepareQuery(KDbQuerySchema *query,
54  KDbCursor::Options options
55  = KDbCursor::Option::None) override;
56 
57  Q_REQUIRED_RESULT KDbPreparedStatementInterface *prepareStatementInternal() override;
58 
59  /*! Connection-specific string escaping. */
60  KDbEscapedString escapeString(const QString& str) const override;
61  virtual KDbEscapedString escapeString(const QByteArray& str) const;
62 
63 private:
64  /*! Used by driver */
65  PostgresqlConnection(KDbDriver *driver, const KDbConnectionData& connData,
66  const KDbConnectionOptions &options);
67 
68  //! @return true if currently connected to a database, ignoring the m_is_connected flag.
69  bool drv_isDatabaseUsed() const override;
70  //! Noop: we tell we are connected, but we wont actually connect until we use a database.
71  bool drv_connect() override;
72  bool drv_getServerVersion(KDbServerVersionInfo* version) override;
73  //! Noop: we tell we have disconnected, but it is actually handled by closeDatabase.
74  bool drv_disconnect() override;
75  //! @return a list of database names
76  bool drv_getDatabasesList(QStringList* list) override;
77  //! Create a new database
78  bool drv_createDatabase(const QString &dbName = QString()) override;
79  //! Uses database. Note that if data().localSocketFileName() is not empty,
80  //! only directory path is used for connecting; the local socket's filename stays ".s.PGSQL.5432".
81  bool drv_useDatabase(const QString &dbName = QString(), bool *cancelled = nullptr,
82  KDbMessageHandler* msgHandler = nullptr) override;
83  //! Close the database connection
84  bool drv_closeDatabase() override;
85  //! Drops the given database
86  bool drv_dropDatabase(const QString &dbName = QString()) override;
87  //! Executes an SQL statement
88  Q_REQUIRED_RESULT KDbSqlResult *drv_prepareSql(const KDbEscapedString &sql) override;
89  bool drv_executeSql(const KDbEscapedString& sql) override;
90 
91  //! Implemented for KDbResultable
92  QString serverResultName() const override;
93 
94 //! @todo move this somewhere to low level class (MIGRATION?)
95  tristate drv_containsTable(const QString &tableName) override;
96 
97  void storeResult(PGresult *pgResult, ExecStatusType execStatus);
98 
99  PostgresqlConnectionInternal * const d;
100 
101  friend class PostgresqlDriver;
102  friend class PostgresqlCursorData;
103  friend class PostgresqlTransactionData;
104  friend class PostgresqlSqlResult;
105  Q_DISABLE_COPY(PostgresqlConnection)
106 };
107 
108 #endif
Provides database cursor functionality.
Definition: KDbCursor.h:68
virtual bool drv_executeSql(const KDbEscapedString &sql)=0
Executes query for a raw SQL statement sql without returning resulting records.
virtual bool drv_getDatabasesList(QStringList *list)
The KDbSqlResult class abstracts result of a raw SQL query preparation by KDbConnection::prepareSql()
Definition: KDbSqlResult.h:44
virtual KDbPreparedStatementInterface * prepareStatementInternal()=0
virtual bool drv_isDatabaseUsed() const
virtual KDbCursor * prepareQuery(const KDbEscapedString &sql, KDbCursor::Options options=KDbCursor::Option::None)=0
Specialized string for escaping.
Database driver's abstraction.
Definition: KDbDriver.h:49
virtual bool drv_useDatabase(const QString &dbName=QString(), bool *cancelled=nullptr, KDbMessageHandler *msgHandler=nullptr)=0
virtual bool drv_disconnect()=0
virtual tristate drv_containsTable(const QString &tableName)=0
virtual QString serverResultName() const
Definition: KDbResult.cpp:209
virtual bool drv_closeDatabase()=0
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition: KDbTristate.h:100
virtual KDbEscapedString escapeString(const QString &str) const
virtual bool drv_connect()=0
Prepared statement interface for backend-dependent implementations.
KDbQuerySchema provides information about database query.
virtual bool drv_dropDatabase(const QString &dbName=QString())=0
Database specific connection data, e.g. host, port.
Generic options for a single connection. The options are accessible using key/value pairs....
virtual bool drv_getServerVersion(KDbServerVersionInfo *version)=0
Provides database connection, allowing queries and data modification.
Definition: KDbConnection.h:51
virtual bool drv_createDatabase(const QString &dbName=QString())=0
PostgreSQL database driver.
Internal prototype for storing transaction handle for KDbTransaction object.
virtual KDbSqlResult * drv_prepareSql(const KDbEscapedString &sql)=0
Prepares query for a raw SQL statement sql with possibility of returning records.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:21:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.