[196] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Definition of QSqlCursor class
|
---|
| 4 | **
|
---|
| 5 | ** Created : 2000-11-03
|
---|
| 6 | **
|
---|
| 7 | ** Copyright (C) 2005-2007 Trolltech ASA. 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 ASA 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 | void setValue( int i, const QVariant& val );
|
---|
| 77 | void setValue( const QString& name, const QVariant& val );
|
---|
| 78 | virtual QSqlIndex primaryIndex( bool prime = TRUE ) const;
|
---|
| 79 | virtual QSqlIndex index( const QStringList& fieldNames ) const;
|
---|
| 80 | QSqlIndex index( const QString& fieldName ) const;
|
---|
| 81 | QSqlIndex index( const char* fieldName ) const;
|
---|
| 82 | virtual void setPrimaryIndex( const QSqlIndex& idx );
|
---|
| 83 |
|
---|
| 84 | virtual void append( const QSqlFieldInfo& fieldInfo );
|
---|
| 85 | virtual void insert( int pos, const QSqlFieldInfo& fieldInfo );
|
---|
| 86 | void remove( int pos );
|
---|
| 87 | void clear();
|
---|
| 88 | void setGenerated( const QString& name, bool generated );
|
---|
| 89 | void setGenerated( int i, bool generated );
|
---|
| 90 |
|
---|
| 91 | virtual QSqlRecord* editBuffer( bool copy = FALSE );
|
---|
| 92 | virtual QSqlRecord* primeInsert();
|
---|
| 93 | virtual QSqlRecord* primeUpdate();
|
---|
| 94 | virtual QSqlRecord* primeDelete();
|
---|
| 95 | virtual int insert( bool invalidate = TRUE );
|
---|
| 96 | virtual int update( bool invalidate = TRUE );
|
---|
| 97 | virtual int del( bool invalidate = TRUE );
|
---|
| 98 |
|
---|
| 99 | virtual void setMode( int flags );
|
---|
| 100 | int mode() const;
|
---|
| 101 | virtual void setCalculated( const QString& name, bool calculated );
|
---|
| 102 | bool isCalculated( const QString& name ) const;
|
---|
| 103 | virtual void setTrimmed( const QString& name, bool trim );
|
---|
| 104 | bool isTrimmed( const QString& name ) const;
|
---|
| 105 |
|
---|
| 106 | bool isReadOnly() const;
|
---|
| 107 | bool canInsert() const;
|
---|
| 108 | bool canUpdate() const;
|
---|
| 109 | bool canDelete() const;
|
---|
| 110 |
|
---|
| 111 | bool select();
|
---|
| 112 | bool select( const QSqlIndex& sort );
|
---|
| 113 | bool select( const QSqlIndex & filter, const QSqlIndex & sort );
|
---|
| 114 | virtual bool select( const QString & filter, const QSqlIndex & sort = QSqlIndex() );
|
---|
| 115 |
|
---|
| 116 | virtual void setSort( const QSqlIndex& sort );
|
---|
| 117 | QSqlIndex sort() const;
|
---|
| 118 | virtual void setFilter( const QString& filter );
|
---|
| 119 | QString filter() const;
|
---|
| 120 | virtual void setName( const QString& name, bool autopopulate = TRUE );
|
---|
| 121 | QString name() const;
|
---|
| 122 | QString toString( const QString& prefix = QString::null,
|
---|
| 123 | const QString& sep = "," ) const;
|
---|
| 124 | bool isNull( int i ) const;
|
---|
| 125 | bool isNull( const QString& name ) const;
|
---|
| 126 |
|
---|
| 127 | protected:
|
---|
| 128 | void afterSeek();
|
---|
| 129 | bool exec( const QString & sql );
|
---|
| 130 |
|
---|
| 131 | virtual QVariant calculateField( const QString& name );
|
---|
| 132 | virtual int update( const QString & filter, bool invalidate = TRUE );
|
---|
| 133 | virtual int del( const QString & filter, bool invalidate = TRUE );
|
---|
| 134 |
|
---|
| 135 | virtual QString toString( const QString& prefix, QSqlField* field, const QString& fieldSep ) const;
|
---|
| 136 | virtual QString toString( QSqlRecord* rec, const QString& prefix, const QString& fieldSep,
|
---|
| 137 | const QString& sep ) const;
|
---|
| 138 | virtual QString toString( const QSqlIndex& i, QSqlRecord* rec, const QString& prefix,
|
---|
| 139 | const QString& fieldSep, const QString& sep ) const;
|
---|
| 140 |
|
---|
| 141 | private:
|
---|
| 142 | void sync();
|
---|
| 143 | int apply( const QString& q, bool invalidate );
|
---|
| 144 | int applyPrepared( const QString& q, bool invalidate );
|
---|
| 145 | QSqlRecord& operator=( const QSqlRecord & list );
|
---|
| 146 | void append( const QSqlField& field );
|
---|
| 147 | void insert( int pos, const QSqlField& field );
|
---|
| 148 |
|
---|
| 149 | QSqlCursorPrivate* d;
|
---|
| 150 | };
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 | #endif // QT_NO_SQL
|
---|
| 156 | #endif
|
---|