Q3SqlCursor Class Reference |
Constant | Value | Description |
---|---|---|
Q3SqlCursor::ReadOnly | 0 | the cursor can only SELECT records from the database. |
Q3SqlCursor::Insert | 1 | the cursor can INSERT records into the database. |
Q3SqlCursor::Update | 2 | the cursor can UPDATE records in the database. |
Q3SqlCursor::Delete | 4 | the cursor can DELETE records from the database. |
Q3SqlCursor::Writable | 7 | the cursor can INSERT, UPDATE and DELETE records in the database. |
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 Q3SqlCursor::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.
See also setName() and setMode().
Constructs a copy of other.
Destroys the object and frees any allocated resources.
Append a copy of field fieldInfo to the end of the cursor. Note that all references to the cursor edit buffer become invalidated.
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.
See also setCalculated().
Returns true if the cursor will perform deletes; otherwise returns false.
See also setMode().
Returns true if the cursor will perform inserts; otherwise returns false.
See also setMode().
Returns true if the cursor will perform updates; otherwise returns false.
See also setMode().
Removes all fields from the cursor. Note that all references to the cursor edit buffer become invalidated.
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:
Q3SqlCursor cur("prices"); cur.select("id=999"); if (cur.next()) { cur.primeDelete(); cur.del(); }
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.
See also primeDelete(), setMode(), and lastError().
This is an overloaded member function, provided for convenience.
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.
See also setMode() and lastError().
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.
See also primeInsert(), primeUpdate(), and primeDelete().
Executes the SQL query sql. Returns true of the cursor is active, otherwise returns false.
Returns the current filter, or an empty string if there is no current filter.
See also setFilter().
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.
See also QSqlIndex.
This is an overloaded member function, provided for convenience.
Returns an index based on fieldName.
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.
This is an overloaded member function, provided for convenience.
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.
Q3SqlCursor cur("prices"); QSqlRecord *buffer = cur.primeInsert(); buffer->setValue("id", 53981); buffer->setValue("name", "Thingy"); buffer->setValue("price", 105.75); cur.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.
See also setMode() and lastError().
Returns true if the field name exists and is calculated; otherwise returns false.
See also setCalculated().
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)
This is an overloaded member function, provided for convenience.
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)
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().
See also setMode().
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.
See also setTrimmed().
Returns the current cursor mode.
See also setMode().
Returns the name of the cursor.
See also setName().
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.
See also setPrimaryIndex().
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.
See also editBuffer() and del().
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.
See also editBuffer() and insert().
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.
See also editBuffer() and update().
Removes the field at pos. If pos does not exist, nothing happens. Note that all references to the cursor edit buffer become invalidated.
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(), previous() or next().
Example:
Q3SqlCursor 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.
Q3SqlCursor 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 ...
This is an overloaded member function, provided for convenience.
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(), previous() or next().
See also setSort() and setFilter().
This is an overloaded member function, provided for convenience.
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(), previous() or next().
This is an overloaded member function, provided for convenience.
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(), previous() or next(). This function is useful, for example, for retrieving data based upon a table's primary index:
Q3SqlCursor 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.
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.
See also isCalculated() and calculateField().
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.
See also filter().
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().
This is an overloaded member function, provided for convenience.
Sets the generated flag for the field i to generated.
Sets the cursor mode to mode. This value can be an OR'ed combination of Q3SqlCursor::Mode values. The default mode for a cursor is Q3SqlCursor::Writable.
Q3SqlCursor cur("Employee"); cur.setMode(Q3SqlCursor::Writable); // allow insert/update/delete ... cur.setMode(Q3SqlCursor::Insert | Q3SqlCursor::Update); // allow inserts and updates only ... cur.setMode(Q3SqlCursor::ReadOnly); // no inserts/updates/deletes allowed
See also mode().
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 Q3SqlCursor constructor documentation for more information.
See also name().
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.
See also primaryIndex(), update(), and del().
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.
See also sort().
Sets field name's trimmed status to trim. If the field name does not exist, nothing happens.
When a trimmed field of type string is read from the database any trailing (right-most) spaces are removed.
See also isTrimmed() and QVariant.
This is an overloaded member function, provided for convenience.
Sets the value for the field named name to val.
Returns the current sort, or an empty index if there is no current sort.
See also setSort().
This is an overloaded member function, provided for convenience.
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.
This is an overloaded member function, provided for convenience.
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.
This is an overloaded member function, provided for convenience.
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.
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:
Q3SqlCursor cur("prices"); cur.select("id=202"); if (cur.next()) { QSqlRecord *buffer = cur.primeUpdate(); double price = buffer->value("price").toDouble(); double newprice = price * 1.05; buffer->setValue("price", newprice); cur.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.
See also setMode() and lastError().
This is an overloaded member function, provided for convenience.
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.
See also primeUpdate(), setMode(), and lastError().
Returns the value of field number i.
This is an overloaded member function, provided for convenience.
Returns the value of the field named name.
Sets the cursor equal to other.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.1 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com