source: trunk/src/sql/drivers/odbc/qsql_odbc.h

Last change on this file was 196, checked in by rudi, 14 years ago

Add SQL module (currently it isn't build by default, however it's needed for QtDesigner)

File size: 4.6 KB
Line 
1/****************************************************************************
2**
3** Definition of ODBC driver classes
4**
5** Created : 001103
6**
7** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
8**
9** This file is part of the sql module of the Qt GUI Toolkit.
10**
11** This file may be distributed under the terms of the Q Public License
12** as defined by Trolltech ASA of Norway and appearing in the file
13** LICENSE.QPL included in the packaging of this file.
14**
15** This file may be distributed and/or modified under the terms of the
16** GNU General Public License version 2 as published by the Free Software
17** Foundation and appearing in the file LICENSE.GPL included in the
18** packaging of this file.
19**
20** Licensees holding valid Qt Enterprise Edition licenses may use this
21** file in accordance with the Qt Commercial License Agreement provided
22** with the Software.
23**
24** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26**
27** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
28** information about Qt Commercial License Agreements.
29** See http://www.trolltech.com/qpl/ for QPL licensing information.
30** See http://www.trolltech.com/gpl/ for GPL licensing information.
31**
32** Contact info@trolltech.com if any conditions of this licensing are
33** not clear to you.
34**
35**********************************************************************/
36
37#ifndef QSQL_ODBC_H
38#define QSQL_ODBC_H
39
40#include <qmap.h>
41#include <qstring.h>
42#include <qsqldriver.h>
43#include <qsqlfield.h>
44#include <qsqlresult.h>
45#include <qsqlindex.h>
46
47#if defined (Q_OS_WIN32) || defined(Q_OS_CYGWIN)
48#include <qt_windows.h>
49#endif
50
51#if defined (Q_OS_MAC)
52// assume we use iodbc on MAC
53// comment next line out if you use a
54// unicode compatible manager
55# define Q_ODBC_VERSION_2
56#endif
57
58#ifdef QT_PLUGIN
59#define Q_EXPORT_SQLDRIVER_ODBC
60#else
61#define Q_EXPORT_SQLDRIVER_ODBC Q_EXPORT
62#endif
63
64#ifdef Q_OS_UNIX
65#define HAVE_LONG_LONG 1 // force UnixODBC NOT to fall back to a struct for BIGINTs
66#endif
67
68#if defined(Q_CC_BOR)
69// workaround for Borland to make sure that SQLBIGINT is defined
70# define _MSC_VER 900
71#endif
72#include <sql.h>
73#if defined(Q_CC_BOR)
74# undef _MSC_VER
75#endif
76
77#ifndef Q_ODBC_VERSION_2
78#include <sqlucode.h>
79#endif
80
81#include <sqlext.h>
82
83class QODBCPrivate;
84class QODBCDriver;
85class QSqlRecordInfo;
86
87class QODBCResult : public QSqlResult
88{
89 friend class QODBCDriver;
90public:
91 QODBCResult( const QODBCDriver * db, QODBCPrivate* p );
92 ~QODBCResult();
93
94 SQLHANDLE statement();
95 bool prepare( const QString& query );
96 bool exec();
97
98protected:
99 bool fetchNext();
100 bool fetchFirst();
101 bool fetchLast();
102 bool fetchPrior();
103 bool fetch(int i);
104 bool reset ( const QString& query );
105 QVariant data( int field );
106 bool isNull( int field );
107 int size();
108 int numRowsAffected();
109private:
110 QODBCPrivate* d;
111 typedef QMap<int,QVariant> FieldCache;
112 FieldCache fieldCache;
113 typedef QMap<int,bool> NullCache;
114 NullCache nullCache;
115};
116
117class Q_EXPORT_SQLDRIVER_ODBC QODBCDriver : public QSqlDriver
118{
119public:
120 QODBCDriver( QObject * parent=0, const char * name=0 );
121 QODBCDriver( SQLHANDLE env, SQLHANDLE con, QObject * parent=0, const char * name=0 );
122 ~QODBCDriver();
123 bool hasFeature( DriverFeature f ) const;
124 bool open( const QString & db,
125 const QString & user = QString::null,
126 const QString & password = QString::null,
127 const QString & host = QString::null,
128 int port = -1 );
129 void close();
130 QSqlQuery createQuery() const;
131 QStringList tables( const QString& user ) const;
132 QSqlRecord record( const QString& tablename ) const;
133 QSqlRecord record( const QSqlQuery& query ) const;
134 QSqlRecordInfo recordInfo( const QString& tablename ) const;
135 QSqlRecordInfo recordInfo( const QSqlQuery& query ) const;
136 QSqlIndex primaryIndex( const QString& tablename ) const;
137 SQLHANDLE environment();
138 SQLHANDLE connection();
139
140 QString formatValue( const QSqlField* field,
141 bool trimStrings ) const;
142 // ### remove me for 4.0
143 bool open( const QString& db,
144 const QString& user,
145 const QString& password,
146 const QString& host,
147 int port,
148 const QString& connOpts );
149
150protected:
151 bool beginTransaction();
152 bool commitTransaction();
153 bool rollbackTransaction();
154private:
155 void init();
156 bool endTrans();
157 void cleanup();
158 QODBCPrivate* d;
159};
160
161#endif
Note: See TracBrowser for help on using the repository browser.