|
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_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 virtual void setForwardOnly(bool forward); |
|
104 |
|
105 protected: |
|
106 bool fetchNext(); |
|
107 bool fetchFirst(); |
|
108 bool fetchLast(); |
|
109 bool fetchPrevious(); |
|
110 bool fetch(int i); |
|
111 bool reset (const QString& query); |
|
112 QVariant data(int field); |
|
113 bool isNull(int field); |
|
114 int size(); |
|
115 int numRowsAffected(); |
|
116 QSqlRecord record() const; |
|
117 void virtual_hook(int id, void *data); |
|
118 bool nextResult(); |
|
119 |
|
120 private: |
|
121 QODBCPrivate *d; |
|
122 }; |
|
123 |
|
124 class Q_EXPORT_SQLDRIVER_ODBC QODBCDriver : public QSqlDriver |
|
125 { |
|
126 Q_OBJECT |
|
127 public: |
|
128 explicit QODBCDriver(QObject *parent=0); |
|
129 QODBCDriver(SQLHANDLE env, SQLHANDLE con, QObject * parent=0); |
|
130 virtual ~QODBCDriver(); |
|
131 bool hasFeature(DriverFeature f) const; |
|
132 void close(); |
|
133 QSqlResult *createResult() const; |
|
134 QStringList tables(QSql::TableType) const; |
|
135 QSqlRecord record(const QString& tablename) const; |
|
136 QSqlIndex primaryIndex(const QString& tablename) const; |
|
137 QVariant handle() const; |
|
138 QString formatValue(const QSqlField &field, |
|
139 bool trimStrings) const; |
|
140 bool open(const QString& db, |
|
141 const QString& user, |
|
142 const QString& password, |
|
143 const QString& host, |
|
144 int port, |
|
145 const QString& connOpts); |
|
146 |
|
147 QString escapeIdentifier(const QString &identifier, IdentifierType type) const; |
|
148 |
|
149 protected Q_SLOTS: |
|
150 bool isIdentifierEscapedImplementation(const QString &identifier, IdentifierType type) const; |
|
151 |
|
152 protected: |
|
153 bool beginTransaction(); |
|
154 bool commitTransaction(); |
|
155 bool rollbackTransaction(); |
|
156 |
|
157 private: |
|
158 void init(); |
|
159 bool endTrans(); |
|
160 void cleanup(); |
|
161 QODBCDriverPrivate* d; |
|
162 friend class QODBCPrivate; |
|
163 }; |
|
164 |
|
165 QT_END_NAMESPACE |
|
166 |
|
167 QT_END_HEADER |
|
168 |
|
169 #endif // QSQL_ODBC_H |