Eneboo - Documentación para desarrolladores
Tipos públicos | Métodos públicos | Métodos protegidos
Referencia de la Clase QSqlCursor

The QSqlCursor class provides browsing and editing of SQL tables and views. Más...

#include <qsqlcursor.h>

Diagrama de herencias de QSqlCursor
QSqlRecord QSqlQuery QSqlRecord QSqlQuery FLSqlCursor QSqlSelectCursor QSqlSelectCursor AQSqlCursor

Lista de todos los miembros.

Tipos públicos

enum  Mode {
  ReadOnly = 0, Insert = 1, Update = 2, Delete = 4,
  Writable = 7, ReadOnly = 0, Insert = 1, Update = 2,
  Delete = 4, Writable = 7
}
enum  Mode {
  ReadOnly = 0, Insert = 1, Update = 2, Delete = 4,
  Writable = 7, ReadOnly = 0, Insert = 1, Update = 2,
  Delete = 4, Writable = 7
}

Métodos públicos

 QSqlCursor (const QString &name=QString::null, bool autopopulate=TRUE, QSqlDatabase *db=0)
 QSqlCursor (const QSqlCursor &other)
QSqlCursoroperator= (const QSqlCursor &other)
 ~QSqlCursor ()
QVariant value (int i) const
QVariant value (const QString &name) const
void setValue (int i, const QVariant &val)
void setValue (const QString &name, const QVariant &val)
virtual QSqlIndex primaryIndex (bool prime=TRUE) const
virtual QSqlIndex index (const QStringList &fieldNames) const
QSqlIndex index (const QString &fieldName) const
QSqlIndex index (const char *fieldName) const
virtual void setPrimaryIndex (const QSqlIndex &idx)
virtual void append (const QSqlFieldInfo &fieldInfo)
virtual void insert (int pos, const QSqlFieldInfo &fieldInfo)
void remove (int pos)
void clear ()
void setGenerated (const QString &name, bool generated)
void setGenerated (int i, bool generated)
virtual QSqlRecordeditBuffer (bool copy=FALSE)
virtual QSqlRecordprimeInsert ()
virtual QSqlRecordprimeUpdate ()
virtual QSqlRecordprimeDelete ()
virtual int insert (bool invalidate=TRUE)
virtual int update (bool invalidate=TRUE)
virtual int del (bool invalidate=TRUE)
virtual void setMode (int flags)
int mode () const
virtual void setCalculated (const QString &name, bool calculated)
bool isCalculated (const QString &name) const
virtual void setTrimmed (const QString &name, bool trim)
bool isTrimmed (const QString &name) const
bool isReadOnly () const
bool canInsert () const
bool canUpdate () const
bool canDelete () const
bool select ()
bool select (const QSqlIndex &sort)
bool select (const QSqlIndex &filter, const QSqlIndex &sort)
virtual bool select (const QString &filter, const QSqlIndex &sort=QSqlIndex())
virtual void setSort (const QSqlIndex &sort)
QSqlIndex sort () const
virtual void setFilter (const QString &filter)
QString filter () const
virtual void setName (const QString &name, bool autopopulate=TRUE)
QString name () const
QString toString (const QString &prefix=QString::null, const QString &sep=",") const
bool isNull (int i) const
bool isNull (const QString &name) const
QSqlError lastError () const
 QSqlCursor (const QString &name=QString::null, bool autopopulate=TRUE, QSqlDatabase *db=0)
 QSqlCursor (const QSqlCursor &other)
QSqlCursoroperator= (const QSqlCursor &other)
 ~QSqlCursor ()
QVariant value (int i) const
QVariant value (const QString &name) const
void setValue (int i, const QVariant &val)
void setValue (const QString &name, const QVariant &val)
virtual QSqlIndex primaryIndex (bool prime=TRUE) const
virtual QSqlIndex index (const QStringList &fieldNames) const
QSqlIndex index (const QString &fieldName) const
QSqlIndex index (const char *fieldName) const
virtual void setPrimaryIndex (const QSqlIndex &idx)
virtual void append (const QSqlFieldInfo &fieldInfo)
virtual void insert (int pos, const QSqlFieldInfo &fieldInfo)
void remove (int pos)
void clear ()
void setGenerated (const QString &name, bool generated)
void setGenerated (int i, bool generated)
virtual QSqlRecordeditBuffer (bool copy=FALSE)
virtual QSqlRecordprimeInsert ()
virtual QSqlRecordprimeUpdate ()
virtual QSqlRecordprimeDelete ()
virtual int insert (bool invalidate=TRUE)
virtual int update (bool invalidate=TRUE)
virtual int del (bool invalidate=TRUE)
virtual void setMode (int flags)
int mode () const
virtual void setCalculated (const QString &name, bool calculated)
bool isCalculated (const QString &name) const
virtual void setTrimmed (const QString &name, bool trim)
bool isTrimmed (const QString &name) const
bool isReadOnly () const
bool canInsert () const
bool canUpdate () const
bool canDelete () const
bool select ()
bool select (const QSqlIndex &sort)
bool select (const QSqlIndex &filter, const QSqlIndex &sort)
virtual bool select (const QString &filter, const QSqlIndex &sort=QSqlIndex())
virtual void setSort (const QSqlIndex &sort)
QSqlIndex sort () const
virtual void setFilter (const QString &filter)
QString filter () const
virtual void setName (const QString &name, bool autopopulate=TRUE)
QString name () const
QString toString (const QString &prefix=QString::null, const QString &sep=",") const
bool isNull (int i) const
bool isNull (const QString &name) const
QSqlError lastError () const

Métodos protegidos

void afterSeek ()
bool exec (const QString &sql)
virtual QVariant calculateField (const QString &name)
virtual int update (const QString &filter, bool invalidate=TRUE)
virtual int del (const QString &filter, bool invalidate=TRUE)
virtual QString toString (const QString &prefix, QSqlField *field, const QString &fieldSep) const
virtual QString toString (QSqlRecord *rec, const QString &prefix, const QString &fieldSep, const QString &sep) const
virtual QString toString (const QSqlIndex &i, QSqlRecord *rec, const QString &prefix, const QString &fieldSep, const QString &sep) const
void afterSeek ()
bool exec (const QString &sql)
virtual QVariant calculateField (const QString &name)
virtual int update (const QString &filter, bool invalidate=TRUE)
virtual int del (const QString &filter, bool invalidate=TRUE)
virtual QString toString (const QString &prefix, QSqlField *field, const QString &fieldSep) const
virtual QString toString (QSqlRecord *rec, const QString &prefix, const QString &fieldSep, const QString &sep) const
virtual QString toString (const QSqlIndex &i, QSqlRecord *rec, const QString &prefix, const QString &fieldSep, const QString &sep) const

Descripción detallada

The QSqlCursor class provides browsing and editing of SQL tables and views.

sql

A 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.

When 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.

For 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.

For example:

sql/overview/retrieve2/main.cpp QSqlCursor QSqlCursor }

In 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.

For 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.

For example:

sql/overview/update/main.cpp prices prices update

To edit an existing database record, first move to the record you wish to update. Call primeUpdate() to get the pointer to the cursor's edit buffer. Then use this pointer to modify the values in the edit buffer. Finally, call update() to save the changes to the database. The values in the edit buffer will be used to locate the appropriate record when updating the database (see primaryIndex()).

Similarly, when deleting an existing database record, first move to the record you wish to delete. Then, call primeDelete() to get the pointer to the edit buffer. Finally, call del() to delete the record from the database. Again, the values in the edit buffer will be used to locate and delete the appropriate record.

To insert a new record, call primeInsert() to get the pointer to the edit buffer. Use this pointer to populate the edit buffer with new values and then insert() the record into the database.

After calling insert(), update() or del(), the cursor is no longer positioned on a valid record and can no longer be navigated (isValid() return FALSE). The reason for this is that any changes made to the database will not be visible until select() is called to refresh the cursor. You can change this behavior by passing FALSE to insert(), update() or del() which will prevent the cursor from becoming invalid. The edits will still not be visible when navigating the cursor until select() is called.

QSqlCursor contains virtual methods which allow editing behavior to be customized by subclasses. This allows custom cursors to be created that encapsulate the editing behavior of a database table for an entire application. For example, a cursor can be customized to always auto-number primary index fields, or provide fields with suitable default values, when inserting new records. QSqlCursor generates SQL statements which are sent to the database engine; you can control which fields are included in these statements using setGenerated().

Note that QSqlCursor does not inherit from QObject. This means that you are responsible for destroying instances of this class yourself. However if you create a QSqlCursor and use it in a QDataTable, QDataBrowser or a QDataView these classes will usually take ownership of the cursor and destroy it when they don't need it anymore. The documentation for QDataTable, QDataBrowser and QDataView explicitly states which calls take ownership of the cursor.


Documentación de las enumeraciones miembro de la clase

This enum type describes how QSqlCursor operates on records in the database.

ReadOnly the cursor can only SELECT records from the database.

Insert the cursor can INSERT records into the database.

Update the cursor can UPDATE records in the database.

Delete the cursor can DELETE records from the database.

Writable the cursor can INSERT, UPDATE and DELETE records in the database.

Valores de enumeraciones:
ReadOnly 
Insert 
Update 
Delete 
Writable 
ReadOnly 
Insert 
Update 
Delete 
Writable 

Reimplementado en FLSqlCursor.

Valores de enumeraciones:
ReadOnly 
Insert 
Update 
Delete 
Writable 
ReadOnly 
Insert 
Update 
Delete 
Writable 

Reimplementado en FLSqlCursor.


Documentación del constructor y destructor

QSqlCursor::QSqlCursor ( const QString name = QString::null,
bool  autopopulate = TRUE,
QSqlDatabase db = 0 
)

Constructs a cursor on database db using table or view name.

If autopopulate is TRUE (the default), the name of the cursor must correspond to an existing table or view name in the database so that field information can be automatically created. If the table or view does not exist, the cursor will not be functional.

The cursor is created with an initial mode of QSqlCursor::Writable (meaning that records can be inserted, updated or deleted using the cursor). If the cursor does not have a unique primary index, update and deletes cannot be performed.

Note that autopopulate refers to populating the cursor with meta-data, e.g. the names of the table's fields, not with retrieving data. The select() function is used to populate the cursor with data.

Ver también:
setName() setMode()
QSqlCursor::QSqlCursor ( const QSqlCursor other)

Constructs a copy of other.

QSqlCursor::~QSqlCursor ( )

Destroys the object and frees any allocated resources.

QSqlCursor::QSqlCursor ( const QString name = QString::null,
bool  autopopulate = TRUE,
QSqlDatabase db = 0 
)
QSqlCursor::QSqlCursor ( const QSqlCursor other)
QSqlCursor::~QSqlCursor ( )

Documentación de las funciones miembro

void QSqlCursor::afterSeek ( ) [protected, virtual]

Reimplementado de QSqlQuery.

Reimplementado en FLSqlCursor.

void QSqlCursor::afterSeek ( ) [protected, virtual]

Protected virtual function called after the internal record pointer is moved to a new record. The default implementation does nothing.

Reimplementado de QSqlQuery.

Reimplementado en FLSqlCursor.

virtual void QSqlCursor::append ( const QSqlFieldInfo fieldInfo) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::append ( const QSqlFieldInfo fieldInfo) [virtual]

Append a copy of field fieldInfo to the end of the cursor. Note that all references to the cursor edit buffer become invalidated.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QVariant QSqlCursor::calculateField ( const QString name) [protected, virtual]

Protected virtual function which is called whenever a field needs to be calculated. If calculated fields are being used, derived classes must reimplement this function and return the appropriate value for field name. The default implementation returns an invalid QVariant.

Ver también:
setCalculated()

Reimplementado en FLSqlCursor.

virtual QVariant QSqlCursor::calculateField ( const QString name) [protected, virtual]

Reimplementado en FLSqlCursor.

bool QSqlCursor::canDelete ( ) const

Returns TRUE if the cursor will perform deletes; otherwise returns FALSE.

Ver también:
setMode()
bool QSqlCursor::canDelete ( ) const
bool QSqlCursor::canInsert ( ) const
bool QSqlCursor::canInsert ( ) const

Returns TRUE if the cursor will perform inserts; otherwise returns FALSE.

Ver también:
setMode()
bool QSqlCursor::canUpdate ( ) const

Returns TRUE if the cursor will perform updates; otherwise returns FALSE.

Ver también:
setMode()
bool QSqlCursor::canUpdate ( ) const
void QSqlCursor::clear ( void  ) [virtual]

Removes all the record's fields.

Ver también:
clearValues()

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::clear ( void  ) [virtual]

Removes all fields from the cursor. Note that all references to the cursor edit buffer become invalidated.

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

int QSqlCursor::del ( bool  invalidate = TRUE) [virtual]

Deletes a record from the database using the cursor's primary index and the contents of the cursor edit buffer. Returns the number of records which were deleted. For error information, use lastError().

Only records which meet the filter criteria specified by the cursor's primary index are deleted. If the cursor does not contain a primary index, no delete is performed and 0 is returned. If invalidate is TRUE (the default), the current cursor can no longer be navigated. A new select() call must be made before you can move to a valid record. For example:

sql/overview/delete/main.cpp prices prices }

In the above example, a cursor is created on the 'prices' table and positioned to the record to be deleted. First primeDelete() is called to populate the edit buffer with the current cursor values, e.g. with an id of 999, and then del() is called to actually delete the record from the database. Remember: all edit operations (insert(), update() and delete()) operate on the contents of the cursor edit buffer and not on the contents of the cursor itself.

Ver también:
primeDelete() setMode() lastError()

Reimplementado en FLSqlCursor, QSqlSelectCursor y QSqlSelectCursor.

virtual int QSqlCursor::del ( bool  invalidate = TRUE) [virtual]
int QSqlCursor::del ( const QString filter,
bool  invalidate = TRUE 
) [protected, virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Deletes the current cursor record from the database using the filter filter. Only records which meet the filter criteria are deleted. Returns the number of records which were deleted. If invalidate is TRUE (the default), the current cursor can no longer be navigated. A new select() call must be made before you can move to a valid record. For error information, use lastError().

The filter is an SQL WHERE clause, e.g. {id=500}.

Ver también:
setMode() lastError()
virtual int QSqlCursor::del ( const QString filter,
bool  invalidate = TRUE 
) [protected, virtual]
virtual QSqlRecord* QSqlCursor::editBuffer ( bool  copy = FALSE) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlRecord * QSqlCursor::editBuffer ( bool  copy = FALSE) [virtual]

Returns the current internal edit buffer. If copy is TRUE (the default is FALSE), the current cursor field values are first copied into the edit buffer. The edit buffer is valid as long as the cursor remains valid. The cursor retains ownership of the returned pointer, so it must not be deleted or modified.

Ver también:
primeInsert(), primeUpdate() primeDelete()

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

bool QSqlCursor::exec ( const QString sql) [protected, virtual]

Executes the SQL query sql. Returns TRUE of the cursor is active, otherwise returns FALSE.

Reimplementado de QSqlQuery.

Reimplementado en FLSqlCursor, QSqlSelectCursor y QSqlSelectCursor.

bool QSqlCursor::exec ( const QString query) [protected, virtual]

Executes the SQL in query. Returns TRUE and sets the query state to active if the query was successful; otherwise returns FALSE and sets the query state to inactive. The query string must use syntax appropriate for the SQL database being queried, for example, standard SQL.

After the query is executed, the query is positioned on an invalid record, and must be navigated to a valid record before data values can be retrieved, e.g. using next().

Note that the last error for this query is reset when exec() is called.

Ver también:
isActive() isValid() next() prev() first() last() seek()

Reimplementado de QSqlQuery.

Reimplementado en FLSqlCursor, QSqlSelectCursor y QSqlSelectCursor.

QString QSqlCursor::filter ( ) const

Returns the current filter, or an empty string if there is no current filter.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QString QSqlCursor::filter ( ) const

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlIndex QSqlCursor::index ( const char *  fieldName) const

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlIndex QSqlCursor::index ( const QStringList fieldNames) const [virtual]

Returns an index composed of fieldNames, all in ASCending order. Note that all field names must exist in the cursor, otherwise an empty index is returned.

Ver también:
QSqlIndex

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlIndex QSqlCursor::index ( const char *  fieldName) const

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns an index based on fieldName.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlIndex QSqlCursor::index ( const QString fieldName) const

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns an index based on fieldName.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual QSqlIndex QSqlCursor::index ( const QStringList fieldNames) const [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlIndex QSqlCursor::index ( const QString fieldName) const

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual void QSqlCursor::insert ( int  pos,
const QSqlFieldInfo fieldInfo 
) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual int QSqlCursor::insert ( bool  invalidate = TRUE) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

int QSqlCursor::insert ( bool  invalidate = TRUE) [virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Inserts the current contents of the cursor's edit record buffer into the database, if the cursor allows inserts. Returns the number of rows affected by the insert. For error information, use lastError().

If invalidate is TRUE (the default), the cursor will no longer be positioned on a valid record and can no longer be navigated. A new select() call must be made before navigating to a valid record.

sql/overview/insert2/main.cpp prices prices insert

In the above example, a cursor is created on the 'prices' table and a pointer to the insert buffer is aquired using primeInsert(). Each field's value is set to the desired value and then insert() is called to insert the data into the database. Remember: all edit operations (insert(), update() and delete()) operate on the contents of the cursor edit buffer and not on the contents of the cursor itself.

Ver también:
setMode() lastError()

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::insert ( int  pos,
const QSqlFieldInfo fieldInfo 
) [virtual]

Insert a copy of fieldInfo at position pos. If a field already exists at pos, it is removed. Note that all references to the cursor edit buffer become invalidated.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

bool QSqlCursor::isCalculated ( const QString name) const
bool QSqlCursor::isCalculated ( const QString name) const

Returns TRUE if the field name exists and is calculated; otherwise returns FALSE.

Ver también:
setCalculated()
bool QSqlCursor::isNull ( int  i) const

Returns TRUE if the field i is NULL or if there is no field at position i; otherwise returns FALSE.

This is the same as calling QSqlRecord::isNull( i )

Reimplementado de QSqlQuery.

bool QSqlCursor::isNull ( const QString name) const

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns TRUE if the field called name is NULL or if there is no field called name; otherwise returns FALSE.

This is the same as calling QSqlRecord::isNull( name )

Reimplementado de QSqlRecord.

bool QSqlCursor::isNull ( int  field) const

Returns TRUE if the query is active and positioned on a valid record and the field is NULL; otherwise returns FALSE. Note that for some drivers isNull() will not return accurate information until after an attempt is made to retrieve data.

Ver también:
isActive() isValid() value()

Reimplementado de QSqlQuery.

bool QSqlCursor::isNull ( const QString name) const

Returns TRUE if the field called name is NULL or if there is no field called name; otherwise returns FALSE.

Ver también:
position()

Reimplementado de QSqlRecord.

bool QSqlCursor::isReadOnly ( ) const
bool QSqlCursor::isReadOnly ( ) const

Returns TRUE if the cursor is read-only; otherwise returns FALSE. The default is FALSE. Read-only cursors cannot be edited using insert(), update() or del().

Ver también:
setMode()
bool QSqlCursor::isTrimmed ( const QString name) const
bool QSqlCursor::isTrimmed ( const QString name) const

Returns TRUE if the field name exists and is trimmed; otherwise returns FALSE.

When a trimmed field of type string or cstring is read from the database any trailing (right-most) spaces are removed.

Ver también:
setTrimmed()
QSqlError QSqlCursor::lastError ( ) const [virtual]

Returns error information about the last error (if any) that occurred.

Ver también:
QSqlError

Reimplementado de QSqlQuery.

QSqlError QSqlCursor::lastError ( ) const [virtual]

Returns error information about the last error (if any) that occurred.

Ver también:
QSqlError

Reimplementado de QSqlQuery.

int QSqlCursor::mode ( ) const
int QSqlCursor::mode ( ) const

Returns the current cursor mode.

Ver también:
setMode()
QString QSqlCursor::name ( ) const

Returns the name of the cursor.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QString QSqlCursor::name ( ) const

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlCursor & QSqlCursor::operator= ( const QSqlCursor other)

Sets the cursor equal to other.

QSqlCursor& QSqlCursor::operator= ( const QSqlCursor other)
QSqlIndex QSqlCursor::primaryIndex ( bool  setFromCursor = TRUE) const [virtual]

Returns the primary index associated with the cursor as defined in the database, or an empty index if there is no primary index. If setFromCursor is TRUE (the default), the index fields are populated with the corresponding values in the cursor's current record.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual QSqlIndex QSqlCursor::primaryIndex ( bool  prime = TRUE) const [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual QSqlRecord* QSqlCursor::primeDelete ( ) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlRecord * QSqlCursor::primeDelete ( ) [virtual]

This function primes the edit buffer's field values for delete and returns the edit buffer. The default implementation copies the field values from the current cursor record into the edit buffer (therefore, this function is equivalent to calling editBuffer( TRUE ) ). The cursor retains ownership of the returned pointer, so it must not be deleted or modified.

Ver también:
editBuffer() del()

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual QSqlRecord* QSqlCursor::primeInsert ( ) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlRecord * QSqlCursor::primeInsert ( ) [virtual]

This function primes the edit buffer's field values for insert and returns the edit buffer. The default implementation clears all field values in the edit buffer. The cursor retains ownership of the returned pointer, so it must not be deleted or modified.

Ver también:
editBuffer() insert()

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual QSqlRecord* QSqlCursor::primeUpdate ( ) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlRecord * QSqlCursor::primeUpdate ( ) [virtual]

This function primes the edit buffer's field values for update and returns the edit buffer. The default implementation copies the field values from the current cursor record into the edit buffer (therefore, this function is equivalent to calling editBuffer( TRUE ) ). The cursor retains ownership of the returned pointer, so it must not be deleted or modified.

Ver también:
editBuffer() update()

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::remove ( int  pos) [virtual]

Removes the field at pos. If pos does not exist, nothing happens.

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::remove ( int  pos) [virtual]

Removes the field at pos. If pos does not exist, nothing happens. Note that all references to the cursor edit buffer become invalidated.

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

bool QSqlCursor::select ( )

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Selects all fields in the cursor from the database. The rows are returned in the order specified by the last call to setSort() or the last call to select() that specified a sort, whichever is the most recent. If there is no current sort, the order in which the rows are returned is undefined. The records are filtered according to the filter specified by the last call to setFilter() or the last call to select() that specified a filter, whichever is the most recent. If there is no current filter, all records are returned. The cursor is initially positioned at an invalid row. To move to a valid row, use seek(), first(), last(), prev() or next().

Ver también:
setSort() setFilter()

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

bool QSqlCursor::select ( const QSqlIndex sort)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Selects all fields in the cursor from the database. The data is returned in the order specified by the index sort. The records are filtered according to the filter specified by the last call to setFilter() or the last call to select() that specified a filter, whichever is the most recent. The cursor is initially positioned at an invalid row. To move to a valid row, use seek(), first(), last(), prev() or next().

bool QSqlCursor::select ( const QSqlIndex filter,
const QSqlIndex sort 
)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Selects all fields in the cursor matching the filter index filter. The data is returned in the order specified by the index sort. The filter index works by constructing a WHERE clause using the names of the fields from the filter and their values from the current cursor record. The cursor is initially positioned at an invalid row. To move to a valid row, use seek(), first(), last(), prev() or next(). This function is useful, for example, for retrieving data based upon a table's primary index:

    QSqlCursor cur( "Employee" );
    QSqlIndex pk = cur.primaryIndex();
    cur.setValue( "id", 10 );
    cur.select( pk, pk ); // generates "SELECT ... FROM Employee WHERE id=10 ORDER BY id"
    ...

In this example the QSqlIndex, pk, is used for two different purposes. When used as the filter (first) argument, the field names it contains are used to construct the WHERE clause, each set to the current cursor value, {WHERE id=10}, in this case. When used as the sort (second) argument the field names it contains are used for the ORDER BY clause, {ORDER BY id} in this example.

bool QSqlCursor::select ( const QString filter,
const QSqlIndex sort = QSqlIndex() 
) [virtual]

Selects all fields in the cursor from the database matching the filter criteria filter. The data is returned in the order specified by the index sort. Returns TRUE if the data was successfully selected; otherwise returns FALSE.

The filter is a string containing a SQL WHERE clause but without the 'WHERE' keyword. The cursor is initially positioned at an invalid row after this function is called. To move to a valid row, use seek(), first(), last(), prev() or next().

Example:

    QSqlCursor cur( "Employee" ); // Use the Employee table or view
    cur.select( "deptno=10" ); // select all records in department 10
    while( cur.next() ) {
        ... // process data
    }
    ...
    // select records in other departments, ordered by department number
    cur.select( "deptno>10", cur.index( "deptno" ) );
    ...

The filter will apply to any subsequent select() calls that do not explicitly specify another filter. Similarly the sort will apply to any subsequent select() calls that do not explicitly specify another sort.

    QSqlCursor cur( "Employee" );
    cur.select( "deptno=10" ); // select all records in department 10
    while( cur.next() ) {
        ... // process data
    }
    ...
    cur.select(); // re-selects all records in department 10
    ...

Reimplementado en FLSqlCursor, QSqlSelectCursor y QSqlSelectCursor.

bool QSqlCursor::select ( )

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

bool QSqlCursor::select ( const QSqlIndex sort)
virtual bool QSqlCursor::select ( const QString filter,
const QSqlIndex sort = QSqlIndex() 
) [virtual]
bool QSqlCursor::select ( const QSqlIndex filter,
const QSqlIndex sort 
)
void QSqlCursor::setCalculated ( const QString name,
bool  calculated 
) [virtual]

Sets field name to calculated. If the field name does not exist, nothing happens. The value of a calculated field is set by the calculateField() virtual function which you must reimplement (or the field value will be an invalid QVariant). Calculated fields do not appear in generated SQL statements sent to the database.

Ver también:
calculateField() QSqlRecord::setGenerated()
virtual void QSqlCursor::setCalculated ( const QString name,
bool  calculated 
) [virtual]
void QSqlCursor::setFilter ( const QString filter) [virtual]

Sets the current filter to filter. Note that no new records are selected. To select new records, use select(). The filter will apply to any subsequent select() calls that do not explicitly specify a filter.

The filter is a SQL WHERE clause without the keyword 'WHERE', e.g. {name='Dave'} which will be processed by the DBMS.

Reimplementado en FLSqlCursor, QSqlSelectCursor y QSqlSelectCursor.

virtual void QSqlCursor::setFilter ( const QString filter) [virtual]
void QSqlCursor::setGenerated ( int  i,
bool  generated 
) [virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Sets the generated flag for the field i to generated.

Ver también:
isGenerated()

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::setGenerated ( int  i,
bool  generated 
) [virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Sets the generated flag for the field i to generated.

Ver también:
isGenerated()

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::setGenerated ( const QString name,
bool  generated 
) [virtual]

Sets the generated flag for the field called name to generated. If the field does not exist, nothing happens. Only fields that have generated set to TRUE are included in the SQL that is generated, e.g. by QSqlCursor.

Ver también:
isGenerated()

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::setGenerated ( const QString name,
bool  generated 
) [virtual]

Sets the generated flag for the field name to generated. If the field does not exist, nothing happens. Only fields that have generated set to TRUE are included in the SQL that is generated by insert(), update() or del().

Ver también:
isGenerated()

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::setMode ( int  mode) [virtual]

Sets the cursor mode to mode. This value can be an OR'ed combination of QSqlCursor::Mode values. The default mode for a cursor is QSqlCursor::Writable.

    QSqlCursor cur( "Employee" );
    cur.setMode( QSqlCursor::Writable ); // allow insert/update/delete
    ...
    cur.setMode( QSqlCursor::Insert | QSqlCursor::Update ); // allow inserts and updates only
    ...
    cur.setMode( QSqlCursor::ReadOnly ); // no inserts/updates/deletes allowed

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual void QSqlCursor::setMode ( int  flags) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual void QSqlCursor::setName ( const QString name,
bool  autopopulate = TRUE 
) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::setName ( const QString name,
bool  autopopulate = TRUE 
) [virtual]

Sets the name of the cursor to name. If autopopulate is TRUE (the default), the name must correspond to a valid table or view name in the database. Also, note that all references to the cursor edit buffer become invalidated when fields are auto-populated. See the QSqlCursor constructor documentation for more information.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual void QSqlCursor::setPrimaryIndex ( const QSqlIndex idx) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::setPrimaryIndex ( const QSqlIndex idx) [virtual]

Sets the primary index associated with the cursor to the index idx. Note that this index must contain a field or set of fields which identify a unique record within the underlying database table or view so that update() and del() will execute as expected.

Ver también:
update() del()

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

void QSqlCursor::setSort ( const QSqlIndex sort) [virtual]

Sets the current sort to sort. Note that no new records are selected. To select new records, use select(). The sort will apply to any subsequent select() calls that do not explicitly specify a sort.

Reimplementado en FLSqlCursor, QSqlSelectCursor y QSqlSelectCursor.

virtual void QSqlCursor::setSort ( const QSqlIndex sort) [virtual]
void QSqlCursor::setTrimmed ( const QString name,
bool  trim 
) [virtual]

Sets field {name}'s trimmed status to trim. If the field name does not exist, nothing happens.

When a trimmed field of type string or cstring is read from the database any trailing (right-most) spaces are removed.

Ver también:
isTrimmed() QVariant
virtual void QSqlCursor::setTrimmed ( const QString name,
bool  trim 
) [virtual]
void QSqlCursor::setValue ( int  i,
const QVariant val 
) [virtual]

Reimplementado de QSqlRecord.

void QSqlCursor::setValue ( int  i,
const QVariant val 
) [virtual]

Sets the value of the field at position i to val. If the field does not exist, nothing happens.

Reimplementado de QSqlRecord.

void QSqlCursor::setValue ( const QString name,
const QVariant val 
) [virtual]

Reimplementado de QSqlRecord.

void QSqlCursor::setValue ( const QString name,
const QVariant val 
) [virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Sets the value of the field called name to val. If the field does not exist, nothing happens.

Reimplementado de QSqlRecord.

QSqlIndex QSqlCursor::sort ( ) const

Returns the current sort, or an empty index if there is no current sort.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QSqlIndex QSqlCursor::sort ( ) const

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual QString QSqlCursor::toString ( const QString prefix,
QSqlField field,
const QString fieldSep 
) const [protected, virtual]
QString QSqlCursor::toString ( const QSqlIndex i,
QSqlRecord rec,
const QString prefix,
const QString fieldSep,
const QString sep 
) const [protected, virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns a formatted string composed of all the fields in the index i. Each field is composed of the prefix (e.g. table or view name), ".", the field name, the fieldSep and the field value. If the prefix is empty then each field will begin with the field name. The field values are taken from rec. The fields are then joined together separated by sep. Fields where isGenerated() returns FALSE are ignored. This function is useful for generating SQL statements.

QString QSqlCursor::toString ( const QString prefix,
QSqlField field,
const QString fieldSep 
) const [protected, virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns a formatted string composed of the prefix (e.g. table or view name), ".", the field name, the fieldSep and the field value. If the prefix is empty then the string will begin with the field name. This function is useful for generating SQL statements.

QString QSqlCursor::toString ( const QString prefix = QString::null,
const QString sep = "," 
) const [virtual]

Returns a list of all the record's field names as a string separated by sep.

Note that fields which are not generated are not included (see {isGenerated()}). The returned string is suitable, for example, for generating SQL SELECT statements. If a prefix is specified, e.g. a table name, all fields are prefixed in the form:

"\a{prefix}.\<fieldname\>"

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual QString QSqlCursor::toString ( const QSqlIndex i,
QSqlRecord rec,
const QString prefix,
const QString fieldSep,
const QString sep 
) const [protected, virtual]
virtual QString QSqlCursor::toString ( QSqlRecord rec,
const QString prefix,
const QString fieldSep,
const QString sep 
) const [protected, virtual]
QString QSqlCursor::toString ( const QString prefix = QString::null,
const QString sep = "," 
) const [virtual]

Reimplementado de QSqlRecord.

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QString QSqlCursor::toString ( QSqlRecord rec,
const QString prefix,
const QString fieldSep,
const QString sep 
) const [protected, virtual]

Returns a formatted string composed of all the fields in rec. Each field is composed of the prefix (e.g. table or view name), ".", the field name, the fieldSep and the field value. If the prefix is empty then each field will begin with the field name. The fields are then joined together separated by sep. Fields where isGenerated() returns FALSE are not included. This function is useful for generating SQL statements.

virtual int QSqlCursor::update ( const QString filter,
bool  invalidate = TRUE 
) [protected, virtual]
int QSqlCursor::update ( const QString filter,
bool  invalidate = TRUE 
) [protected, virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Updates the database with the current contents of the cursor edit buffer using the specified filter. Returns the number of records which were updated. For error information, use lastError().

Only records which meet the filter criteria are updated, otherwise all records in the table are updated.

If invalidate is TRUE (the default), the cursor can no longer be navigated. A new select() call must be made before you can move to a valid record.

Ver también:
primeUpdate() setMode() lastError()
int QSqlCursor::update ( bool  invalidate = TRUE) [virtual]

Updates the database with the current contents of the edit buffer. Returns the number of records which were updated. For error information, use lastError().

Only records which meet the filter criteria specified by the cursor's primary index are updated. If the cursor does not contain a primary index, no update is performed and 0 is returned.

If invalidate is TRUE (the default), the current cursor can no longer be navigated. A new select() call must be made before you can move to a valid record. For example:

sql/overview/update/main.cpp prices prices update

In the above example, a cursor is created on the 'prices' table and is positioned on the record to be updated. Then a pointer to the cursor's edit buffer is acquired using primeUpdate(). A new value is calculated and placed into the edit buffer with the setValue() call. Finally, an update() call is made on the cursor which uses the tables's primary index to update the record in the database with the contents of the cursor's edit buffer. Remember: all edit operations (insert(), update() and delete()) operate on the contents of the cursor edit buffer and not on the contents of the cursor itself.

Note that if the primary index does not uniquely distinguish records the database may be changed into an inconsistent state.

Ver también:
setMode() lastError()

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

virtual int QSqlCursor::update ( bool  invalidate = TRUE) [virtual]

Reimplementado en QSqlSelectCursor y QSqlSelectCursor.

QVariant QSqlCursor::value ( const QString name) const [virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns the value of the field called name in the record. If field name does not exist the resultant behaviour is undefined.

Reimplementado de QSqlRecord.

QVariant QSqlCursor::value ( int  i) const [virtual]

Returns the value of field number i.

Reimplementado de QSqlQuery.

QVariant QSqlCursor::value ( const QString name) const [virtual]

Returns the value of the field called name.

Reimplementado de QSqlRecord.

QVariant QSqlCursor::value ( int  i) const [virtual]

Returns the value of the {i}-th field in the query (zero based).

The fields are numbered from left to right using the text of the SELECT statement, e.g. in {SELECT forename, surname FROM people}, field 0 is forename and field 1 is surname. Using {SELECT *} is not recommended because the order of the fields in the query is undefined.

An invalid QVariant is returned if field i does not exist, if the query is inactive, or if the query is positioned on an invalid record.

Ver también:
prev() next() first() last() seek() isActive() isValid()

Reimplementado de QSqlQuery.


La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'