• PySide 模块
  • PySide.QtSql
  • 内容表

    上一话题

    QSql

    下一话题

    QSqlRecord

    QSqlResult

    概要

    虚函数

    详细描述

    PySide.QtSql.QSqlResult class provides an abstract interface for accessing data from specific SQL databases.

    Normally, you would use PySide.QtSql.QSqlQuery 而不是 PySide.QtSql.QSqlResult , since PySide.QtSql.QSqlQuery provides a generic wrapper for database-specific implementations of PySide.QtSql.QSqlResult .

    If you are implementing your own SQL driver (by subclassing PySide.QtSql.QSqlDriver ), you will need to provide your own PySide.QtSql.QSqlResult subclass that implements all the pure virtual functions and other virtual functions that you need.

    class PySide.QtSql. QSqlResult ( db )
    参数: db PySide.QtSql.QSqlDriver

    创建 PySide.QtSql.QSqlResult using database driver db . The object is initialized to an inactive state.

    PySide.QtSql.QSqlResult. BindingSyntax

    This enum type specifies the different syntaxes for specifying placeholders in prepared queries.

    常量 描述
    QSqlResult.PositionalBinding Use the ODBC-style positional syntax, with ”?” as placeholders.
    QSqlResult.NamedBinding Use the Oracle-style syntax with named placeholders (e.g., ”:id”)
    PySide.QtSql.QSqlResult. VirtualHookOperation
    PySide.QtSql.QSqlResult. addBindValue ( val , type )
    参数:
    • val – object
    • type PySide.QtSql.QSql.ParamType
    PySide.QtSql.QSqlResult. at ( )
    返回类型: PySide.QtCore.int

    Returns the current (zero-based) row position of the result. May return the special values QSql.BeforeFirstRow or QSql.AfterLastRow .

    PySide.QtSql.QSqlResult. bindValue ( placeholder , val , type )
    参数:
    • placeholder – unicode
    • val – object
    • type PySide.QtSql.QSql.ParamType
    PySide.QtSql.QSqlResult. bindValue ( pos , val , type )
    参数:
    • pos PySide.QtCore.int
    • val – object
    • type PySide.QtSql.QSql.ParamType
    PySide.QtSql.QSqlResult. bindValueType ( pos )
    参数: pos PySide.QtCore.int
    返回类型: PySide.QtSql.QSql.ParamType

    Returns the parameter type for the value bound at position index .

    PySide.QtSql.QSqlResult. bindValueType ( placeholder )
    参数: placeholder – unicode
    返回类型: PySide.QtSql.QSql.ParamType

    这是重载函数。

    Returns the parameter type for the value bound with the given placeholder name.

    PySide.QtSql.QSqlResult. bindingSyntax ( )
    返回类型: PySide.QtSql.QSqlResult.BindingSyntax

    Returns the binding syntax used by prepared queries.

    PySide.QtSql.QSqlResult. boundValue ( pos )
    参数: pos PySide.QtCore.int
    返回类型: object

    Returns the value bound at position index in the current record (row).

    PySide.QtSql.QSqlResult. boundValue ( placeholder )
    参数: placeholder – unicode
    返回类型: object

    这是重载函数。

    Returns the value bound by the given placeholder name in the current record (row).

    PySide.QtSql.QSqlResult. boundValueCount ( )
    返回类型: PySide.QtCore.int

    Returns the number of bound values in the result.

    PySide.QtSql.QSqlResult. boundValueName ( pos )
    参数: pos PySide.QtCore.int
    返回类型: unicode

    Returns the name of the bound value at position index in the current record (row).

    PySide.QtSql.QSqlResult. boundValues ( )
    返回类型:

    Returns a vector of the result's bound values for the current record (row).

    PySide.QtSql.QSqlResult. clear ( )

    Clears the entire result set and releases any associated resources.

    PySide.QtSql.QSqlResult. data ( i )
    参数: i PySide.QtCore.int
    返回类型: object

    Returns the data for field index in the current row as a PySide.QtCore.QVariant . This function is only called if the result is in an active state and is positioned on a valid record and index is non-negative. Derived classes must reimplement this function and return the value of field index ,或 QVariant() if it cannot be determined.

    PySide.QtSql.QSqlResult. detachFromResultSet ( )
    PySide.QtSql.QSqlResult. driver ( )
    返回类型: PySide.QtSql.QSqlDriver

    Returns the driver associated with the result. This is the object that was passed to the constructor.

    PySide.QtSql.QSqlResult. execBatch ( [ arrayBind=false ] )
    参数: arrayBind PySide.QtCore.bool
    返回类型: PySide.QtCore.bool

    Executes a prepared query in batch mode if the driver supports it, otherwise emulates a batch execution using PySide.QtSql.QSqlResult.bindValue() and exec() . QSqlDriver.hasFeature() can be used to find out whether a driver supports batch execution.

    Batch execution can be faster for large amounts of data since it reduces network roundtrips.

    For batch executions, bound values have to be provided as lists of variants ( QVariantList ).

    Each list must contain values of the same type. All lists must contain equal amount of values (rows).

    NULL values are passed in as typed QVariants ,例如 QVariant(QVariant::Int) for an integer NULL value.

    范例:

    q = QSqlQuery()
    q.prepare("insert into test (i1, i2, s) values (?, ?, ?)")
    col1 = [1, 3]
    col2 = [2, 4]
    col3 = ["hello", "world"]
    q.bindValue(0, col1)
    q.bindValue(1, col2)
    q.bindValue(2, col3)
    if not q.execBatch():
        print q.lastError()
    											

    Here, we insert two rows into a SQL table, with each row containing three values.

    另请参阅

    exec() QSqlDriver.hasFeature()

    PySide.QtSql.QSqlResult. exec_ ( )
    返回类型: PySide.QtCore.bool

    Executes the query, returning true if successful; otherwise returns false.

    PySide.QtSql.QSqlResult. executedQuery ( )
    返回类型: unicode

    Returns the query that was actually executed. This may differ from the query that was passed, for example if bound values were used with a prepared query and the underlying database doesn't support prepared queries.

    PySide.QtSql.QSqlResult. fetch ( i )
    参数: i PySide.QtCore.int
    返回类型: PySide.QtCore.bool

    Positions the result to an arbitrary (zero-based) row index .

    This function is only called if the result is in an active state. Derived classes must reimplement this function and position the result to the row index , and call PySide.QtSql.QSqlResult.setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

    PySide.QtSql.QSqlResult. fetchFirst ( )
    返回类型: PySide.QtCore.bool

    Positions the result to the first record (row 0) in the result.

    This function is only called if the result is in an active state. Derived classes must reimplement this function and position the result to the first record, and call PySide.QtSql.QSqlResult.setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

    PySide.QtSql.QSqlResult. fetchLast ( )
    返回类型: PySide.QtCore.bool

    Positions the result to the last record (last row) in the result.

    This function is only called if the result is in an active state. Derived classes must reimplement this function and position the result to the last record, and call PySide.QtSql.QSqlResult.setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

    PySide.QtSql.QSqlResult. fetchNext ( )
    返回类型: PySide.QtCore.bool

    Positions the result to the next available record (row) in the result.

    This function is only called if the result is in an active state. The default implementation calls PySide.QtSql.QSqlResult.fetch() with the next index. Derived classes can reimplement this function and position the result to the next record in some other way, and call PySide.QtSql.QSqlResult.setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

    PySide.QtSql.QSqlResult. fetchPrevious ( )
    返回类型: PySide.QtCore.bool

    Positions the result to the previous record (row) in the result.

    This function is only called if the result is in an active state. The default implementation calls PySide.QtSql.QSqlResult.fetch() with the previous index. Derived classes can reimplement this function and position the result to the next record in some other way, and call PySide.QtSql.QSqlResult.setAt() with an appropriate value. Return true to indicate success, or false to signify failure.

    PySide.QtSql.QSqlResult. handle ( )
    返回类型: object

    Returns the low-level database handle for this result set wrapped in a PySide.QtCore.QVariant or an invalid PySide.QtCore.QVariant if there is no handle.

    警告

    Use this with uttermost care and only if you know what you're doing.

    警告

    The handle returned here can become a stale pointer if the result is modified (for example, if you clear it).

    警告

    The handle can be NULL if the result was not executed yet.

    The handle returned here is database-dependent, you should query the type name of the variant before accessing it.

    This example retrieves the handle for a sqlite result:

    query = QSqlQuery ...
    v = query.result().handle()
    if v.isValid() and (v.typeName() == "sqlite3_stmt*"):
        # v.data() returns a pointer to the handle
        handle = v.data()
        if handle != 0: # check that it is not NULL
            ...
    										

    This snippet returns the handle for PostgreSQL or MySQL:

    if v.typeName() == "PGresult*":
        handle = v.data()
        if handle != 0 ...
    if v.typeName() == "MYSQL_STMT*":
        handle = v.data()
        if handle != 0 ...
    }
    										

    另请参阅

    QSqlDriver.handle()

    PySide.QtSql.QSqlResult. hasOutValues ( )
    返回类型: PySide.QtCore.bool

    Returns true if at least one of the query's bound values is a QSql::Out QSql.InOut ;否则返回 false。

    PySide.QtSql.QSqlResult. isActive ( )
    返回类型: PySide.QtCore.bool

    Returns true if the result has records to be retrieved; otherwise returns false.

    PySide.QtSql.QSqlResult. isForwardOnly ( )
    返回类型: PySide.QtCore.bool

    Returns true if you can only scroll forward through the result set; otherwise returns false.

    PySide.QtSql.QSqlResult. isNull ( i )
    参数: i PySide.QtCore.int
    返回类型: PySide.QtCore.bool

    Returns true if the field at position index in the current row is null; otherwise returns false.

    PySide.QtSql.QSqlResult. isSelect ( )
    返回类型: PySide.QtCore.bool

    Returns true if the current result is from a SELECT statement; otherwise returns false.

    PySide.QtSql.QSqlResult. isValid ( )
    返回类型: PySide.QtCore.bool

    Returns true if the result is positioned on a valid record (that is, the result is not positioned before the first or after the last record); otherwise returns false.

    PySide.QtSql.QSqlResult. lastError ( )
    返回类型: PySide.QtSql.QSqlError

    Returns the last error associated with the result.

    PySide.QtSql.QSqlResult. lastInsertId ( )
    返回类型: object

    Returns the object ID of the most recent inserted row if the database supports it. An invalid PySide.QtCore.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.

    Note that for Oracle databases the row's ROWID will be returned, while for MySQL databases the row's auto-increment field will be returned.

    PySide.QtSql.QSqlResult. lastQuery ( )
    返回类型: unicode

    Returns the current SQL query text, or an empty string if there isn't one.

    PySide.QtSql.QSqlResult. nextResult ( )
    返回类型: PySide.QtCore.bool
    PySide.QtSql.QSqlResult. numRowsAffected ( )
    返回类型: PySide.QtCore.int

    Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or if the query is a SELECT 语句。

    PySide.QtSql.QSqlResult. numericalPrecisionPolicy ( )
    返回类型: PySide.QtSql.QSql.NumericalPrecisionPolicy
    PySide.QtSql.QSqlResult. prepare ( query )
    参数: query – unicode
    返回类型: PySide.QtCore.bool

    Prepares the given query for execution; the query will normally use placeholders so that it can be executed repeatedly. Returns true if the query is prepared successfully; otherwise returns false.

    另请参阅

    exec()

    PySide.QtSql.QSqlResult. record ( )
    返回类型: PySide.QtSql.QSqlRecord

    Returns the current record if the query is active; otherwise returns an empty PySide.QtSql.QSqlRecord .

    The default implementation always returns an empty PySide.QtSql.QSqlRecord .

    PySide.QtSql.QSqlResult. reset ( sqlquery )
    参数: sqlquery – unicode
    返回类型: PySide.QtCore.bool

    Sets the result to use the SQL statement query for subsequent data retrieval.

    Derived classes must reimplement this function and apply the query to the database. This function is only called after the result is set to an inactive state and is positioned before the first record of the new result. Derived classes should return true if the query was successful and ready to be used, or false otherwise.

    PySide.QtSql.QSqlResult. resetBindCount ( )
    PySide.QtSql.QSqlResult. savePrepare ( sqlquery )
    参数: sqlquery – unicode
    返回类型: PySide.QtCore.bool

    Prepares the given query , using the underlying database functionality where possible. Returns true if the query is prepared successfully; otherwise returns false.

    PySide.QtSql.QSqlResult. setActive ( a )
    参数: a PySide.QtCore.bool

    This function is provided for derived classes to set the internal active state to active .

    PySide.QtSql.QSqlResult. setAt ( at )
    参数: at PySide.QtCore.int

    This function is provided for derived classes to set the internal (zero-based) row position to index .

    PySide.QtSql.QSqlResult. setForwardOnly ( forward )
    参数: forward PySide.QtCore.bool

    Sets forward only mode to forward 。若 forward is true, only PySide.QtSql.QSqlResult.fetchNext() is allowed for navigating the results. Forward only mode needs much less memory since results do not have to be cached. By default, this feature is disabled.

    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. PySide.QtSql.QSqlResult.isForwardOnly() will always return the correct status of the result set.

    注意

    Calling setForwardOnly after execution of the query will result in unexpected results at best, and crashes at worst.

    PySide.QtSql.QSqlResult. setLastError ( e )
    参数: e PySide.QtSql.QSqlError

    This function is provided for derived classes to set the last error to error .

    PySide.QtSql.QSqlResult. setNumericalPrecisionPolicy ( policy )
    参数: policy PySide.QtSql.QSql.NumericalPrecisionPolicy
    PySide.QtSql.QSqlResult. setQuery ( query )
    参数: query – unicode

    Sets the current query for the result to query . You must call PySide.QtSql.QSqlResult.reset() to execute the query on the database.

    PySide.QtSql.QSqlResult. setSelect ( s )
    参数: s PySide.QtCore.bool

    This function is provided for derived classes to indicate whether or not the current statement is a SQL SELECT statement. The select parameter should be true if the statement is a SELECT statement; otherwise it should be false.

    PySide.QtSql.QSqlResult. size ( )
    返回类型: PySide.QtCore.int

    Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELECT 语句。