Qt 4.8
qsql_psql.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSql module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QSQL_PSQL_H
43 #define QSQL_PSQL_H
44 
45 #include <QtSql/qsqlresult.h>
46 #include <QtSql/qsqldriver.h>
47 
48 #ifdef QT_PLUGIN
49 #define Q_EXPORT_SQLDRIVER_PSQL
50 #else
51 #define Q_EXPORT_SQLDRIVER_PSQL Q_SQL_EXPORT
52 #endif
53 
55 
56 typedef struct pg_conn PGconn;
57 typedef struct pg_result PGresult;
58 
60 
61 class QPSQLResultPrivate;
62 class QPSQLDriverPrivate;
63 class QPSQLDriver;
64 class QSqlRecordInfo;
65 
66 class QPSQLResult : public QSqlResult
67 {
68  friend class QPSQLResultPrivate;
69 public:
70  QPSQLResult(const QPSQLDriver* db, const QPSQLDriverPrivate* p);
71  ~QPSQLResult();
72 
73  QVariant handle() const;
74  void virtual_hook(int id, void *data);
75 
76 protected:
77  void cleanup();
78  bool fetch(int i);
79  bool fetchFirst();
80  bool fetchLast();
81  QVariant data(int i);
82  bool isNull(int field);
83  bool reset (const QString& query);
84  int size();
85  int numRowsAffected();
86  QSqlRecord record() const;
87  QVariant lastInsertId() const;
88  bool prepare(const QString& query);
89  bool exec();
90 
91 private:
93 };
94 
96 {
97  Q_OBJECT
98 public:
99  enum Protocol {
100  VersionUnknown = -1,
101  Version6 = 6,
102  Version7 = 7,
103  Version71 = 8,
104  Version73 = 9,
105  Version74 = 10,
106  Version8 = 11,
107  Version81 = 12,
108  Version82 = 13,
109  Version83 = 14,
110  Version84 = 15,
111  Version9 = 16,
112  };
113 
114  explicit QPSQLDriver(QObject *parent=0);
115  explicit QPSQLDriver(PGconn *conn, QObject *parent=0);
116  ~QPSQLDriver();
117  bool hasFeature(DriverFeature f) const;
118  bool open(const QString & db,
119  const QString & user,
120  const QString & password,
121  const QString & host,
122  int port,
123  const QString& connOpts);
124  bool isOpen() const;
125  void close();
126  QSqlResult *createResult() const;
127  QStringList tables(QSql::TableType) const;
128  QSqlIndex primaryIndex(const QString& tablename) const;
129  QSqlRecord record(const QString& tablename) const;
130 
131  Protocol protocol() const;
132  QVariant handle() const;
133 
134  QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
135  QString formatValue(const QSqlField &field, bool trimStrings) const;
136 
137 protected:
138  bool beginTransaction();
139  bool commitTransaction();
140  bool rollbackTransaction();
141 
142 protected Q_SLOTS:
143  bool subscribeToNotificationImplementation(const QString &name);
144  bool unsubscribeFromNotificationImplementation(const QString &name);
145  QStringList subscribedToNotificationsImplementation() const;
146 
147 private Q_SLOTS:
148  void _q_handleNotification(int);
149 
150 private:
151  void init();
153 };
154 
156 
158 
159 #endif // QSQL_PSQL_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition: qsqlindex.h:55
QPSQLResultPrivate * d
Definition: qsql_psql.h:92
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
DriverFeature
This enum contains a list of features a driver might support.
Definition: qsqldriver.h:75
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
int size()
Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELE...
Definition: qsql_psql.cpp:470
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
Definition: qsqldriver.h:68
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_EXPORT_SQLDRIVER_PSQL
Definition: qsql_psql.h:51
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
struct pg_conn PGconn
Definition: qsql_psql.h:56
QPSQLDriverPrivate * d
Definition: qsql_psql.h:152
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QVariant handle() const
Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVarian...
Definition: qsql_psql.cpp:314
void virtual_hook(int id, void *data)
Definition: qsql_psql.cpp:519
static bool init
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QSqlRecord record() const
Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
Definition: qsql_psql.cpp:490
TableType
Definition: qsql.h:74
QVariant lastInsertId() const
Returns the object ID of the most recent inserted row if the database supports it.
Definition: qsql_psql.cpp:480
struct pg_result PGresult
Definition: qsql_psql.h:57
bool fetchLast()
Positions the result to the last record (last row) in the result.
Definition: qsql_psql.cpp:348
#define Q_OBJECT
Definition: qobjectdefs.h:157
void cleanup()
Definition: qsql_psql.cpp:319
bool fetchFirst()
Positions the result to the first record (row 0) in the result.
Definition: qsql_psql.cpp:343
static bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature)
Definition: qdockwidget.cpp:74
bool reset(const QString &query)
Sets the result to use the SQL statement query for subsequent data retrieval.
Definition: qsql_psql.cpp:459
bool prepare(const QString &query)
Prepares the given query for execution; the query will normally use placeholders so that it can be ex...
Definition: qsql_psql.cpp:584
QVariant data(int i)
Returns the data for field index in the current row as a QVariant.
Definition: qsql_psql.cpp:353
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
QPSQLResult(const QPSQLDriver *db, const QPSQLDriverPrivate *p)
Definition: qsql_psql.cpp:296
#define QT_END_HEADER
Definition: qglobal.h:137
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases...
Definition: qsqlresult.h:63
bool fetch(int i)
Positions the result to an arbitrary (zero-based) row index.
Definition: qsql_psql.cpp:329
bool exec()
Executes the query, returning true if successful; otherwise returns false.
Definition: qsql_psql.cpp:612
IdentifierType
This enum contains a list of SQL identifier types.
Definition: qsqldriver.h:83
int open(const char *, int,...)
bool isNull(int field)
Returns true if the field at position index in the current row is null; otherwise returns false...
Definition: qsql_psql.cpp:453
int numRowsAffected()
Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or i...
Definition: qsql_psql.cpp:475