src/sql/drivers/mysql/qsql_mysql.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtSql module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    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     friend class QMYSQLResultPrivate;
       
    73 public:
       
    74     explicit QMYSQLResult(const QMYSQLDriver* db);
       
    75     ~QMYSQLResult();
       
    76 
       
    77     QVariant handle() const;
       
    78 protected:
       
    79     void cleanup();
       
    80     bool fetch(int i);
       
    81     bool fetchNext();
       
    82     bool fetchLast();
       
    83     bool fetchFirst();
       
    84     QVariant data(int field);
       
    85     bool isNull(int field);
       
    86     bool reset (const QString& query);
       
    87     int size();
       
    88     int numRowsAffected();
       
    89     QVariant lastInsertId() const;
       
    90     QSqlRecord record() const;
       
    91     void virtual_hook(int id, void *data);
       
    92     bool nextResult();
       
    93 
       
    94 #if MYSQL_VERSION_ID >= 40108
       
    95     bool prepare(const QString& stmt);
       
    96     bool exec();
       
    97 #endif
       
    98 private:
       
    99     QMYSQLResultPrivate* d;
       
   100 };
       
   101 
       
   102 class Q_EXPORT_SQLDRIVER_MYSQL QMYSQLDriver : public QSqlDriver
       
   103 {
       
   104     Q_OBJECT
       
   105     friend class QMYSQLResult;
       
   106 public:
       
   107     explicit QMYSQLDriver(QObject *parent=0);
       
   108     explicit QMYSQLDriver(MYSQL *con, QObject * parent=0);
       
   109     ~QMYSQLDriver();
       
   110     bool hasFeature(DriverFeature f) const;
       
   111     bool open(const QString & db,
       
   112                const QString & user,
       
   113                const QString & password,
       
   114                const QString & host,
       
   115                int port,
       
   116                const QString& connOpts);
       
   117     void close();
       
   118     QSqlResult *createResult() const;
       
   119     QStringList tables(QSql::TableType) const;
       
   120     QSqlIndex primaryIndex(const QString& tablename) const;
       
   121     QSqlRecord record(const QString& tablename) const;
       
   122     QString formatValue(const QSqlField &field,
       
   123                                      bool trimStrings) const;
       
   124     QVariant handle() const;
       
   125     QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
       
   126 
       
   127 protected Q_SLOTS:
       
   128     bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const;
       
   129 
       
   130 protected:
       
   131     bool beginTransaction();
       
   132     bool commitTransaction();
       
   133     bool rollbackTransaction();
       
   134 private:
       
   135     void init();
       
   136     QMYSQLDriverPrivate* d;
       
   137 };
       
   138 
       
   139 QT_END_NAMESPACE
       
   140 
       
   141 QT_END_HEADER
       
   142 
       
   143 #endif // QSQL_MYSQL_H