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

  1. /****************************************************************************
  2. **
  3. ** Definition of QSqlCursor 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 QSQLCURSOR_H
  38. #define QSQLCURSOR_H
  39.  
  40. #ifndef QT_H
  41. #include "qsqlrecord.h"
  42. #include "qstringlist.h"
  43. #include "qsqlquery.h"
  44. #include "qsqlindex.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 QSqlDatabase;
  56. class QSqlCursorPrivate;
  57.  
  58. class QM_EXPORT_SQL QSqlCursor : public QSqlRecord, public QSqlQuery
  59. {
  60. public:
  61.     QSqlCursor( const QString & name = QString::null, bool autopopulate = TRUE, QSqlDatabase* db = 0 );
  62.     QSqlCursor( const QSqlCursor & other );
  63.     QSqlCursor& operator=( const QSqlCursor& other );
  64.     ~QSqlCursor();
  65.  
  66.     enum Mode {
  67.     ReadOnly = 0,
  68.     Insert = 1,
  69.     Update = 2,
  70.     Delete = 4,
  71.     Writable = 7
  72.     };
  73.  
  74.     QVariant        value( int i ) const;
  75.     QVariant        value( const QString& name ) const;
  76.     virtual QSqlIndex    primaryIndex( bool prime = TRUE ) const;
  77.     virtual QSqlIndex    index( const QStringList& fieldNames ) const;
  78.     QSqlIndex        index( const QString& fieldName ) const;
  79.     QSqlIndex        index( const char* fieldName ) const;
  80.     virtual void    setPrimaryIndex( const QSqlIndex& idx );
  81.  
  82.     virtual void    append( const QSqlFieldInfo& fieldInfo );
  83.     virtual void    insert( int pos, const QSqlFieldInfo& fieldInfo );
  84.     void        remove( int pos );
  85.     void        clear();
  86.     void        setGenerated( const QString& name, bool generated );
  87.     void        setGenerated( int i, bool generated );
  88.  
  89.     virtual QSqlRecord*    editBuffer( bool copy = FALSE );
  90.     virtual QSqlRecord*    primeInsert();
  91.     virtual QSqlRecord*    primeUpdate();
  92.     virtual QSqlRecord*    primeDelete();
  93.     virtual int        insert( bool invalidate = TRUE );
  94.     virtual int        update( bool invalidate = TRUE );
  95.     virtual int        del( bool invalidate = TRUE );
  96.  
  97.     virtual void    setMode( int flags );
  98.     int            mode() const;
  99.     virtual void    setCalculated( const QString& name, bool calculated );
  100.     bool        isCalculated( const QString& name ) const;
  101.     virtual void    setTrimmed( const QString& name, bool trim );
  102.     bool        isTrimmed( const QString& name ) const;
  103.  
  104.     bool        isReadOnly() const;
  105.     bool        canInsert() const;
  106.     bool        canUpdate() const;
  107.     bool        canDelete() const;
  108.  
  109.     bool        select();
  110.     bool        select( const QSqlIndex& sort );
  111.     bool        select( const QSqlIndex & filter, const QSqlIndex & sort );
  112.     virtual bool    select( const QString & filter, const QSqlIndex & sort = QSqlIndex() );
  113.  
  114.     virtual void    setSort( const QSqlIndex& sort );
  115.     QSqlIndex        sort() const;
  116.     virtual void    setFilter( const QString& filter );
  117.     QString        filter() const;
  118.     virtual void    setName( const QString& name, bool autopopulate = TRUE );
  119.     QString        name() const;
  120.     QString        toString( const QString& prefix = QString::null,
  121.                 const QString& sep = "," ) const;
  122.  
  123. protected:
  124.     void        afterSeek();
  125.     bool        exec( const QString & sql );
  126.  
  127.     virtual QVariant    calculateField( const QString& name );
  128.     virtual int        update( const QString & filter, bool invalidate = TRUE );
  129.     virtual int        del( const QString & filter, bool invalidate = TRUE );
  130.  
  131.     virtual QString    toString( const QString& prefix, QSqlField* field, const QString& fieldSep ) const;
  132.     virtual QString    toString( QSqlRecord* rec, const QString& prefix, const QString& fieldSep,
  133.                 const QString& sep ) const;
  134.     virtual QString    toString( const QSqlIndex& i, QSqlRecord* rec, const QString& prefix,
  135.                 const QString& fieldSep, const QString& sep ) const;
  136.  
  137. private:
  138.     void        sync();
  139.     int            apply( const QString& q, bool invalidate );
  140.     QSqlRecord&        operator=( const QSqlRecord & list );
  141.     void         append( const QSqlField& field );
  142.     void         insert( int pos, const QSqlField& field );
  143.  
  144.     QSqlCursorPrivate*    d;
  145. };
  146.  
  147.  
  148.  
  149.  
  150. #endif    // QT_NO_SQL
  151. #endif
  152.