- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qsqldatabase.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtSql module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QSQLDATABASE_H
    00043 #define QSQLDATABASE_H
    00044
    00045 #include <QtCore/qstring.h>
    00046 #include <QtSql/qsql.h>
    00047 #ifdef QT3_SUPPORT
    00048 #include <QtSql/qsqlrecord.h>
    00049 #endif
    00050
    00051 QT_BEGIN_HEADER
    00052
    00053 QT_BEGIN_NAMESPACE
    00054
    00055 QT_MODULE(Sql)
    00056
    00057 class QSqlError;
    00058 class QSqlDriver;
    00059 class QSqlIndex;
    00060 class QSqlRecord;
    00061 class QSqlQuery;
    00062 class QSqlDatabasePrivate;
    00063
    00064 class Q_SQL_EXPORT QSqlDriverCreatorBase
    00065 {
    00066 public:
    00067     virtual ~QSqlDriverCreatorBase() {}
    00068     virtual QSqlDriver *createObject() const = 0;
    00069 };
    00070
    00071 template <class T>
    00072 class QSqlDriverCreator : public QSqlDriverCreatorBase
    00073 {
    00074 public:
    00075     QSqlDriver *createObject() const { return new T; }
    00076 };
    00077
    00078 class Q_SQL_EXPORT QSqlDatabase
    00079 {
    00080 public:
    00081     QSqlDatabase();
    00082     QSqlDatabase(const QSqlDatabase &other);
    00083     ~QSqlDatabase();
    00084
    00085     QSqlDatabase &operator=(const QSqlDatabase &other);
    00086
    00087     bool open();
    00088     bool open(const QString& user, const QString& password);
    00089     void close();
    00090     bool isOpen() const;
    00091     bool isOpenError() const;
    00092     QStringList tables(QSql::TableType type = QSql::Tables) const;
    00093     QSqlIndex primaryIndex(const QString& tablename) const;
    00094     QSqlRecord record(const QString& tablename) const;
    00095 #ifdef QT3_SUPPORT
    00096     QT3_SUPPORT QSqlRecord record(const QSqlQuery& query) const;
    00097     inline QT3_SUPPORT QSqlRecord recordInfo(const QString& tablename) const
    00098     { return record(tablename); }
    00099     QT3_SUPPORT QSqlRecord recordInfo(const QSqlQuery& query) const;
    00100 #endif
    00101     QSqlQuery exec(const QString& query = QString()) const;
    00102     QSqlError lastError() const;
    00103     bool isValid() const;
    00104
    00105     bool transaction();
    00106     bool commit();
    00107     bool rollback();
    00108
    00109     void setDatabaseName(const QString& name);
    00110     void setUserName(const QString& name);
    00111     void setPassword(const QString& password);
    00112     void setHostName(const QString& host);
    00113     void setPort(int p);
    00114     void setConnectOptions(const QString& options = QString());
    00115     QString databaseName() const;
    00116     QString userName() const;
    00117     QString password() const;
    00118     QString hostName() const;
    00119     QString driverName() const;
    00120     int port() const;
    00121     QString connectOptions() const;
    00122     QString connectionName() const;
    00123     void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
    00124     QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
    00125
    00126     QSqlDriver* driver() const;
    00127
    00128     QT_STATIC_CONST char *defaultConnection;
    00129
    00130     static QSqlDatabase addDatabase(const QString& type,
    00131                                  const QString& connectionName = QLatin1String(defaultConnection));
    00132     static QSqlDatabase addDatabase(QSqlDriver* driver,
    00133                                  const QString& connectionName = QLatin1String(defaultConnection));
    00134     static QSqlDatabase cloneDatabase(const QSqlDatabase &other, const QString& connectionName);
    00135     static QSqlDatabase database(const QString& connectionName = QLatin1String(defaultConnection),
    00136                                  bool open = true);
    00137     static void removeDatabase(const QString& connectionName);
    00138     static bool contains(const QString& connectionName = QLatin1String(defaultConnection));
    00139     static QStringList drivers();
    00140     static QStringList connectionNames();
    00141     static void registerSqlDriver(const QString &name, QSqlDriverCreatorBase *creator);
    00142     static bool isDriverAvailable(const QString &name);
    00143
    00144 protected:
    00145     explicit QSqlDatabase(const QString& type);
    00146     explicit QSqlDatabase(QSqlDriver* driver);
    00147
    00148 private:
    00149     friend class QSqlDatabasePrivate;
    00150     QSqlDatabasePrivate *d;
    00151 };
    00152
    00153 #ifndef QT_NO_DEBUG_STREAM
    00154 Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlDatabase &);
    00155 #endif
    00156
    00157 QT_END_NAMESPACE
    00158
    00159 QT_END_HEADER
    00160
    00161 #endif // QSQLDATABASE_H