📄 qsqlcursor.3qt
字号:
'\" t.TH QSqlCursor 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQSqlCursor \- Browsing and editing of SQL tables and views.SH SYNOPSIS\fC#include <qsqlcursor.h>\fR.PPInherits QSqlRecord and QSqlQuery..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQSqlCursor\fR ( const QString & name = QString::null, bool autopopulate = TRUE, QSqlDatabase * db = 0 )".br.ti -1c.BI "\fBQSqlCursor\fR ( const QSqlCursor & other )".br.ti -1c.BI "QSqlCursor & \fBoperator=\fR ( const QSqlCursor & other )".br.ti -1c.BI "\fB~QSqlCursor\fR ()".br.ti -1c.BI "enum \fBMode\fR { ReadOnly = 0, Insert = 1, Update = 2, Delete = 4, Writable = 7 }".br.ti -1c.BI "virtual QSqlIndex \fBprimaryIndex\fR ( bool setFromCursor = TRUE ) const".br.ti -1c.BI "virtual QSqlIndex \fBindex\fR ( const QStringList & fieldNames ) const".br.ti -1c.BI "QSqlIndex \fBindex\fR ( const QString & fieldName ) const".br.ti -1c.BI "QSqlIndex \fBindex\fR ( const char * fieldName ) const".br.ti -1c.BI "virtual void \fBsetPrimaryIndex\fR ( const QSqlIndex & idx )".br.ti -1c.BI "virtual void \fBappend\fR ( const QSqlFieldInfo & fieldInfo )".br.ti -1c.BI "virtual void \fBinsert\fR ( int pos, const QSqlFieldInfo & fieldInfo )".br.ti -1c.BI "virtual void \fBremove\fR ( int pos )".br.ti -1c.BI "virtual void \fBclear\fR ()".br.ti -1c.BI "virtual void \fBsetGenerated\fR ( const QString & name, bool generated )".br.ti -1c.BI "virtual void \fBsetGenerated\fR ( int i, bool generated )".br.ti -1c.BI "virtual QSqlRecord * \fBeditBuffer\fR ( bool copy = FALSE )".br.ti -1c.BI "virtual QSqlRecord * \fBprimeInsert\fR ()".br.ti -1c.BI "virtual QSqlRecord * \fBprimeUpdate\fR ()".br.ti -1c.BI "virtual QSqlRecord * \fBprimeDelete\fR ()".br.ti -1c.BI "virtual int \fBinsert\fR ( bool invalidate = TRUE )".br.ti -1c.BI "virtual int \fBupdate\fR ( bool invalidate = TRUE )".br.ti -1c.BI "virtual int \fBdel\fR ( bool invalidate = TRUE )".br.ti -1c.BI "virtual void \fBsetMode\fR ( int mode )".br.ti -1c.BI "int \fBmode\fR () const".br.ti -1c.BI "virtual void \fBsetCalculated\fR ( const QString & name, bool calculated )".br.ti -1c.BI "bool \fBisCalculated\fR ( const QString & name ) const".br.ti -1c.BI "virtual void \fBsetTrimmed\fR ( const QString & name, bool trim )".br.ti -1c.BI "bool \fBisTrimmed\fR ( const QString & name ) const".br.ti -1c.BI "bool \fBisReadOnly\fR () const".br.ti -1c.BI "bool \fBcanInsert\fR () const".br.ti -1c.BI "bool \fBcanUpdate\fR () const".br.ti -1c.BI "bool \fBcanDelete\fR () const".br.ti -1c.BI "bool \fBselect\fR ()".br.ti -1c.BI "bool \fBselect\fR ( const QSqlIndex & sort )".br.ti -1c.BI "bool \fBselect\fR ( const QSqlIndex & filter, const QSqlIndex & sort )".br.ti -1c.BI "virtual bool \fBselect\fR ( const QString & filter, const QSqlIndex & sort = QSqlIndex ( ) )".br.ti -1c.BI "virtual void \fBsetSort\fR ( const QSqlIndex & sort )".br.ti -1c.BI "QSqlIndex \fBsort\fR () const".br.ti -1c.BI "virtual void \fBsetFilter\fR ( const QString & filter )".br.ti -1c.BI "QString \fBfilter\fR () const".br.ti -1c.BI "virtual void \fBsetName\fR ( const QString & name, bool autopopulate = TRUE )".br.ti -1c.BI "QString \fBname\fR () const".br.ti -1c.BI "bool \fBisNull\fR ( int i ) const".br.ti -1c.BI "bool \fBisNull\fR ( const QString & name ) const".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual QVariant \fBcalculateField\fR ( const QString & name )".br.ti -1c.BI "virtual int \fBupdate\fR ( const QString & filter, bool invalidate = TRUE )".br.ti -1c.BI "virtual int \fBdel\fR ( const QString & filter, bool invalidate = TRUE )".br.ti -1c.BI "virtual QString \fBtoString\fR ( const QString & prefix, QSqlField * field, const QString & fieldSep ) const".br.ti -1c.BI "virtual QString \fBtoString\fR ( QSqlRecord * rec, const QString & prefix, const QString & fieldSep, const QString & sep ) const".br.ti -1c.BI "virtual QString \fBtoString\fR ( const QSqlIndex & i, QSqlRecord * rec, const QString & prefix, const QString & fieldSep, const QString & sep ) const".br.in -1c.SH DESCRIPTIONThe QSqlCursor class provides browsing and editing of SQL tables and views..PPA QSqlCursor is a database record (see QSqlRecord) that corresponds to a table or view within an SQL database (see QSqlDatabase). There are two buffers in a cursor, one used for browsing and one used for editing records. Each buffer contains a list of fields which correspond to the fields in the table or view..PPWhen positioned on a valid record, the browse buffer contains the values of the current record's fields from the database. The edit buffer is separate, and is used for editing existing records and inserting new records..PPFor browsing data, a cursor must first select() data from the database. After a successful select() the cursor is active (isActive() returns TRUE), but is initially not positioned on a valid record (isValid() returns FALSE). To position the cursor on a valid record, use one of the navigation functions, next(), prev(), first(), last(), or seek(). Once positioned on a valid record, data can be retrieved from the browse buffer using value(). If a navigation function is not successful, it returns FALSE, the cursor will no longer be positioned on a valid record and the values returned by value() are undefined..PPFor example:.PP.nf.br QSqlCursor cur( "staff" ); // Specify the table/view name.br cur.select(); // We'll retrieve every record.br while ( cur.next() ) {.br qDebug( cur.value( "id" ).toString() + ": " +.br cur.value( "surname" ).toString() + " " +.br cur.value( "salary" ).toString() );.br }.fi.PPIn the above example, a cursor is created specifying a table or view name in the database. Then, select() is called, which can be optionally parameterised to filter and order the records retrieved. Each record in the cursor is retrieved using next(). When next() returns FALSE, there are no more records to process, and the loop terminates..PPFor editing records (rows of data), a cursor contains a separate edit buffer which is independent of the fields used when browsing. The functions insert(), update() and del() operate on the edit buffer. This allows the cursor to be repositioned to other records while simultaneously maintaining a separate buffer for edits. You can get a pointer to the edit buffer using editBuffer(). The primeInsert(), primeUpdate() and primeDelete() functions also return a pointer to the edit buffer and prepare it for insert, update and delete respectively. Edit operations only affect a single row at a time. Note that update() and del() require that the table or view contain a primaryIndex() to ensure that edit operations affect a unique record within the database..PPFor example:.PP.nf.br QSqlCursor cur( "prices" );.br cur.select( "id=202" );.br if ( cur.next() ) {.br QSqlRecord *buffer = cur.primeUpdate();.br double price = buffer->value( "price" ).toDouble();.br
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -