1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtSql module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
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 | #if defined (Q_OS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3)
|
---|
53 | // assume we use iodbc on MACX
|
---|
54 | // comment next line out if you use a
|
---|
55 | // unicode compatible manager
|
---|
56 | # define Q_ODBC_VERSION_2
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | #ifdef QT_PLUGIN
|
---|
60 | #define Q_EXPORT_SQLDRIVER_ODBC
|
---|
61 | #else
|
---|
62 | #define Q_EXPORT_SQLDRIVER_ODBC Q_SQL_EXPORT
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | #ifdef Q_OS_UNIX
|
---|
66 | #define HAVE_LONG_LONG 1 // force UnixODBC NOT to fall back to a struct for BIGINTs
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | #if defined(Q_CC_BOR)
|
---|
70 | // workaround for Borland to make sure that SQLBIGINT is defined
|
---|
71 | # define _MSC_VER 900
|
---|
72 | #endif
|
---|
73 | #include <sql.h>
|
---|
74 | #if defined(Q_CC_BOR)
|
---|
75 | # undef _MSC_VER
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | #ifndef Q_ODBC_VERSION_2
|
---|
79 | #include <sqlucode.h>
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | #include <sqlext.h>
|
---|
83 |
|
---|
84 | QT_BEGIN_HEADER
|
---|
85 |
|
---|
86 | QT_BEGIN_NAMESPACE
|
---|
87 |
|
---|
88 | class QODBCPrivate;
|
---|
89 | class QODBCDriverPrivate;
|
---|
90 | class QODBCDriver;
|
---|
91 | class QSqlRecordInfo;
|
---|
92 |
|
---|
93 | class QODBCResult : public QSqlResult
|
---|
94 | {
|
---|
95 | public:
|
---|
96 | QODBCResult(const QODBCDriver * db, QODBCDriverPrivate* p);
|
---|
97 | virtual ~QODBCResult();
|
---|
98 |
|
---|
99 | bool prepare(const QString& query);
|
---|
100 | bool exec();
|
---|
101 |
|
---|
102 | QVariant handle() const;
|
---|
103 |
|
---|
104 | protected:
|
---|
105 | bool fetchNext();
|
---|
106 | bool fetchFirst();
|
---|
107 | bool fetchLast();
|
---|
108 | bool fetchPrevious();
|
---|
109 | bool fetch(int i);
|
---|
110 | bool reset (const QString& query);
|
---|
111 | QVariant data(int field);
|
---|
112 | bool isNull(int field);
|
---|
113 | int size();
|
---|
114 | int numRowsAffected();
|
---|
115 | QSqlRecord record() const;
|
---|
116 | void virtual_hook(int id, void *data);
|
---|
117 | bool nextResult();
|
---|
118 |
|
---|
119 | private:
|
---|
120 | QODBCPrivate *d;
|
---|
121 | };
|
---|
122 |
|
---|
123 | class Q_EXPORT_SQLDRIVER_ODBC QODBCDriver : public QSqlDriver
|
---|
124 | {
|
---|
125 | Q_OBJECT
|
---|
126 | public:
|
---|
127 | explicit QODBCDriver(QObject *parent=0);
|
---|
128 | QODBCDriver(SQLHANDLE env, SQLHANDLE con, QObject * parent=0);
|
---|
129 | virtual ~QODBCDriver();
|
---|
130 | bool hasFeature(DriverFeature f) const;
|
---|
131 | void close();
|
---|
132 | QSqlResult *createResult() const;
|
---|
133 | QStringList tables(QSql::TableType) const;
|
---|
134 | QSqlRecord record(const QString& tablename) const;
|
---|
135 | QSqlIndex primaryIndex(const QString& tablename) const;
|
---|
136 | QVariant handle() const;
|
---|
137 | QString formatValue(const QSqlField &field,
|
---|
138 | bool trimStrings) const;
|
---|
139 | bool open(const QString& db,
|
---|
140 | const QString& user,
|
---|
141 | const QString& password,
|
---|
142 | const QString& host,
|
---|
143 | int port,
|
---|
144 | const QString& connOpts);
|
---|
145 |
|
---|
146 | QString escapeIdentifier(const QString &identifier, IdentifierType type) const;
|
---|
147 |
|
---|
148 | protected:
|
---|
149 | bool beginTransaction();
|
---|
150 | bool commitTransaction();
|
---|
151 | bool rollbackTransaction();
|
---|
152 | private:
|
---|
153 | void init();
|
---|
154 | bool endTrans();
|
---|
155 | void cleanup();
|
---|
156 | QODBCDriverPrivate* d;
|
---|
157 | friend class QODBCPrivate;
|
---|
158 | };
|
---|
159 |
|
---|
160 | QT_END_NAMESPACE
|
---|
161 |
|
---|
162 | QT_END_HEADER
|
---|
163 |
|
---|
164 | #endif // QSQL_ODBC_H
|
---|