1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtSql module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
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 |
|
---|
60 | QT_BEGIN_HEADER
|
---|
61 |
|
---|
62 | QT_BEGIN_NAMESPACE
|
---|
63 |
|
---|
64 | class QMYSQLDriverPrivate;
|
---|
65 | class QMYSQLResultPrivate;
|
---|
66 | class QMYSQLDriver;
|
---|
67 | class QSqlRecordInfo;
|
---|
68 |
|
---|
69 | class QMYSQLResult : public QSqlResult
|
---|
70 | {
|
---|
71 | friend class QMYSQLDriver;
|
---|
72 | public:
|
---|
73 | explicit QMYSQLResult(const QMYSQLDriver* db);
|
---|
74 | ~QMYSQLResult();
|
---|
75 |
|
---|
76 | QVariant handle() const;
|
---|
77 | protected:
|
---|
78 | void cleanup();
|
---|
79 | bool fetch(int i);
|
---|
80 | bool fetchNext();
|
---|
81 | bool fetchLast();
|
---|
82 | bool fetchFirst();
|
---|
83 | QVariant data(int field);
|
---|
84 | bool isNull(int field);
|
---|
85 | bool reset (const QString& query);
|
---|
86 | int size();
|
---|
87 | int numRowsAffected();
|
---|
88 | QVariant lastInsertId() const;
|
---|
89 | QSqlRecord record() const;
|
---|
90 | void virtual_hook(int id, void *data);
|
---|
91 | bool nextResult();
|
---|
92 |
|
---|
93 | #if MYSQL_VERSION_ID >= 40108
|
---|
94 | bool prepare(const QString& stmt);
|
---|
95 | bool exec();
|
---|
96 | #endif
|
---|
97 | private:
|
---|
98 | QMYSQLResultPrivate* d;
|
---|
99 | };
|
---|
100 |
|
---|
101 | class Q_EXPORT_SQLDRIVER_MYSQL QMYSQLDriver : public QSqlDriver
|
---|
102 | {
|
---|
103 | Q_OBJECT
|
---|
104 | friend class QMYSQLResult;
|
---|
105 | public:
|
---|
106 | explicit QMYSQLDriver(QObject *parent=0);
|
---|
107 | explicit QMYSQLDriver(MYSQL *con, QObject * parent=0);
|
---|
108 | ~QMYSQLDriver();
|
---|
109 | bool hasFeature(DriverFeature f) const;
|
---|
110 | bool open(const QString & db,
|
---|
111 | const QString & user,
|
---|
112 | const QString & password,
|
---|
113 | const QString & host,
|
---|
114 | int port,
|
---|
115 | const QString& connOpts);
|
---|
116 | void close();
|
---|
117 | QSqlResult *createResult() const;
|
---|
118 | QStringList tables(QSql::TableType) const;
|
---|
119 | QSqlIndex primaryIndex(const QString& tablename) const;
|
---|
120 | QSqlRecord record(const QString& tablename) const;
|
---|
121 | QString formatValue(const QSqlField &field,
|
---|
122 | bool trimStrings) const;
|
---|
123 | QVariant handle() const;
|
---|
124 | QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
|
---|
125 |
|
---|
126 | protected:
|
---|
127 | bool beginTransaction();
|
---|
128 | bool commitTransaction();
|
---|
129 | bool rollbackTransaction();
|
---|
130 | private:
|
---|
131 | void init();
|
---|
132 | QMYSQLDriverPrivate* d;
|
---|
133 | };
|
---|
134 |
|
---|
135 | QT_END_NAMESPACE
|
---|
136 |
|
---|
137 | QT_END_HEADER
|
---|
138 |
|
---|
139 | #endif // QSQL_MYSQL_H
|
---|