PySide6.QtSql.QSqlQuery¶
- class QSqlQuery¶
The
QSqlQueryclass provides a means of executing and manipulating SQL statements. More…Synopsis¶
Properties¶
Methods¶
def
__init__()def
addBindValue()def
at()def
bindValue()def
boundValue()def
boundValueName()def
boundValues()def
clear()def
driver()def
exec()def
execBatch()def
exec_()def
executedQuery()def
finish()def
first()def
isActive()def
isForwardOnly()def
isNull()def
isSelect()def
isValid()def
last()def
lastError()def
lastInsertId()def
lastQuery()def
next()def
nextResult()def
prepare()def
previous()def
record()def
result()def
seek()def
setForwardOnly()def
size()def
swap()def
value()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
QSqlQueryencapsulates the functionality involved in creating, navigating and retrieving data from SQL queries which are executed on aQSqlDatabase. It can be used to execute DML (data manipulation language) statements, such asSELECT,INSERT,UPDATEandDELETE, as well as DDL (data definition language) statements, such asCREATETABLE. It can also be used to execute database-specific commands which are not standard SQL (e.g.SET DATESTYLE=ISOfor PostgreSQL).Successfully executed SQL statements set the query’s state to active so that
isActive()returnstrue. Otherwise the query’s state is set to inactive. In either case, when executing a new SQL statement, the query is positioned on an invalid record. An active query must be navigated to a valid record (so thatisValid()returnstrue) before values can be retrieved.For some databases, if an active query that is a
SELECTstatement exists when you callcommit()orrollback(), the commit or rollback will fail. SeeisActive()for details.Navigating records is performed with the following functions:
These functions allow the programmer to move forward, backward or arbitrarily through the records returned by the query. If you only need to move forward through the results (e.g., by using
next()), you can usesetForwardOnly(), which will save a significant amount of memory overhead and improve performance on some databases. Once an active query is positioned on a valid record, data can be retrieved usingvalue(). All data is transferred from the SQL backend using QVariants.For example:
query = QSqlQuery("SELECT country FROM artist") while query.next(): country = query.value(0).toString() doSomething(country)
To access the data returned by a query, use value(int). Each field in the data returned by a
SELECTstatement is accessed by passing the field’s position in the statement, starting from 0. This makes usingSELECT *queries inadvisable because the order of the fields returned is indeterminate.For the sake of efficiency, there are no functions to access a field by name (unless you use prepared queries with names, as explained below). To convert a field name into an index, use
record().indexOf(), for example:query = QSqlQuery("SELECT * FROM artist") fieldNo = query.record().indexOf("country") while query.next(): country = query.value(fieldNo).toString() doSomething(country)
QSqlQuerysupports prepared query execution and the binding of parameter values to placeholders. Some databases don’t support these features, so for those, Qt emulates the required functionality. For example, the Oracle and ODBC drivers have proper prepared query support, and Qt makes use of it; but for databases that don’t have this support, Qt implements the feature itself, e.g. by replacing placeholders with actual values when a query is executed. UsenumRowsAffected()to find out how many rows were affected by a non-SELECTquery, andsize()to find how many were retrieved by aSELECT.Oracle databases identify placeholders by using a colon-name syntax, e.g
:name. ODBC simply uses?characters. Qt supports both syntaxes, with the restriction that you can’t mix them in the same query.You can retrieve the values of all the fields in a single variable using
boundValues().Note
Not all SQL operations support binding values. Refer to your database system’s documentation to check their availability.
Approaches to Binding Values¶
Below we present the same example using each of the four different binding approaches, as well as one example of binding values to a stored procedure.
Named binding using named placeholders:
query = QSqlQuery() query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (:id, :forename, :surname)") query.bindValue(":id", 1001) query.bindValue(":forename", "Bart") query.bindValue(":surname", "Simpson") query.exec()
Positional binding using named placeholders:
query = QSqlQuery() query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (:id, :forename, :surname)") query.bindValue(0, 1001) query.bindValue(1, "Bart") query.bindValue(2, "Simpson") query.exec()
Binding values using positional placeholders (version 1):
query = QSqlQuery() query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (?, ?, ?)") query.bindValue(0, 1001) query.bindValue(1, "Bart") query.bindValue(2, "Simpson") query.exec()
Binding values using positional placeholders (version 2):
query = QSqlQuery() query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (?, ?, ?)") query.addBindValue(1001) query.addBindValue("Bart") query.addBindValue("Simpson") query.exec()
Binding values to a stored procedure:
This code calls a stored procedure called
AsciiToInt(), passing it a character through its in parameter, and taking its result in the out parameter.query = QSqlQuery() query.prepare("CALL AsciiToInt(?, ?)") query.bindValue(0, "A") query.bindValue(1, 0, QSql.Out) query.exec() i = query.boundValue(1).toInt() # i is 65
Note that unbound parameters will retain their values.
Stored procedures that uses the return statement to return values, or return multiple result sets, are not fully supported. For specific details see SQL Database Drivers .
Warning
You must load the SQL driver and open the connection before a
QSqlQueryis created. Also, the connection must remain open while the query exists; otherwise, the behavior ofQSqlQueryis undefined.See also
QSqlDatabaseQSqlQueryModelQSqlTableModelQVariant- class BatchExecutionMode¶
Constant
Description
QSqlQuery.BatchExecutionMode.ValuesAsRows
Updates multiple rows. Treats every entry in a QVariantList as a value for updating the next row.
QSqlQuery.BatchExecutionMode.ValuesAsColumns
Updates a single row. Treats every entry in a QVariantList as a single value of an array type.
Note
Properties can be used directly when
from __feature__ import true_propertyis used or via accessor functions otherwise.- property forwardOnlyᅟ: bool¶
This property holds the forward only mode. If
forwardis true, onlynext()andseek()with positive values, are allowed for navigating the results.Forward only mode can be (depending on the driver) more memory efficient since results do not need to be cached. It will also improve performance on some databases. For this to be true, you must call
setForwardOnly()before the query is prepared or executed. Note that the constructor that takes a query and a database may execute the query.Forward only mode is off by default.
Setting forward only to false is a suggestion to the database engine, which has the final say on whether a result set is forward only or scrollable.
isForwardOnly()will always return the correct status of the result set.Note
Calling
setForwardOnlyafter execution of the query will result in unexpected results at best, and crashes at worst.Note
To make sure the forward-only query completed successfully, the application should check
lastError()for an error not only after executing the query, but also after navigating the query results.Warning
PostgreSQL: While navigating the query results in forward-only mode, do not execute any other SQL command on the same database connection. This will cause the query results to be lost.
- Access functions:
- property numericalPrecisionPolicyᅟ: QSql.NumericalPrecisionPolicy¶
Instruct the database driver to return numerical values with a precision specified by
precisionPolicy.The Oracle driver, for example, can retrieve numerical values as strings to prevent the loss of precision. If high precision doesn’t matter, use this method to increase execution speed by bypassing string conversions.
Note: Drivers that don’t support fetching numerical values with low precision will ignore the precision policy. You can use
hasFeature()to find out whether a driver supports this feature.Note: Setting the precision policy doesn’t affect the currently active query. Call
exec(QString)orprepare()in order to activate the policy.- Access functions:
- property positionalBindingEnabledᅟ: bool¶
This property enables or disables the positional
bindingfor this query, depending onenable(default istrue). Disabling positional bindings is useful if the query itself contains a ‘?’ which must not be handled as a positional binding parameter but, for example, as a JSON operator for a PostgreSQL database.This property will have no effect when the database has native support for positional bindings with question marks (see also
PositionalPlaceholders).- Access functions:
- __init__(r)¶
- Parameters:
r –
QSqlResult
Constructs a
QSqlQueryobject which uses theQSqlResultresultto communicate with a database.- __init__(db)
- Parameters:
db –
QSqlDatabase
Constructs a
QSqlQueryobject using the databasedb. Ifdbis invalid, the application’s default database will be used.See also
- __init__(other)
- Parameters:
other –
QSqlQuery
Note
This function is deprecated.
Constructs a copy of
other.QSqlQuerycannot be meaningfully copied. Prepared statements, bound values and so on will not work correctly, depending on your database driver (for instance, changing the copy will affect the original). TreatQSqlQueryas a move-only type instead.- __init__([query=""[, db=QSqlDatabase()]])
- Parameters:
query – str
db –
QSqlDatabase
Constructs a
QSqlQueryobject using the SQLqueryand the databasedb. Ifdbis not specified, or is invalid, the application’s default database is used. Ifqueryis not an empty string, it will be executed.See also
- addBindValue(val[, type=QSql.In])¶
- Parameters:
val – object
type – Combination of
ParamTypeFlag
Adds the value
valto the list of values when using positional value binding. The order of the addBindValue() calls determines which placeholder a value will be bound to in the prepared query. IfparamTypeisOutorInOut, the placeholder will be overwritten with data from the database after theexec()call.To bind a NULL value, use a null QVariant; for example, use
QVariant(QMetaType::fromType<QString>())if you are binding a string.See also
- at()¶
- Return type:
int
Returns the current internal position of the query. The first record is at position zero. If the position is invalid, the function returns
BeforeFirstRoworAfterLastRow, which are special negative values.See also
previous()next()first()last()seek()isActive()isValid()- bindValue(placeholder, val[, type=QSql.In])¶
- Parameters:
placeholder – str
val – object
type – Combination of
ParamTypeFlag
Set the placeholder
placeholderto be bound to valuevalin the prepared statement. Note that the placeholder mark (e.g:) must be included when specifying the placeholder name. IfparamTypeisOutorInOut, the placeholder will be overwritten with data from the database after theexec()call. In this case, sufficient space must be pre-allocated to store the result into.To bind a NULL value, use a null QVariant; for example, use
QVariant(QMetaType::fromType<QString>())if you are binding a string.- bindValue(pos, val[, type=QSql.In])
- Parameters:
pos – int
val – object
type – Combination of
ParamTypeFlag
Set the placeholder in position
posto be bound to valuevalin the prepared statement. Field numbering starts at 0. IfparamTypeisOutorInOut, the placeholder will be overwritten with data from the database after theexec()call.- boundValue(placeholder)¶
- Parameters:
placeholder – str
- Return type:
object
Returns the value for the
placeholder.See also
- boundValue(pos)
- Parameters:
pos – int
- Return type:
object
Returns the value for the placeholder at position
pos.See also
- boundValueName(pos)¶
- Parameters:
pos – int
- Return type:
str
Returns the bound value name at position
pos.The order of the list is in binding order, irrespective of whether named or positional binding is used.
See also
- boundValueNames()¶
- Return type:
list of strings
Returns the names of all bound values.
The order of the list is in binding order, irrespective of whether named or positional binding is used.
See also
- boundValues()¶
- Return type:
.list of QVariant
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Returns a list of bound values.
The order of the list is in binding order, irrespective of whether named or positional binding is used.
The bound values can be examined in the following way:
list = query.boundValues() for i in range(0, list.size()): print(i, ":", list.at(i).toString())
- clear()¶
Clears the result set and releases any resources held by the query. Sets the query state to inactive. You should rarely if ever need to call this function.
- driver()¶
- Return type:
Returns the database driver associated with the query.
- exec()¶
- Return type:
bool
Executes a previously prepared SQL query. Returns
trueif the query executed successfully; otherwise returnsfalse.Note that the last error for this query is reset when exec() is called.
- exec(query)
- Parameters:
query – str
- Return type:
bool
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Executes the SQL in
query. Returnstrueand sets the query state toactiveif the query was successful; otherwise returnsfalse. Thequerystring 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 (for example, using
next()).Note that the last error for this query is reset when
exec()is called.For SQLite, the query string can contain only one statement at a time. If more than one statement is given, the function returns
false.Example:
query = QSqlQuery() query.exec("INSERT INTO employee (id, name, salary) " "VALUES (1001, 'Thad Beaumont', 65000)")
See also
isActive()isValid()next()previous()first()last()seek()- execBatch([mode=QSqlQuery.BatchExecutionMode.ValuesAsRows])¶
- Parameters:
mode –
BatchExecutionMode- Return type:
bool
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Executes a previously prepared SQL query in a batch. All the bound parameters have to be lists of variants. If the database doesn’t support batch executions, the driver will simulate it using conventional
exec()calls.Returns
trueif the query is executed successfully; otherwise returnsfalse.Example:
q = QSqlQuery() q.prepare("insert into myTable values (?, ?)") ints = QVariantList() ints << 1 << 2 << 3 << 4 q.addBindValue(ints) names = QVariantList() names << "Harald" << "Boris" << "Trond" << QVariant(QMetaType.fromType<QString>()) q.addBindValue(names) if not q.execBatch(): print(q.lastError())
The example above inserts four new rows into
myTable:1 Harald 2 Boris 3 Trond 4 NULL
To bind NULL values, a null QVariant of the relevant type has to be added to the bound QVariantList; for example,
QVariant(QMetaType::fromType<QString>())should be used if you are using strings.Note
Every bound QVariantList must contain the same amount of variants.
Note
The type of the QVariants in a list must not change. For example, you cannot mix integer and string variants within a QVariantList.
The
modeparameter indicates how the bound QVariantList will be interpreted. IfmodeisValuesAsRows, every variant within the QVariantList will be interpreted as a value for a new row.ValuesAsColumnsis a special case for the Oracle driver. In this mode, every entry within a QVariantList will be interpreted as array-value for an IN or OUT value within a stored procedure. Note that this will only work if the IN or OUT value is a table-type consisting of only one column of a basic type, for exampleTYPE myType IS TABLE OF VARCHAR(64) INDEX BY BINARY_INTEGER;See also
- exec_()¶
- Return type:
bool
- exec_(arg__1)
- Parameters:
arg__1 – str
- Return type:
bool
- executedQuery()¶
- Return type:
str
Returns the last query that was successfully executed.
In most cases this function returns the same string as
lastQuery(). If a prepared query with placeholders is executed on a DBMS that does not support it, the preparation of this query is emulated. The placeholders in the original query are replaced with their bound values to form a new query. This function returns the modified query. It is mostly useful for debugging purposes.See also
- finish()¶
Instruct the database driver that no more data will be fetched from this query until it is re-executed. There is normally no need to call this function, but it may be helpful in order to free resources such as locks or cursors if you intend to re-use the query at a later time.
Sets the query to inactive. Bound values retain their values.
See also
- first()¶
- Return type:
bool
Retrieves the first record in the result, if available, and positions the query on the retrieved record. Note that the result must be in the
activestate andisSelect()must return true before calling this function or it will do nothing and return false. Returnstrueif successful. If unsuccessful the query position is set to an invalid position and false is returned.See also
- isActive()¶
- Return type:
bool
Returns
trueif the query is active. An activeQSqlQueryis one that has beenexec()'dsuccessfully but not yet finished with. When you are finished with an active query, you can make the query inactive by callingfinish()orclear(), or you can delete theQSqlQueryinstance.Note
Of particular interest is an active query that is a
SELECTstatement. For some databases that support transactions, an active query that is aSELECTstatement can cause acommit()or arollback()to fail, so before committing or rolling back, you should make your activeSELECTstatement query inactive using one of the ways listed above.See also
- isForwardOnly()¶
- Return type:
bool
Returns
forwardOnly.Getter of property
forwardOnlyᅟ.- isNull(name)¶
- Parameters:
name – str
- Return type:
bool
This is an overloaded function.
Returns
trueif there is no field with thisname; otherwise returnsisNull(int index) for the corresponding field index.This overload is less efficient than
isNull()Note
In Qt versions prior to 6.8, this function took QString, not QAnyStringView.
- isNull(field)
- Parameters:
field – int
- Return type:
bool
Returns
trueif the query is notactive, the query is not positioned on a valid record, there is no suchfield, or thefieldis null; otherwisefalse. Note that for some drivers, isNull() will not return accurate information until after an attempt is made to retrieve data.See also
- isPositionalBindingEnabled()¶
- Return type:
bool
Returns
positionalBindingEnabled.See also
positionalBindingEnabledGetter of property
positionalBindingEnabledᅟ.- isSelect()¶
- Return type:
bool
Returns
trueif the current query is aSELECTstatement; otherwise returnsfalse.- isValid()¶
- Return type:
bool
Returns
trueif the query is currently positioned on a valid record; otherwise returnsfalse.- last()¶
- Return type:
bool
Retrieves the last record in the result, if available, and positions the query on the retrieved record. Note that the result must be in the
activestate andisSelect()must return true before calling this function or it will do nothing and return false. Returnstrueif successful. If unsuccessful the query position is set to an invalid position and false is returned.See also
Returns error information about the last error (if any) that occurred with this query.
See also
- lastInsertId()¶
- Return type:
object
Returns the object ID of the most recent inserted row if the database supports it. An invalid QVariant will be returned if the query did not insert any value or if the database does not report the id back. If more than one row was touched by the insert, the behavior is undefined.
For MySQL databases the row’s auto-increment field will be returned.
Note
For this function to work in PSQL, the table must contain OIDs, which may not have been created by default. Check the
default_with_oidsconfiguration variable to be sure.See also
- lastQuery()¶
- Return type:
str
Returns the text of the current query being used, or an empty string if there is no current query text.
See also
- next()¶
- Return type:
bool
Retrieves the next record in the result, if available, and positions the query on the retrieved record. Note that the result must be in the
activestate andisSelect()must return true before calling this function or it will do nothing and return false.The following rules apply:
If the result is currently located before the first record, e.g. immediately after a query is executed, an attempt is made to retrieve the first record.
If the result is currently located after the last record, there is no change and false is returned.
If the result is located somewhere in the middle, an attempt is made to retrieve the next record.
If the record could not be retrieved, the result is positioned after the last record and false is returned. If the record is successfully retrieved, true is returned.
See also
- nextResult()¶
- Return type:
bool
Discards the current result set and navigates to the next if available.
Some databases are capable of returning multiple result sets for stored procedures or SQL batches (a query strings that contains multiple statements). If multiple result sets are available after executing a query this function can be used to navigate to the next result set(s).
If a new result set is available this function will return true. The query will be repositioned on an invalid record in the new result set and must be navigated to a valid record before data values can be retrieved. If a new result set isn’t available the function returns
falseand the query is set to inactive. In any case the old result set will be discarded.When one of the statements is a non-select statement a count of affected rows may be available instead of a result set.
Note that some databases, i.e. Microsoft SQL Server, requires non-scrollable cursors when working with multiple result sets. Some databases may execute all statements at once while others may delay the execution until the result set is actually accessed, and some databases may have restrictions on which statements are allowed to be used in a SQL batch.
See also
hasFeature()forwardOnlynext()isSelect()numRowsAffected()isActive()lastError()- numRowsAffected()¶
- Return type:
int
Returns the number of rows affected by the result’s SQL statement, or -1 if it cannot be determined. Note that for
SELECTstatements, the value is undefined; usesize()instead. If the query is notactive, -1 is returned.See also
- numericalPrecisionPolicy()¶
- Return type:
Returns the numericalPrecisionPolicy.
See also
Getter of property
numericalPrecisionPolicyᅟ.- prepare(query)¶
- Parameters:
query – str
- Return type:
bool
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Prepares the SQL query
queryfor execution. Returnstrueif the query is prepared successfully; otherwise returnsfalse.The query may contain placeholders for binding values. Both Oracle style colon-name (e.g.,
:surname), and ODBC style (?) placeholders are supported; but they cannot be mixed in the same query. See theDetailed Descriptionfor examples.Portability notes: Some databases choose to delay preparing a query until it is executed the first time. In this case, preparing a syntactically wrong query succeeds, but every consecutive
exec()will fail. When the database does not support named placeholders directly, the placeholder can only contain characters in the range [a-zA-Z0-9_].For SQLite, the query string can contain only one statement at a time. If more than one statement is given, the function returns
false.Example:
query = QSqlQuery() query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (:id, :forename, :surname)") query.bindValue(":id", 1001) query.bindValue(":forename", "Bart") query.bindValue(":surname", "Simpson") query.exec()
See also
- previous()¶
- Return type:
bool
Retrieves the previous record in the result, if available, and positions the query on the retrieved record. Note that the result must be in the
activestate andisSelect()must return true before calling this function or it will do nothing and return false.The following rules apply:
If the result is currently located before the first record, there is no change and false is returned.
If the result is currently located after the last record, an attempt is made to retrieve the last record.
If the result is somewhere in the middle, an attempt is made to retrieve the previous record.
If the record could not be retrieved, the result is positioned before the first record and false is returned. If the record is successfully retrieved, true is returned.
- record()¶
- Return type:
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Returns a
QSqlRecordcontaining the field information for the current query. If the query points to a valid row (isValid()returns true), the record is populated with the row’s values. An empty record is returned when there is no active query (isActive()returns false).To retrieve values from a query,
value()should be used since its index-based lookup is faster.In the following example, a
SELECT * FROMquery is executed. Since the order of the columns is not defined,indexOf()is used to obtain the index of a column.q = QSqlQuery("select * from employees") rec = q.record() print("Number of columns: ", rec.count()) nameCol = rec.indexOf("name") # index of the field "name" while q.next(): print(q.value(nameCol).toString()) # output all names
See also
- result()¶
- Return type:
Returns the result associated with the query.
- seek(i[, relative=false])¶
- Parameters:
i – int
relative – bool
- Return type:
bool
Retrieves the record at position
index, if available, and positions the query on the retrieved record. The first record is at position 0. Note that the query must be in anactivestate andisSelect()must return true before calling this function.If
relativeis false (the default), the following rules apply:If
indexis negative, the result is positioned before the first record and false is returned.Otherwise, an attempt is made to move to the record at position
index. If the record at positionindexcould not be retrieved, the result is positioned after the last record and false is returned. If the record is successfully retrieved, true is returned.
If
relativeis true, the following rules apply:If the result is currently positioned before the first record and:
indexis negative or zero, there is no change, and false is returned.indexis positive, an attempt is made to position the result at absolute positionindex- 1, following the sames rule for non relative seek, above.
If the result is currently positioned after the last record and:
indexis positive or zero, there is no change, and false is returned.indexis negative, an attempt is made to position the result atindex+ 1 relative position from last record, following the rule below.
If the result is currently located somewhere in the middle, and the relative offset
indexmoves the result below zero, the result is positioned before the first record and false is returned.Otherwise, an attempt is made to move to the record
indexrecords ahead of the current record (orindexrecords behind the current record ifindexis negative). If the record at offsetindexcould not be retrieved, the result is positioned after the last record ifindex>= 0, (or before the first record ifindexis negative), and false is returned. If the record is successfully retrieved, true is returned.
See also
- setForwardOnly(forward)¶
- Parameters:
forward – bool
Sets
forwardOnlytoforward.See also
isForwardOnly()forwardOnlynext()seek()Setter of property
forwardOnlyᅟ.- setNumericalPrecisionPolicy(precisionPolicy)¶
- Parameters:
precisionPolicy –
NumericalPrecisionPolicy
Sets
numericalPrecisionPolicytoprecisionPolicy.See also
Setter of property
numericalPrecisionPolicyᅟ.- setPositionalBindingEnabled(enable)¶
- Parameters:
enable – bool
Sets
positionalBindingEnabledtoenable.See also
isPositionalBindingEnabled()positionalBindingEnabledSetter of property
positionalBindingEnabledᅟ.- size()¶
- Return type:
int
Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or if the database does not support reporting information about query sizes. Note that for non-
SELECTstatements (isSelect()returnsfalse), size() will return -1. If the query is not active (isActive()returnsfalse), -1 is returned.To determine the number of rows affected by a non-
SELECTstatement, usenumRowsAffected().See also
Swaps this query with
other. This operation is very fast and never fails.- value(name)¶
- Parameters:
name – str
- Return type:
object
This is an overloaded function.
Returns the value of the field called
namein the current record. If fieldnamedoes not exist an invalid variant is returned.This overload is less efficient than
value()Note
In Qt versions prior to 6.8, this function took QString, not QAnyStringView.
- value(i)
- Parameters:
i – int
- Return type:
object
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Returns the value of field
indexin the current record.The fields are numbered from left to right using the text of the
SELECTstatement, e.g. inforename, = SELECT()
field 0 is
forenameand field 1 issurname. UsingSELECT *is not recommended because the order of the fields in the query is undefined.An invalid QVariant is returned if field
indexdoes not exist, if the query is inactive, or if the query is positioned on an invalid record.See also
previous()next()first()last()seek()isActive()isValid()