Eneboo - Documentación para desarrolladores
src/qt/include/qsqldatabase.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 **
00003 ** Definition of QSqlDatabase class
00004 **
00005 ** Created : 2000-11-03
00006 **
00007 ** Copyright (C) 2005-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 QSQLDATABASE_H
00038 #define QSQLDATABASE_H
00039 
00040 #ifndef QT_H
00041 #include "qobject.h"
00042 #include "qstring.h"
00043 #include "qsqlquery.h"
00044 #include "qstringlist.h"
00045 #endif // QT_H
00046 
00047 #if !defined( QT_MODULE_SQL ) || defined( QT_LICENSE_PROFESSIONAL )
00048 #define QM_EXPORT_SQL
00049 #else
00050 #define QM_EXPORT_SQL Q_EXPORT
00051 #endif
00052 
00053 #ifndef QT_NO_SQL
00054 
00055 class QSqlError;
00056 class QSqlDriver;
00057 class QSqlIndex;
00058 class QSqlRecord;
00059 class QSqlRecordInfo;
00060 class QSqlDatabasePrivate;
00061 
00062 class QM_EXPORT_SQL QSqlDriverCreatorBase
00063 {
00064 public:
00065     virtual QSqlDriver* createObject() = 0;
00066 };
00067 
00068 template <class type>
00069 class QM_EXPORT_SQL QSqlDriverCreator: public QSqlDriverCreatorBase
00070 {
00071 public:
00072     QSqlDriver* createObject() { return new type; }
00073 };
00074 
00075 class QM_EXPORT_SQL QSqlDatabase : public QObject
00076 {
00077     Q_OBJECT
00078     Q_PROPERTY( QString databaseName  READ databaseName WRITE setDatabaseName )
00079     Q_PROPERTY( QString userName  READ userName WRITE setUserName )
00080     Q_PROPERTY( QString password  READ password WRITE setPassword )
00081     Q_PROPERTY( QString hostName  READ hostName WRITE setHostName )
00082     Q_PROPERTY( int port READ port WRITE setPort )
00083     Q_PROPERTY( QString connectOptions READ connectOptions WRITE setConnectOptions )
00084 
00085 public:
00086     ~QSqlDatabase();
00087 
00088     bool                open();
00089     bool                open( const QString& user, const QString& password );
00090     void                close();
00091     bool                isOpen() const;
00092     bool                isOpenError() const;
00093     QStringList         tables() const;
00094     QStringList         tables( QSql::TableType type ) const;
00095     QSqlIndex           primaryIndex( const QString& tablename ) const;
00096     QSqlRecord          record( const QString& tablename ) const;
00097     QSqlRecord          record( const QSqlQuery& query ) const;
00098     QSqlRecordInfo      recordInfo( const QString& tablename ) const;
00099     QSqlRecordInfo      recordInfo( const QSqlQuery& query ) const;
00100     QSqlQuery           exec( const QString& query = QString::null ) const;
00101     QSqlError           lastError() const;
00102 
00103     bool                transaction();
00104     bool                commit();
00105     bool                rollback();
00106 
00107     virtual void        setDatabaseName( const QString& name );
00108     virtual void        setUserName( const QString& name );
00109     virtual void        setPassword( const QString& password );
00110     virtual void        setHostName( const QString& host );
00111     virtual void        setPort( int p );
00112     void                setConnectOptions( const QString& options = QString::null );
00113     QString             databaseName() const;
00114     QString             userName() const;
00115     QString             password() const;
00116     QString             hostName() const;
00117     QString             driverName() const;
00118     int                 port() const;
00119     QString             connectOptions() const;
00120 
00121     QSqlDriver*         driver() const;
00122     
00123     // MOC_SKIP_BEGIN
00124     QT_STATIC_CONST char * const defaultConnection;
00125     // MOC_SKIP_END
00126 
00127     static QSqlDatabase* addDatabase( const QString& type, const QString& connectionName = defaultConnection );
00128     static QSqlDatabase* addDatabase( QSqlDriver* driver, const QString& connectionName = defaultConnection );
00129     static QSqlDatabase* database( const QString& connectionName = defaultConnection, bool open = TRUE );
00130     static void          removeDatabase( const QString& connectionName );
00131     static void          removeDatabase( QSqlDatabase* db );
00132     static bool          contains( const QString& connectionName = defaultConnection );
00133     static QStringList   drivers();
00134     static void          registerSqlDriver( const QString& name, const QSqlDriverCreatorBase* creator ); // ### 4.0: creator should not be const
00135     static bool          isDriverAvailable( const QString& name );
00136     
00137 protected:
00138     QSqlDatabase( const QString& type, const QString& name, QObject * parent=0, const char * objname=0 );
00139     QSqlDatabase( QSqlDriver* driver, QObject * parent=0, const char * objname=0 );
00140 private:
00141     void        init( const QString& type, const QString& name );
00142     QSqlDatabasePrivate* d;
00143 #if defined(Q_DISABLE_COPY) // Disabled copy constructor and operator=
00144     QSqlDatabase( const QSqlDatabase & );
00145     QSqlDatabase &operator=( const QSqlDatabase & );
00146 #endif
00147 
00148 };
00149 
00150 #endif // QT_NO_SQL
00151 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'