1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtSql module of the Qt Toolkit. 7 ** 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 The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 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 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 #ifndef QSQL_ODBC_H 43 #define QSQL_ODBC_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 #ifdef QT_PLUGIN 53 #define Q_EXPORT_SQLDRIVER_ODBC 54 #else 55 #define Q_EXPORT_SQLDRIVER_ODBC Q_SQL_EXPORT 56 #endif 57 58 #ifdef Q_OS_UNIX 59 #define HAVE_LONG_LONG 1 // force UnixODBC NOT to fall back to a struct for BIGINTs 60 #endif 61 62 #if defined(Q_CC_BOR) 63 // workaround for Borland to make sure that SQLBIGINT is defined 64 # define _MSC_VER 900 65 #endif 66 #include <sql.h> 67 #if defined(Q_CC_BOR) 68 # undef _MSC_VER 69 #endif 70 71 #include <sqlext.h> 72 73 QT_BEGIN_HEADER 74 75 QT_BEGIN_NAMESPACE 76 77 class QODBCPrivate; 78 class QODBCDriverPrivate; 79 class QODBCDriver; 80 class QSqlRecordInfo; 81 82 class QODBCResult : public QSqlResult 83 { 84 public: 85 QODBCResult(const QODBCDriver * db, QODBCDriverPrivate* p); 86 virtual ~QODBCResult(); 87 88 bool prepare(const QString& query); 89 bool exec(); 90 91 QVariant handle() const; 92 virtual void setForwardOnly(bool forward); 93 94 protected: 95 bool fetchNext(); 96 bool fetchFirst(); 97 bool fetchLast(); 98 bool fetchPrevious(); 99 bool fetch(int i); 100 bool reset (const QString& query); 101 QVariant data(int field); 102 bool isNull(int field); 103 int size(); 104 int numRowsAffected(); 105 QSqlRecord record() const; 106 void virtual_hook(int id, void *data); 107 bool nextResult(); 108 109 private: 110 QODBCPrivate *d; 111 }; 112 113 class Q_EXPORT_SQLDRIVER_ODBC QODBCDriver : public QSqlDriver 114 { 115 Q_OBJECT 116 public: 117 explicit QODBCDriver(QObject *parent=0); 118 QODBCDriver(SQLHANDLE env, SQLHANDLE con, QObject * parent=0); 119 virtual ~QODBCDriver(); 120 bool hasFeature(DriverFeature f) const; 121 void close(); 122 QSqlResult *createResult() const; 123 QStringList tables(QSql::TableType) const; 124 QSqlRecord record(const QString& tablename) const; 125 QSqlIndex primaryIndex(const QString& tablename) const; 126 QVariant handle() const; 127 QString formatValue(const QSqlField &field, 128 bool trimStrings) const; 129 bool open(const QString& db, 130 const QString& user, 131 const QString& password, 132 const QString& host, 133 int port, 134 const QString& connOpts); 135 136 QString escapeIdentifier(const QString &identifier, IdentifierType type) const; 137 138 protected Q_SLOTS: 139 bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const; 140 141 protected: 142 bool beginTransaction(); 143 bool commitTransaction(); 144 bool rollbackTransaction(); 145 146 private: 147 void init(); 148 bool endTrans(); 149 void cleanup(); 150 QODBCDriverPrivate* d; 151 friend class QODBCPrivate; 152 }; 153 154 QT_END_NAMESPACE 155 156 QT_END_HEADER 157 158 #endif // QSQL_ODBC_H 159