Qt 4.8
qsqlnulldriver_p.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 QSQLNULLDRIVER_P_H
43 #define QSQLNULLDRIVER_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. This header file may
50 // change from version to version without notice, or even be
51 // removed.
52 //
53 // We mean it.
54 //
55 
56 #include "QtCore/qvariant.h"
57 #include "QtSql/qsqldriver.h"
58 #include "QtSql/qsqlerror.h"
59 #include "QtSql/qsqlresult.h"
60 
62 
63 class QSqlNullResult : public QSqlResult
64 {
65 public:
66  inline explicit QSqlNullResult(const QSqlDriver* d): QSqlResult(d)
68  QSqlError(QLatin1String("Driver not loaded"), QLatin1String("Driver not loaded"), QSqlError::ConnectionError)); }
69 protected:
70  inline QVariant data(int) { return QVariant(); }
71  inline bool reset (const QString&) { return false; }
72  inline bool fetch(int) { return false; }
73  inline bool fetchFirst() { return false; }
74  inline bool fetchLast() { return false; }
75  inline bool isNull(int) { return false; }
76  inline int size() { return -1; }
77  inline int numRowsAffected() { return 0; }
78 
79  inline void setAt(int) {}
80  inline void setActive(bool) {}
81  inline void setLastError(const QSqlError&) {}
82  inline void setQuery(const QString&) {}
83  inline void setSelect(bool) {}
84  inline void setForwardOnly(bool) {}
85 
86  inline bool exec() { return false; }
87  inline bool prepare(const QString&) { return false; }
88  inline bool savePrepare(const QString&) { return false; }
89  inline void bindValue(int, const QVariant&, QSql::ParamType) {}
90  inline void bindValue(const QString&, const QVariant&, QSql::ParamType) {}
91 };
92 
93 class QSqlNullDriver : public QSqlDriver
94 {
95 public:
98  QSqlError(QLatin1String("Driver not loaded"), QLatin1String("Driver not loaded"), QSqlError::ConnectionError)); }
99  inline bool hasFeature(DriverFeature) const { return false; }
100  inline bool open(const QString &, const QString & , const QString & ,
101  const QString &, int, const QString&)
102  { return false; }
103  inline void close() {}
104  inline QSqlResult *createResult() const { return new QSqlNullResult(this); }
105 
106 protected:
107  inline void setOpen(bool) {}
108  inline void setOpenError(bool) {}
109  inline void setLastError(const QSqlError&) {}
110 };
111 
113 
114 #endif // QSQLNULLDRIVER_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
void bindValue(int, const QVariant &, QSql::ParamType)
Binds the value val of parameter type paramType to position index in the current record (row)...
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool fetchLast()
Positions the result to the last record (last row) in the result.
DriverFeature
This enum contains a list of features a driver might support.
Definition: qsqldriver.h:75
void setLastError(const QSqlError &)
This function is provided for derived classes to set the last error to error.
void setOpenError(bool)
This function sets the open error state of the database to error.
bool isNull(int)
Returns true if the field at position index in the current row is null; otherwise returns false...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
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
void setAt(int)
This function is provided for derived classes to set the internal (zero-based) row position to index...
void bindValue(const QString &, const QVariant &, QSql::ParamType)
Binds the value val of parameter type paramType to the placeholder name in the current record (row)...
void setLastError(const QSqlError &)
This function is used to set the value of the last error, error, that occurred on the database...
virtual void setLastError(const QSqlError &e)
This function is provided for derived classes to set the last error to error.
Definition: qsqlresult.cpp:417
bool hasFeature(DriverFeature) const
Returns true if the driver supports feature feature; otherwise returns false.
bool fetchFirst()
Positions the result to the first record (row 0) in the result.
void setForwardOnly(bool)
Sets forward only mode to forward.
QVariant data(int)
Returns the data for field index in the current row as a QVariant.
QSqlResultPrivate * d
Definition: qsqlresult.h:142
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool fetch(int)
Positions the result to an arbitrary (zero-based) row index.
bool exec()
Executes the query, returning true if successful; otherwise returns false.
void close()
Derived classes must reimplement this pure virtual function in order to close the database connection...
void setActive(bool)
This function is provided for derived classes to set the internal active state to active...
void setQuery(const QString &)
Sets the current query for the result to query.
void setOpen(bool)
This function sets the open state of the database to open.
void setSelect(bool)
This function is provided for derived classes to indicate whether or not the current statement is a S...
QSqlNullResult(const QSqlDriver *d)
bool savePrepare(const QString &)
Prepares the given query, using the underlying database functionality where possible.
bool open(const QString &, const QString &, const QString &, const QString &, int, const QString &)
Derived classes must reimplement this pure virtual function to open a database connection on database...
virtual void setLastError(const QSqlError &e)
This function is used to set the value of the last error, error, that occurred on the database...
Definition: qsqldriver.cpp:350
bool reset(const QString &)
Sets the result to use the SQL statement query for subsequent data retrieval.
int size()
Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELE...
QSqlResult * createResult() const
Creates an empty SQL result on the database.
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases...
Definition: qsqlresult.h:63
int numRowsAffected()
Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or i...
bool prepare(const QString &)
Prepares the given query for execution; the query will normally use placeholders so that it can be ex...