Eneboo - Documentación para desarrolladores
src/plugins/sqldrivers/mysql/flsql_mysql.h
Ir a la documentación de este archivo.
00001 /***************************************************************************
00002                       flsql_mysql.h  -  description
00003                             -------------------
00004    begin                : lun ago 23 2004
00005    copyright            : (C) 2004-2005 by InfoSiAL, S.L.
00006    email                : mail@infosial.com
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 /****************************************************************************
00018 **
00019 ** Definition of MySQL driver classes
00020 **
00021 ** Created : 001103
00022 **
00023 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00024 **
00025 ** This file is part of the sql module of the Qt GUI Toolkit.
00026 **
00027 ** This file may be distributed under the terms of the Q Public License
00028 ** as defined by Trolltech AS of Norway and appearing in the file
00029 ** LICENSE.QPL included in the packaging of this file.
00030 **
00031 ** This file may be distributed and/or modified under the terms of the
00032 ** GNU General Public License version 2 as published by the Free Software
00033 ** Foundation and appearing in the file LICENSE.GPL included in the
00034 ** packaging of this file.
00035 **
00036 ** Licensees holding valid Qt Enterprise Edition licenses may use this
00037 ** file in accordance with the Qt Commercial License Agreement provided
00038 ** with the Software.
00039 **
00040 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00041 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00042 **
00043 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00044 **   information about Qt Commercial License Agreements.
00045 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00046 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00047 **
00048 ** Contact info@trolltech.com if any conditions of this licensing are
00049 ** not clear to you.
00050 **
00051 **********************************************************************/
00052 
00053 #ifndef QSQL_MYSQL_H
00054 #define QSQL_MYSQL_H
00055 
00056 #include <qsqldriver.h>
00057 #include <qsqlresult.h>
00058 #include <qsqlfield.h>
00059 #include <qsqlindex.h>
00060 #include <qmessagebox.h>
00061 #include <qptrvector.h>
00062 #include <FLManager.h>
00063 #include <FLManagerModules.h>
00064 #include <FLTableMetaData.h>
00065 #include <FLFieldMetaData.h>
00066 #include <FLSqlDatabase.h>
00067 #include <FLSqlDriver.h>
00068 #include <FLSqlCursor.h>
00069 #include <FLUtil.h>
00070 #include <FLDiskCache.h>
00071 
00072 #if defined (Q_OS_WIN32)
00073 #include <qt_windows.h>
00074 #endif
00075 
00076 #include <mysql.h>
00077 
00078 #ifdef QT_PLUGIN
00079 #define Q_EXPORT_SQLDRIVER_MYSQL
00080 #else
00081 #define Q_EXPORT_SQLDRIVER_MYSQL Q_EXPORT
00082 #endif
00083 
00084 class QMYSQLDriverPrivate;
00085 class QMYSQLResultPrivate;
00086 class QMYSQLDriver;
00087 class QSqlRecordInfo;
00088 
00089 class Q_EXPORT_SQLDRIVER_MYSQL QMYSQLDriver : public FLSqlDriver
00090 {
00091 
00092     Q_OBJECT
00093 
00094     friend class QMYSQLResult;
00095 
00096 public:
00097 
00098     enum MySQLVersion {
00099         Version4 = 4,
00100         Version5 = 5
00101     };
00102 
00103     QMYSQLDriver( QObject * parent = 0, const char * name = 0 );
00104     QMYSQLDriver( MYSQL * con, QObject * parent = 0, const char * name = 0 );
00105     ~QMYSQLDriver();
00106     bool hasFeature( DriverFeature f ) const;
00107     bool open( const QString & db, const QString & user = QString::null,
00108                const QString & password = QString::null, const QString & host = QString::null, int port = -1 );
00109     void close();
00110     QSqlQuery createQuery() const;
00111     QStringList tables( const QString & user ) const;
00112     QSqlIndex primaryIndex( const QString & tablename ) const;
00113     QSqlRecord record( const QString & tablename ) const;
00114     QSqlRecord record( const QSqlQuery & query ) const;
00115     QSqlRecordInfo recordInfo( const QString & tablename ) const;
00116     QSqlRecordInfo recordInfo( const QSqlQuery & query ) const;
00117     QString formatValue( const QSqlField * field, bool trimStrings ) const;
00118     MYSQL * mysql();
00119     // ### remove me for 4.0
00120     bool open( const QString& db, const QString& user, const QString& password,
00121                const QString& host, int port, const QString& connOpts );
00122 
00123     bool tryConnect( const QString & db, const QString & user = QString::null,
00124                      const QString & password = QString::null, const QString & host = QString::null, int port = -1 );
00125     QString sqlCreateTable( FLTableMetaData * tmd );
00126     QString formatValueLike( int t, const QVariant & v, const bool upper = false );
00127     QString formatValue( int t, const QVariant & v, const bool upper = false );
00128     QVariant nextSerialVal( const QString & table, const QString & field );
00129     int atFrom( FLSqlCursor * cur );
00130     bool alterTable( const QString & mtd1, const QString & mtd2, const QString & key = QString::null );
00131     bool canSavePoint();
00132     bool savePoint( const QString & n );
00133     bool releaseSavePoint( const QString & n );
00134     bool rollbackSavePoint( const QString & n );
00135     MySQLVersion version() const;
00136 
00137 private slots:
00138 
00139     void Mr_Proper();
00140 
00141 protected:
00142 
00143     bool beginTransaction();
00144     bool commitTransaction();
00145     bool rollbackTransaction();
00146 
00147 private:
00148 
00149     QSqlIndex primaryIndex2( const QString& tablename ) const;
00150     QSqlRecord record2( const QString& tablename ) const;
00151     QSqlRecordInfo recordInfo2( const QString& tablename ) const;
00152     bool alterTable2( const QString & mtd1, const QString & mtd2,
00153                       const QString & key = QString::null, bool force = false );
00154 #ifndef FL_QUICK_CLIENT
00155     void createIndex( const QString & fieldName, const QString & tableName ) const;
00156     static QDict < bool > * dictIndexes;
00157 #endif
00158 
00159     void init();
00160     MySQLVersion version_;
00161     QMYSQLDriverPrivate* d;
00162 
00163     bool existsDatabase( const QString & db, const QString & user,
00164                          const QString & password, const QString & host, int port );
00165 
00166     int insertMulti( const QString & tablename, QPtrList<QSqlRecord> * records );
00167 };
00168 
00169 class QMYSQLResult : public QSqlResult
00170 {
00171     friend class QMYSQLDriver;
00172 
00173 public:
00174 
00175     QMYSQLResult( const QMYSQLDriver * db );
00176     ~QMYSQLResult();
00177     MYSQL_RES * result();
00178 
00179 protected:
00180 
00181     void cleanup();
00182     bool fetch( int i );
00183     bool fetchNext();
00184     bool fetchLast();
00185     bool fetchFirst();
00186     QVariant data( int field );
00187     bool isNull( int field );
00188     bool reset( const QString & query );
00189     int size();
00190     int numRowsAffected();
00191 
00192 private:
00193 
00194     my_ulonglong calcSize();
00195     bool fetchF( int i );
00196     bool fetchNextF();
00197     bool resetF( const QString & query );
00198     bool nextResult( int i );
00199     void cleanupCache();
00200     QMYSQLDriver::MySQLVersion version_;
00201     QMYSQLResultPrivate* d;
00202 };
00203 
00204 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'