KDb

PostgresqlConnection.h
1/* This file is part of the KDE project
2 Copyright (C) 2003 Adam Pigg <adam@piggz.co.uk>
3 Copyright (C) 2010-2016 Jarosław Staniek <staniek@kde.org>
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
29class PostgresqlConnectionInternal;
30
31//! @internal
33{
34public:
37private:
38 Q_DISABLE_COPY(PostgresqlTransactionData)
39};
40
41class PostgresqlConnection : public KDbConnection
42{
43 Q_DECLARE_TR_FUNCTIONS(PostgresqlConnection)
44public:
45 ~PostgresqlConnection() override;
46
47 //! @return a new query based on a query statement
48 Q_REQUIRED_RESULT KDbCursor *prepareQuery(const KDbEscapedString &sql,
50 = KDbCursor::Option::None) override;
51
52 //! @return a new query based on a query object
53 Q_REQUIRED_RESULT KDbCursor *prepareQuery(KDbQuerySchema *query,
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
63private:
64 /*! Used by driver */
65 PostgresqlConnection(KDbDriver *driver, const KDbConnectionData& connData,
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
Database specific connection data, e.g. host, port.
Generic options for a single connection. The options are accessible using key/value pairs....
Provides database connection, allowing queries and data modification.
KDbDriver * driver() const
KDbConnectionOptions * options()
Provides database cursor functionality.
Definition KDbCursor.h:69
Database driver's abstraction.
Definition KDbDriver.h:50
Specialized string for escaping.
Prepared statement interface for backend-dependent implementations.
KDbQuerySchema provides information about database query.
The KDbSqlResult class abstracts result of a raw SQL query preparation by KDbConnection::prepareSql()
Internal prototype for storing transaction handle for KDbTransaction object.
PostgreSQL database driver.
3-state logical type with three values: true, false and cancelled and convenient operators.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:11:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.