1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtSql module of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
42
#ifndef QSQLDATABASE_H
43
#define QSQLDATABASE_H
45
#include <QtCore/qstring.h>
46
#include <QtSql/qsql.h>
58
class QSqlDatabasePrivate;
60
class Q_SQL_EXPORT QSqlDriverCreatorBase
63
virtual ~QSqlDriverCreatorBase() {}
64
virtual QSqlDriver *createObject() const = 0;
68
class QSqlDriverCreator : public QSqlDriverCreatorBase
71
QSqlDriver *createObject() const { return new T; }
74
class Q_SQL_EXPORT QSqlDatabase
78
QSqlDatabase(const QSqlDatabase &other);
81
QSqlDatabase &operator=(const QSqlDatabase &other);
84
bool open(const QString& user, const QString& password);
87
bool isOpenError() const;
88
QStringList tables(QSql::TableType type = QSql::Tables) const;
89
QSqlIndex primaryIndex(const QString& tablename) const;
90
QSqlRecord record(const QString& tablename) const;
91
QSqlQuery exec(const QString& query = QString()) const;
92
QSqlError lastError() const;
99
void setDatabaseName(const QString& name);
100
void setUserName(const QString& name);
101
void setPassword(const QString& password);
102
void setHostName(const QString& host);
104
void setConnectOptions(const QString& options = QString());
105
QString databaseName() const;
106
QString userName() const;
107
QString password() const;
108
QString hostName() const;
109
QString driverName() const;
111
QString connectOptions() const;
112
QString connectionName() const;
113
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
114
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
116
QSqlDriver* driver() const;
118
QT_STATIC_CONST char *defaultConnection;
120
static QSqlDatabase addDatabase(const QString& type,
121
const QString& connectionName = QLatin1String(defaultConnection));
122
static QSqlDatabase addDatabase(QSqlDriver* driver,
123
const QString& connectionName = QLatin1String(defaultConnection));
124
static QSqlDatabase cloneDatabase(const QSqlDatabase &other, const QString& connectionName);
125
static QSqlDatabase database(const QString& connectionName = QLatin1String(defaultConnection),
127
static void removeDatabase(const QString& connectionName);
128
static bool contains(const QString& connectionName = QLatin1String(defaultConnection));
129
static QStringList drivers();
130
static QStringList connectionNames();
131
static void registerSqlDriver(const QString &name, QSqlDriverCreatorBase *creator);
132
static bool isDriverAvailable(const QString &name);
135
explicit QSqlDatabase(const QString& type);
136
explicit QSqlDatabase(QSqlDriver* driver);
139
friend class QSqlDatabasePrivate;
140
QSqlDatabasePrivate *d;
143
#ifndef QT_NO_DEBUG_STREAM
144
Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlDatabase &);
151
#endif // QSQLDATABASE_H