Eneboo - Documentación para desarrolladores
|
The QSqlSelectCursor class provides browsing of general SQL SELECT statements. Más...
#include <qsqlselectcursor.h>
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(); ...
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 | ( | ) |
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.
Reimplementado de QSqlCursor.
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.
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.
Reimplementado de QSqlCursor.
QSqlRecord * QSqlSelectCursor::editBuffer | ( | bool | = FALSE | ) | [inline, protected, virtual] |
Reimplementado de QSqlCursor.
Reimplementado de QSqlCursor.
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.
Reimplementado de QSqlCursor.
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.
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.
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.
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.
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.
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.
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.
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.
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().
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.
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().
Reimplementado de QSqlCursor.
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.
Reimplementado de QSqlCursor.
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.
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.
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.
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.
Reimplementado de QSqlCursor.
Reimplementado de QSqlCursor.