Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** 00003 ** Definition of ODBC driver classes 00004 ** 00005 ** Created : 001103 00006 ** 00007 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00008 ** 00009 ** This file is part of the sql module of the Qt GUI Toolkit. 00010 ** 00011 ** This file may be distributed under the terms of the Q Public License 00012 ** as defined by Trolltech ASA of Norway and appearing in the file 00013 ** LICENSE.QPL included in the packaging of this file. 00014 ** 00015 ** This file may be distributed and/or modified under the terms of the 00016 ** GNU General Public License version 2 as published by the Free Software 00017 ** Foundation and appearing in the file LICENSE.GPL included in the 00018 ** packaging of this file. 00019 ** 00020 ** Licensees holding valid Qt Enterprise Edition licenses may use this 00021 ** file in accordance with the Qt Commercial License Agreement provided 00022 ** with the Software. 00023 ** 00024 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00025 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00026 ** 00027 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00028 ** information about Qt Commercial License Agreements. 00029 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00030 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00031 ** 00032 ** Contact info@trolltech.com if any conditions of this licensing are 00033 ** not clear to you. 00034 ** 00035 **********************************************************************/ 00036 00037 #ifndef QSQL_ODBC_H 00038 #define QSQL_ODBC_H 00039 00040 #include <qmap.h> 00041 #include <qstring.h> 00042 #include <qsqldriver.h> 00043 #include <qsqlfield.h> 00044 #include <qsqlresult.h> 00045 #include <qsqlindex.h> 00046 00047 #if defined (Q_OS_WIN32) 00048 #include <qt_windows.h> 00049 #endif 00050 00051 #if defined (Q_OS_MAC) 00052 // assume we use iodbc on MAC 00053 // comment next line out if you use a 00054 // unicode compatible manager 00055 # define Q_ODBC_VERSION_2 00056 #endif 00057 00058 #ifdef QT_PLUGIN 00059 #define Q_EXPORT_SQLDRIVER_ODBC 00060 #else 00061 #define Q_EXPORT_SQLDRIVER_ODBC Q_EXPORT 00062 #endif 00063 00064 #ifdef Q_OS_UNIX 00065 #define HAVE_LONG_LONG 1 // force UnixODBC NOT to fall back to a struct for BIGINTs 00066 #endif 00067 00068 #if defined(Q_CC_BOR) 00069 // workaround for Borland to make sure that SQLBIGINT is defined 00070 # define _MSC_VER 900 00071 #endif 00072 #include <sql.h> 00073 #if defined(Q_CC_BOR) 00074 # undef _MSC_VER 00075 #endif 00076 00077 #ifndef Q_ODBC_VERSION_2 00078 #include <sqlucode.h> 00079 #endif 00080 00081 #include <sqlext.h> 00082 00083 class QODBCPrivate; 00084 class QODBCDriver; 00085 class QSqlRecordInfo; 00086 00087 class QODBCResult : public QSqlResult 00088 { 00089 friend class QODBCDriver; 00090 public: 00091 QODBCResult( const QODBCDriver * db, QODBCPrivate* p ); 00092 ~QODBCResult(); 00093 00094 SQLHANDLE statement(); 00095 bool prepare( const QString& query ); 00096 bool exec(); 00097 00098 protected: 00099 bool fetchNext(); 00100 bool fetchFirst(); 00101 bool fetchLast(); 00102 bool fetchPrior(); 00103 bool fetch(int i); 00104 bool reset ( const QString& query ); 00105 QVariant data( int field ); 00106 bool isNull( int field ); 00107 int size(); 00108 int numRowsAffected(); 00109 private: 00110 QODBCPrivate* d; 00111 typedef QMap<int,QVariant> FieldCache; 00112 FieldCache fieldCache; 00113 typedef QMap<int,bool> NullCache; 00114 NullCache nullCache; 00115 }; 00116 00117 class Q_EXPORT_SQLDRIVER_ODBC QODBCDriver : public QSqlDriver 00118 { 00119 public: 00120 QODBCDriver( QObject * parent=0, const char * name=0 ); 00121 QODBCDriver( SQLHANDLE env, SQLHANDLE con, QObject * parent=0, const char * name=0 ); 00122 ~QODBCDriver(); 00123 bool hasFeature( DriverFeature f ) const; 00124 bool open( const QString & db, 00125 const QString & user = QString::null, 00126 const QString & password = QString::null, 00127 const QString & host = QString::null, 00128 int port = -1 ); 00129 void close(); 00130 QSqlQuery createQuery() const; 00131 QStringList tables( const QString& user ) const; 00132 QSqlRecord record( const QString& tablename ) const; 00133 QSqlRecord record( const QSqlQuery& query ) const; 00134 QSqlRecordInfo recordInfo( const QString& tablename ) const; 00135 QSqlRecordInfo recordInfo( const QSqlQuery& query ) const; 00136 QSqlIndex primaryIndex( const QString& tablename ) const; 00137 SQLHANDLE environment(); 00138 SQLHANDLE connection(); 00139 00140 QString formatValue( const QSqlField* field, 00141 bool trimStrings ) const; 00142 // ### remove me for 4.0 00143 bool open( const QString& db, 00144 const QString& user, 00145 const QString& password, 00146 const QString& host, 00147 int port, 00148 const QString& connOpts ); 00149 00150 protected: 00151 bool beginTransaction(); 00152 bool commitTransaction(); 00153 bool rollbackTransaction(); 00154 private: 00155 void init(); 00156 bool endTrans(); 00157 void cleanup(); 00158 QODBCPrivate* d; 00159 }; 00160 00161 #endif