home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qsqldatabase.h < prev    next >
C/C++ Source or Header  |  2001-08-10  |  5KB  |  139 lines

  1. /****************************************************************************
  2. **
  3. ** Definition of QSqlDatabase class
  4. **
  5. ** Created : 2000-11-03
  6. **
  7. ** Copyright (C) 2000 Trolltech AS.  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 AS 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 QSQLDATABASE_H
  38. #define QSQLDATABASE_H
  39.  
  40. #ifndef QT_H
  41. #include "qobject.h"
  42. #include "qstring.h"
  43. #include "qsqlquery.h"
  44. #include "qstringlist.h"
  45. #endif // QT_H
  46.  
  47. #if !defined( QT_MODULE_SQL ) || defined( QT_LICENSE_PROFESSIONAL )
  48. #define QM_EXPORT_SQL
  49. #else
  50. #define QM_EXPORT_SQL Q_EXPORT
  51. #endif
  52.  
  53. #ifndef QT_NO_SQL
  54.  
  55. class QSqlError;
  56. class QSqlDriver;
  57. class QSqlIndex;
  58. class QSqlRecord;
  59. class QSqlRecordInfo;
  60. class QSqlDatabasePrivate;
  61.  
  62. class QM_EXPORT_SQL QSqlDriverCreatorBase
  63. {
  64. public:
  65.     virtual QSqlDriver* createObject() = 0;
  66. };
  67.  
  68. template <class type>
  69. class QM_EXPORT_SQL QSqlDriverCreator: public QSqlDriverCreatorBase
  70. {
  71. public:
  72.     QSqlDriver* createObject() { return new type; }
  73. };
  74.  
  75. class QM_EXPORT_SQL QSqlDatabase : public QObject
  76. {
  77.     Q_OBJECT
  78.     Q_PROPERTY( QString databaseName  READ databaseName WRITE setDatabaseName )
  79.     Q_PROPERTY( QString userName  READ userName WRITE setUserName )
  80.     Q_PROPERTY( QString password  READ password WRITE setPassword )
  81.     Q_PROPERTY( QString hostName  READ hostName WRITE setHostName )
  82.     Q_PROPERTY( int port READ port WRITE setPort )
  83.  
  84. public:
  85.     ~QSqlDatabase();
  86.  
  87.     bool        open();
  88.     bool        open( const QString& user, const QString& password );
  89.     void        close();
  90.     bool        isOpen() const;
  91.     bool        isOpenError() const;
  92.     QStringList        tables() const;
  93.     QSqlIndex        primaryIndex( const QString& tablename ) const;
  94.     QSqlRecord        record( const QString& tablename ) const;
  95.     QSqlRecord        record( const QSqlQuery& query ) const;
  96.     QSqlRecordInfo    recordInfo( const QString& tablename ) const;
  97.     QSqlRecordInfo    recordInfo( const QSqlQuery& query ) const;
  98.     QSqlQuery        exec( const QString& query = QString::null ) const;
  99.     QSqlError        lastError() const;
  100.  
  101.     bool        transaction();
  102.     bool        commit();
  103.     bool        rollback();
  104.  
  105.     virtual void    setDatabaseName( const QString& name );
  106.     virtual void    setUserName( const QString& name );
  107.     virtual void    setPassword( const QString& password );
  108.     virtual void    setHostName( const QString& host );
  109.     virtual void    setPort( int p );
  110.     QString        databaseName() const;
  111.     QString        userName() const;
  112.     QString        password() const;
  113.     QString        hostName() const;
  114.     QString        driverName() const;
  115.     int             port() const;
  116.  
  117.     QSqlDriver*        driver() const;
  118.  
  119.     // MOC_SKIP_BEGIN
  120.     QT_STATIC_CONST char * const defaultConnection;
  121.     // MOC_SKIP_END
  122.  
  123.     static QSqlDatabase* addDatabase( const QString& type, const QString& connectionName = defaultConnection );
  124.     static QSqlDatabase* database( const QString& connectionName = defaultConnection, bool open = TRUE );
  125.     static void          removeDatabase( const QString& connectionName );
  126.     static bool          contains( const QString& connectionName = defaultConnection );
  127.     static QStringList   drivers();
  128.     static void          registerSqlDriver( const QString& name, const QSqlDriverCreatorBase* dcb );
  129.  
  130. protected:
  131.     QSqlDatabase( const QString& type, const QString& name, QObject * parent=0, const char * objname=0 );
  132. private:
  133.     void    init( const QString& type, const QString& name );
  134.     QSqlDatabasePrivate* d;
  135. };
  136.  
  137. #endif // QT_NO_SQL
  138. #endif
  139.