Qt 4.8
qsql_mysql.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_MYSQL_H
43 #define QSQL_MYSQL_H
44 
45 #include <QtSql/qsqldriver.h>
46 #include <QtSql/qsqlresult.h>
47 
48 #if defined (Q_OS_WIN32)
49 #include <QtCore/qt_windows.h>
50 #endif
51 
52 #include <mysql.h>
53 
54 #ifdef QT_PLUGIN
55 #define Q_EXPORT_SQLDRIVER_MYSQL
56 #else
57 #define Q_EXPORT_SQLDRIVER_MYSQL Q_SQL_EXPORT
58 #endif
59 
61 
63 
66 class QMYSQLDriver;
67 class QSqlRecordInfo;
68 
69 class QMYSQLResult : public QSqlResult
70 {
71  friend class QMYSQLDriver;
72  friend class QMYSQLResultPrivate;
73 public:
74  explicit QMYSQLResult(const QMYSQLDriver* db);
75  ~QMYSQLResult();
76 
77  QVariant handle() const;
78 protected:
79  void cleanup();
80  bool fetch(int i);
81  bool fetchNext();
82  bool fetchLast();
83  bool fetchFirst();
84  QVariant data(int field);
85  bool isNull(int field);
86  bool reset (const QString& query);
87  int size();
88  int numRowsAffected();
89  QVariant lastInsertId() const;
90  QSqlRecord record() const;
91  void virtual_hook(int id, void *data);
92  bool nextResult();
93 
94 #if MYSQL_VERSION_ID >= 40108
95  bool prepare(const QString& stmt);
96  bool exec();
97 #endif
98 private:
100 };
101 
103 {
104  Q_OBJECT
105  friend class QMYSQLResult;
106 public:
107  explicit QMYSQLDriver(QObject *parent=0);
108  explicit QMYSQLDriver(MYSQL *con, QObject * parent=0);
109  ~QMYSQLDriver();
110  bool hasFeature(DriverFeature f) const;
111  bool open(const QString & db,
112  const QString & user,
113  const QString & password,
114  const QString & host,
115  int port,
116  const QString& connOpts);
117  void close();
118  QSqlResult *createResult() const;
119  QStringList tables(QSql::TableType) const;
120  QSqlIndex primaryIndex(const QString& tablename) const;
121  QSqlRecord record(const QString& tablename) const;
122  QString formatValue(const QSqlField &field,
123  bool trimStrings) const;
124  QVariant handle() const;
125  QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
126 
127 protected Q_SLOTS:
128  bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const;
129 
130 protected:
131  bool beginTransaction();
132  bool commitTransaction();
133  bool rollbackTransaction();
134 private:
135  void init();
137 };
138 
140 
142 
143 #endif // QSQL_MYSQL_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
bool isNull(int field)
Returns true if the field at position index in the current row is null; otherwise returns false...
Definition: qsql_mysql.cpp:678
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
#define Q_EXPORT_SQLDRIVER_MYSQL
Definition: qsql_mysql.h:57
bool reset(const QString &query)
Sets the result to use the SQL statement query for subsequent data retrieval.
Definition: qsql_mysql.cpp:686
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_mysql.cpp:723
bool fetchFirst()
Positions the result to the first record (row 0) in the result.
Definition: qsql_mysql.cpp:579
void cleanup()
Definition: qsql_mysql.cpp:429
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
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QVariant handle() const
Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVarian...
Definition: qsql_mysql.cpp:419
int numRowsAffected()
Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or i...
Definition: qsql_mysql.cpp:738
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QMYSQLResultPrivate * d
Definition: qsql_mysql.h:99
QVariant lastInsertId() const
Returns the object ID of the most recent inserted row if the database supports it.
Definition: qsql_mysql.cpp:743
static bool init
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool fetchLast()
Positions the result to the last record (last row) in the result.
Definition: qsql_mysql.cpp:552
TableType
Definition: qsql.h:74
virtual bool exec()
Executes the query, returning true if successful; otherwise returns false.
Definition: qsqlresult.cpp:675
virtual bool prepare(const QString &query)
Prepares the given query for execution; the query will normally use placeholders so that it can be ex...
Definition: qsqlresult.cpp:641
bool fetch(int i)
Positions the result to an arbitrary (zero-based) row index.
Definition: qsql_mysql.cpp:479
#define Q_OBJECT
Definition: qobjectdefs.h:157
bool fetchNext()
Positions the result to the next available record (row) in the result.
Definition: qsql_mysql.cpp:523
QVariant data(int field)
Returns the data for field index in the current row as a QVariant.
Definition: qsql_mysql.cpp:589
static bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature)
Definition: qdockwidget.cpp:74
bool nextResult()
Definition: qsql_mysql.cpp:787
void virtual_hook(int id, void *data)
Definition: qsql_mysql.cpp:839
QSqlRecord record() const
Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
Definition: qsql_mysql.cpp:762
QMYSQLResult(const QMYSQLDriver *db)
Definition: qsql_mysql.cpp:407
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
#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
friend class QMYSQLDriver
Definition: qsql_mysql.h:71
IdentifierType
This enum contains a list of SQL identifier types.
Definition: qsqldriver.h:83
int open(const char *, int,...)
QMYSQLDriverPrivate * d
Definition: qsql_mysql.h:136