qsqldriver.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 QSQLDRIVER_H
00043 #define QSQLDRIVER_H
00044 
00045 #include <QtCore/qobject.h>
00046 #include <QtCore/qstring.h>
00047 #include <QtCore/qstringlist.h>
00048 #include <QtSql/qsql.h>
00049 #ifdef QT3_SUPPORT
00050 #include <QtSql/qsqlquery.h>
00051 #endif
00052 
00053 QT_BEGIN_HEADER
00054 
00055 QT_BEGIN_NAMESPACE
00056 
00057 QT_MODULE(Sql)
00058 
00059 class QSqlDatabase;
00060 class QSqlDriverPrivate;
00061 class QSqlError;
00062 class QSqlField;
00063 class QSqlIndex;
00064 class QSqlRecord;
00065 class QSqlResult;
00066 class QVariant;
00067 
00068 class Q_SQL_EXPORT QSqlDriver : public QObject
00069 {
00070     friend class QSqlDatabase;
00071     Q_OBJECT
00072     Q_DECLARE_PRIVATE(QSqlDriver)
00073 
00074 public:
00075     enum DriverFeature { Transactions, QuerySize, BLOB, Unicode, PreparedQueries,
00076                          NamedPlaceholders, PositionalPlaceholders, LastInsertId,
00077                          BatchOperations, SimpleLocking, LowPrecisionNumbers,
00078                          EventNotifications, FinishQuery, MultipleResultSets };
00079 
00080     enum StatementType { WhereStatement, SelectStatement, UpdateStatement,
00081                          InsertStatement, DeleteStatement };
00082 
00083     enum IdentifierType { FieldName, TableName };
00084 
00085     explicit QSqlDriver(QObject *parent=0);
00086     ~QSqlDriver();
00087     virtual bool isOpen() const;
00088     bool isOpenError() const;
00089 
00090     virtual bool beginTransaction();
00091     virtual bool commitTransaction();
00092     virtual bool rollbackTransaction();
00093     virtual QStringList tables(QSql::TableType tableType) const;
00094     virtual QSqlIndex primaryIndex(const QString &tableName) const;
00095     virtual QSqlRecord record(const QString &tableName) const;
00096 #ifdef QT3_SUPPORT
00097     inline QT3_SUPPORT QSqlRecord record(const QSqlQuery& query) const
00098     { return query.record(); }
00099     inline QT3_SUPPORT QSqlRecord recordInfo(const QString& tablename) const
00100     { return record(tablename); }
00101     inline QT3_SUPPORT QSqlRecord recordInfo(const QSqlQuery& query) const
00102     { return query.record(); }
00103     inline QT3_SUPPORT QString nullText() const { return QLatin1String("NULL"); }
00104     inline QT3_SUPPORT QString formatValue(const QSqlField *field, bool trimStrings = false) const
00105     { return field ? formatValue(*field, trimStrings) : QString(); }
00106 #endif
00107     virtual QString formatValue(const QSqlField& field, bool trimStrings = false) const;
00108 
00109     virtual QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
00110     virtual QString sqlStatement(StatementType type, const QString &tableName,
00111                                  const QSqlRecord &rec, bool preparedStatement) const;
00112 
00113     QSqlError lastError() const;
00114 
00115     virtual QVariant handle() const;
00116     virtual bool hasFeature(DriverFeature f) const = 0;
00117     virtual void close() = 0;
00118     virtual QSqlResult *createResult() const = 0;
00119 
00120     virtual bool open(const QString& db,
00121                       const QString& user = QString(),
00122                       const QString& password = QString(),
00123                       const QString& host = QString(),
00124                       int port = -1,
00125                       const QString& connOpts = QString()) = 0;
00126     bool subscribeToNotification(const QString &name);      // ### Qt 5: make virtual
00127     bool unsubscribeFromNotification(const QString &name);  // ### Qt 5: make virtual
00128     QStringList subscribedToNotifications() const;          // ### Qt 5: make virtual
00129 
00130     bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const; // ### Qt 5: make virtual
00131     QString stripDelimiters(const QString &identifier, IdentifierType type) const;  // ### Qt 5: make virtual
00132 
00133     void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
00134     QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
00135 
00136 Q_SIGNALS:
00137     void notification(const QString &name);
00138 
00139 protected:
00140     virtual void setOpen(bool o);
00141     virtual void setOpenError(bool e);
00142     virtual void setLastError(const QSqlError& e);
00143 
00144 protected Q_SLOTS:
00145     bool subscribeToNotificationImplementation(const QString &name);        // ### Qt 5: eliminate, see subscribeToNotification()
00146     bool unsubscribeFromNotificationImplementation(const QString &name);    // ### Qt 5: eliminate, see unsubscribeFromNotification()
00147     QStringList subscribedToNotificationsImplementation() const;            // ### Qt 5: eliminate, see subscribedNotifications()
00148 
00149     bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const;   // ### Qt 5: eliminate, see isIdentifierEscaped()
00150     QString stripDelimitersImplementation(const QString &identifier, IdentifierType type) const;    // ### Qt 5: eliminate, see stripDelimiters()
00151 
00152 private:
00153     Q_DISABLE_COPY(QSqlDriver)
00154 };
00155 
00156 QT_END_NAMESPACE
00157 
00158 QT_END_HEADER
00159 
00160 #endif // QSQLDRIVER_H