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

The QSqlSelectCursor class provides browsing of general SQL SELECT statements. Más...

#include <qsqlselectcursor.h>

Diagrama de herencias de QSqlSelectCursor
QSqlCursor QSqlCursor QSqlQuery QSqlRecord QSqlQuery QSqlRecord QSqlQuery QSqlRecord QSqlQuery QSqlRecord

Lista de todos los miembros.

Métodos públicos

 QSqlSelectCursor (const QString &query=QString::null, QSqlDatabase *db=0)
 QSqlSelectCursor (const QSqlSelectCursor &other)
 ~QSqlSelectCursor ()
bool exec (const QString &query)
bool select ()
 QSqlSelectCursor (const QString &query=QString::null, QSqlDatabase *db=0)
 QSqlSelectCursor (const QSqlSelectCursor &other)
 ~QSqlSelectCursor ()
bool exec (const QString &query)
bool select ()

Métodos protegidos

QSqlIndex primaryIndex (bool=TRUE) const
QSqlIndex index (const QStringList &) const
QSqlIndex index (const QString &) const
QSqlIndex index (const char *) const
void setPrimaryIndex (const QSqlIndex &)
void append (const QSqlFieldInfo &)
void insert (int, const QSqlFieldInfo &)
void remove (int)
void clear ()
void setGenerated (const QString &, bool)
void setGenerated (int, bool)
QSqlRecordeditBuffer (bool=FALSE)
QSqlRecordprimeInsert ()
QSqlRecordprimeUpdate ()
QSqlRecordprimeDelete ()
int insert (bool=TRUE)
int update (bool=TRUE)
int del (bool=TRUE)
void setMode (int)
void setSort (const QSqlIndex &)
QSqlIndex sort () const
void setFilter (const QString &)
QString filter () const
void setName (const QString &, bool=TRUE)
QString name () const
QString toString (const QString &=QString::null, const QString &=",") const
bool select (const QString &, const QSqlIndex &=QSqlIndex())
QSqlIndex primaryIndex (bool=TRUE) const
QSqlIndex index (const QStringList &) const
QSqlIndex index (const QString &) const
QSqlIndex index (const char *) const
void setPrimaryIndex (const QSqlIndex &)
void append (const QSqlFieldInfo &)
void insert (int, const QSqlFieldInfo &)
void remove (int)
void clear ()
void setGenerated (const QString &, bool)
void setGenerated (int, bool)
QSqlRecordeditBuffer (bool=FALSE)
QSqlRecordprimeInsert ()
QSqlRecordprimeUpdate ()
QSqlRecordprimeDelete ()
int insert (bool=TRUE)
int update (bool=TRUE)
int del (bool=TRUE)
void setMode (int)
void setSort (const QSqlIndex &)
QSqlIndex sort () const
void setFilter (const QString &)
QString filter () const
void setName (const QString &, bool=TRUE)
QString name () const
QString toString (const QString &=QString::null, const QString &=",") const
bool select (const QString &, const QSqlIndex &=QSqlIndex())

Descripción detallada

The QSqlSelectCursor class provides browsing of general SQL SELECT statements.

sql

QSqlSelectCursor is a convenience class that makes it possible to display result sets from general SQL SELECT statements in data-aware Qt widgets. QSqlSelectCursor is read-only and does not support INSERT, UPDATE or DELETE operations.

Pass the query in at construction time, or use the QSqlSelectCursor::exec() function.

Example:

    ...
    QSqlSelectCursor* cur = new QSqlSelectCursor( "SELECT id, firstname, lastname FROM author" );
    QDataTable* table = new QDataTable( this );
    table->setSqlCursor( cur, TRUE, TRUE );
    table->refresh();
    ...
    cur->exec( "SELECT * FROM books" );
    table->refresh();
    ...

Documentación del constructor y destructor

QSqlSelectCursor::QSqlSelectCursor ( const QString query = QString::null,
QSqlDatabase db = 0 
)

Constructs a read only cursor on database db using the query query.

QSqlSelectCursor::QSqlSelectCursor ( const QSqlSelectCursor other)

Constructs a copy of other

QSqlSelectCursor::~QSqlSelectCursor ( )

Destroys the object and frees any allocated resources

QSqlSelectCursor::QSqlSelectCursor ( const QString query = QString::null,
QSqlDatabase db = 0 
)
QSqlSelectCursor::QSqlSelectCursor ( const QSqlSelectCursor other)
QSqlSelectCursor::~QSqlSelectCursor ( )

Documentación de las funciones miembro

void QSqlSelectCursor::append ( const QSqlFieldInfo ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::append ( const QSqlFieldInfo fieldInfo) [inline, protected, 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 de QSqlCursor.

void QSqlSelectCursor::clear ( void  ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::clear ( void  ) [inline, protected, virtual]

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

Reimplementado de QSqlCursor.

int QSqlSelectCursor::del ( bool  = TRUE) [inline, protected, virtual]

Reimplementado de QSqlCursor.

int QSqlSelectCursor::del ( bool  invalidate = TRUE) [inline, protected, 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 de QSqlCursor.

QSqlRecord* QSqlSelectCursor::editBuffer ( bool  copy = FALSE) [inline, protected, 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 de QSqlCursor.

QSqlRecord * QSqlSelectCursor::editBuffer ( bool  = FALSE) [inline, protected, virtual]

Reimplementado de QSqlCursor.

bool QSqlSelectCursor::exec ( const QString query) [virtual]

Reimplementado de QSqlCursor.

bool QSqlSelectCursor::exec ( const QString sql) [virtual]

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

Reimplementado de QSqlCursor.

QString QSqlSelectCursor::filter ( ) const [inline, protected]

Reimplementado de QSqlCursor.

QString QSqlSelectCursor::filter ( ) const [inline, protected]

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

Reimplementado de QSqlCursor.

QSqlIndex QSqlSelectCursor::index ( const QStringList fieldNames) const [inline, protected, 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 de QSqlCursor.

QSqlIndex QSqlSelectCursor::index ( const QString fieldName) const [inline, protected]

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 de QSqlCursor.

QSqlIndex QSqlSelectCursor::index ( const char *  fieldName) const [inline, protected]

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 de QSqlCursor.

QSqlIndex QSqlSelectCursor::index ( const QStringList ) const [inline, protected, virtual]

Reimplementado de QSqlCursor.

QSqlIndex QSqlSelectCursor::index ( const QString ) const [inline, protected]

Reimplementado de QSqlCursor.

QSqlIndex QSqlSelectCursor::index ( const char *  ) const [inline, protected]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::insert ( int  ,
const QSqlFieldInfo  
) [inline, protected, virtual]

Reimplementado de QSqlCursor.

int QSqlSelectCursor::insert ( bool  = TRUE) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::insert ( int  pos,
const QSqlFieldInfo fieldInfo 
) [inline, protected, 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 de QSqlCursor.

int QSqlSelectCursor::insert ( bool  invalidate = TRUE) [inline, 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. 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 de QSqlCursor.

QString QSqlSelectCursor::name ( ) const [inline, protected]

Reimplementado de QSqlCursor.

QString QSqlSelectCursor::name ( ) const [inline, protected]

Returns the name of the cursor.

Reimplementado de QSqlCursor.

QSqlIndex QSqlSelectCursor::primaryIndex ( bool  setFromCursor = TRUE) const [inline, protected, 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 de QSqlCursor.

QSqlIndex QSqlSelectCursor::primaryIndex ( bool  = TRUE) const [inline, protected, virtual]

Reimplementado de QSqlCursor.

QSqlRecord * QSqlSelectCursor::primeDelete ( ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

QSqlRecord* QSqlSelectCursor::primeDelete ( ) [inline, protected, 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 de QSqlCursor.

QSqlRecord* QSqlSelectCursor::primeInsert ( ) [inline, protected, 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 de QSqlCursor.

QSqlRecord * QSqlSelectCursor::primeInsert ( ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

QSqlRecord * QSqlSelectCursor::primeUpdate ( ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

QSqlRecord* QSqlSelectCursor::primeUpdate ( ) [inline, protected, 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 de QSqlCursor.

void QSqlSelectCursor::remove ( int  pos) [inline, protected, 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 QSqlCursor.

void QSqlSelectCursor::remove ( int  ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

bool QSqlSelectCursor::select ( ) [inline]

Reimplementado de QSqlCursor.

bool QSqlSelectCursor::select ( const QString ,
const QSqlIndex = QSqlIndex() 
) [protected, virtual]

Reimplementado de QSqlCursor.

bool QSqlSelectCursor::select ( const QString filter,
const QSqlIndex sort = QSqlIndex() 
) [protected, 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 de QSqlCursor.

bool QSqlSelectCursor::select ( ) [inline]

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 de QSqlCursor.

void QSqlSelectCursor::setFilter ( const QString ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::setFilter ( const QString filter) [inline, protected, 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 de QSqlCursor.

void QSqlSelectCursor::setGenerated ( const QString ,
bool   
) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::setGenerated ( const QString name,
bool  generated 
) [inline, protected, 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 QSqlCursor.

void QSqlSelectCursor::setGenerated ( int  i,
bool  generated 
) [inline, 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. Sets the generated flag for the field i to generated.

Ver también:
isGenerated()

Reimplementado de QSqlCursor.

void QSqlSelectCursor::setGenerated ( int  ,
bool   
) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::setMode ( int  ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::setMode ( int  mode) [inline, protected, 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 de QSqlCursor.

void QSqlSelectCursor::setName ( const QString ,
bool  = TRUE 
) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::setName ( const QString name,
bool  autopopulate = TRUE 
) [inline, protected, 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 de QSqlCursor.

void QSqlSelectCursor::setPrimaryIndex ( const QSqlIndex ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::setPrimaryIndex ( const QSqlIndex idx) [inline, protected, 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 de QSqlCursor.

void QSqlSelectCursor::setSort ( const QSqlIndex ) [inline, protected, virtual]

Reimplementado de QSqlCursor.

void QSqlSelectCursor::setSort ( const QSqlIndex sort) [inline, protected, 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 de QSqlCursor.

QSqlIndex QSqlSelectCursor::sort ( ) const [inline, protected]

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

Reimplementado de QSqlCursor.

QSqlIndex QSqlSelectCursor::sort ( ) const [inline, protected]

Reimplementado de QSqlCursor.

QString QSqlSelectCursor::toString ( const QString prefix = QString::null,
const QString sep = "," 
) const [inline, protected, virtual]

Reimplementado de QSqlCursor.

QString QSqlSelectCursor::toString ( const QString = QString::null,
const QString = "," 
) const [inline, protected, virtual]

Reimplementado de QSqlCursor.

int QSqlSelectCursor::update ( bool  invalidate = TRUE) [inline, protected, 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 de QSqlCursor.

int QSqlSelectCursor::update ( bool  = TRUE) [inline, protected, virtual]

Reimplementado de QSqlCursor.


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'