qsql_odbc.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 QSQL_ODBC_H
00043 #define QSQL_ODBC_H
00044 
00045 #include <QtSql/qsqldriver.h>
00046 #include <QtSql/qsqlresult.h>
00047 
00048 #if defined (Q_OS_WIN32)
00049 #include <QtCore/qt_windows.h>
00050 #endif
00051 
00052 #ifdef QT_PLUGIN
00053 #define Q_EXPORT_SQLDRIVER_ODBC
00054 #else
00055 #define Q_EXPORT_SQLDRIVER_ODBC Q_SQL_EXPORT
00056 #endif
00057 
00058 #ifdef Q_OS_UNIX
00059 #define HAVE_LONG_LONG 1 // force UnixODBC NOT to fall back to a struct for BIGINTs
00060 #endif
00061 
00062 #if defined(Q_CC_BOR)
00063 // workaround for Borland to make sure that SQLBIGINT is defined
00064 #  define _MSC_VER 900
00065 #endif
00066 #include <sql.h>
00067 #if defined(Q_CC_BOR)
00068 #  undef _MSC_VER
00069 #endif
00070 
00071 #include <sqlext.h>
00072 
00073 QT_BEGIN_HEADER
00074 
00075 QT_BEGIN_NAMESPACE
00076 
00077 class QODBCPrivate;
00078 class QODBCDriverPrivate;
00079 class QODBCDriver;
00080 class QSqlRecordInfo;
00081 
00082 class QODBCResult : public QSqlResult
00083 {
00084 public:
00085     QODBCResult(const QODBCDriver * db, QODBCDriverPrivate* p);
00086     virtual ~QODBCResult();
00087 
00088     bool prepare(const QString& query);
00089     bool exec();
00090 
00091     QVariant handle() const;
00092     virtual void setForwardOnly(bool forward);
00093 
00094 protected:
00095     bool fetchNext();
00096     bool fetchFirst();
00097     bool fetchLast();
00098     bool fetchPrevious();
00099     bool fetch(int i);
00100     bool reset (const QString& query);
00101     QVariant data(int field);
00102     bool isNull(int field);
00103     int size();
00104     int numRowsAffected();
00105     QSqlRecord record() const;
00106     void virtual_hook(int id, void *data);
00107     bool nextResult();
00108 
00109 private:
00110     QODBCPrivate *d;
00111 };
00112 
00113 class Q_EXPORT_SQLDRIVER_ODBC QODBCDriver : public QSqlDriver
00114 {
00115     Q_OBJECT
00116 public:
00117     explicit QODBCDriver(QObject *parent=0);
00118     QODBCDriver(SQLHANDLE env, SQLHANDLE con, QObject * parent=0);
00119     virtual ~QODBCDriver();
00120     bool hasFeature(DriverFeature f) const;
00121     void close();
00122     QSqlResult *createResult() const;
00123     QStringList tables(QSql::TableType) const;
00124     QSqlRecord record(const QString& tablename) const;
00125     QSqlIndex primaryIndex(const QString& tablename) const;
00126     QVariant handle() const;
00127     QString formatValue(const QSqlField &field,
00128                         bool trimStrings) const;
00129     bool open(const QString& db,
00130               const QString& user,
00131               const QString& password,
00132               const QString& host,
00133               int port,
00134               const QString& connOpts);
00135 
00136     QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
00137 
00138 protected Q_SLOTS:
00139     bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const;
00140 
00141 protected:
00142     bool beginTransaction();
00143     bool commitTransaction();
00144     bool rollbackTransaction();
00145 
00146 private:
00147     void init();
00148     bool endTrans();
00149     void cleanup();
00150     QODBCDriverPrivate* d;
00151     friend class QODBCPrivate;
00152 };
00153 
00154 QT_END_NAMESPACE
00155 
00156 QT_END_HEADER
00157 
00158 #endif // QSQL_ODBC_H