<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # QSqlQuery Class Reference ## [[QtSql](index.htm) module] 該QSqlQuery類提供執行和操作的SQL語句的方法。[More...](#details) ### Types * `enum BatchExecutionMode { ValuesAsRows, ValuesAsColumns }` ### Methods * `__init__ (self, QSqlResult?r)` * `__init__ (self, QString?query?=?QString(), QSqlDatabase?db?=?QSqlDatabase())` * `__init__ (self, QSqlDatabase?db)` * `__init__ (self, QSqlQuery?other)` * `addBindValue (self, QVariant?val, QSql.ParamType?type?=?QSql.In)` * `int at (self)` * `bindValue (self, QString?placeholder, QVariant?val, QSql.ParamType?type?=?QSql.In)` * `bindValue (self, int?pos, QVariant?val, QSql.ParamType?type?=?QSql.In)` * `QVariant boundValue (self, QString?placeholder)` * `QVariant boundValue (self, int?pos)` * `dict-of-QString-QVariant boundValues (self)` * `clear (self)` * `QSqlDriver driver (self)` * `bool exec_ (self, QString?query)` * `bool exec_ (self)` * `bool execBatch (self, BatchExecutionMode?mode?=?QSqlQuery.ValuesAsRows)` * `QString executedQuery (self)` * `finish (self)` * `bool first (self)` * `bool isActive (self)` * `bool isForwardOnly (self)` * `bool isNull (self, int?field)` * `bool isSelect (self)` * `bool isValid (self)` * `bool last (self)` * `QSqlError lastError (self)` * `QVariant lastInsertId (self)` * `QString lastQuery (self)` * `bool next (self)` * `bool nextResult (self)` * `QSql.NumericalPrecisionPolicy numericalPrecisionPolicy (self)` * `int numRowsAffected (self)` * `bool prepare (self, QString?query)` * `bool previous (self)` * `QSqlRecord record (self)` * `QSqlResult result (self)` * `bool seek (self, int?index, bool?relative?=?False)` * `setForwardOnly (self, bool?forward)` * `setNumericalPrecisionPolicy (self, QSql.NumericalPrecisionPolicy?precisionPolicy)` * `int size (self)` * `QVariant value (self, int?i)` * * * ## Detailed Description 該QSqlQuery類提供執行和操作的SQL語句的方法。 QSqlQuery封裝這是在執行涉及從SQL查詢創建,瀏覽和檢索數據的功能[QSqlDatabase](qsqldatabase.html)。它可以被用來執行DML (數據操縱語言)語句,如`SELECT`,`INSERT`,`UPDATE`和`DELETE`,以及DDL (數據定義語言)語句,如`CREATE` `TABLE`。它也可以被用來執行特定于數據庫的命令而不是標準的SQL (例如`SET DATESTYLE=ISO`PostgreSQL的) 。 成功執行的SQL語句設置查詢的狀態為主動,使[isActive](qsqlquery.html#isActive)( )返回True 。否則,查詢的狀態設置為無效。在任一情況下,執行一個新的SQL語句時,查詢被定位在一個無效的記錄。一個活躍的查詢必須被導航到一個有效的記錄(使[isValid](qsqlquery.html#isValid)( )值可以被檢索之前返回True ) 。 對于某些數據庫,如果積極的查詢,它是一個`SELECT`當你調用語句存在[commit()](qsqldatabase.html#commit) or [rollback()](qsqldatabase.html#rollback),在提交或回滾將失敗。看[isActive](qsqlquery.html#isActive)( )了解詳情。 導航記錄的是具有以下功能進行: * [next](qsqlquery.html#next)() * [previous](qsqlquery.html#previous)() * [first](qsqlquery.html#first)() * [last](qsqlquery.html#last)() * [seek](qsqlquery.html#seek)() 這些功能使程序員可以前進,后退或者擅自通過查詢返回的記錄。如果你只需要向前移動的結果(例如,通過使用[next](qsqlquery.html#next)( ) ) ,則可以使用[setForwardOnly](qsqlquery.html#setForwardOnly)( ) ,這將節省一個顯著的內存開銷,提高對某些數據庫的性能。一旦活動查詢被定位在一個有效的記錄,數據可以使用檢索[value](qsqlquery.html#value)( ) 。所有數據從SQL后端使用轉[QVariants](index.htm#qvariants)。 例如: ``` QSqlQuery query("SELECT country FROM artist"); while (query.next()) { [QString](qstring.html) country = query.value(0).toString(); doSomething(country); } ``` 要訪問查詢返回的數據,使用值(整數)。在由返回的數據中的每個字段`SELECT`聲明是通過傳遞該領域的地位在聲明中,從0開始訪問的。這使得使用`SELECT *`查詢不可取的,因為返回的字段的順序是不確定的。 為了提高效率,有沒有函數通過名字來訪問一個字段(除非你使用預編譯查詢的姓名,解釋見下文) 。若要將字段名成一個索引,使用[record](qsqlquery.html#record)( ) 。[indexOf()](qsqlrecord.html#indexOf)例如: ``` QSqlQuery query("SELECT * FROM artist"); int fieldNo = query.record().indexOf("country"); while (query.next()) { [QString](qstring.html) country = query.value(fieldNo).toString(); doSomething(country); } ``` QSqlQuery支持準備好的查詢執行和參數值來佔位符綁定。有些數據庫不支持這些功能,所以對于那些, Qt的模擬所需的功能。例如, Oracle和ODBC驅動程序已準備妥當查詢支持,和Qt使得它的使用,但對于那些沒有這種支持的數據庫, Qt的實現了功能本身,如通過執行一個查詢時用實際值替換的佔位符。使用[numRowsAffected](qsqlquery.html#numRowsAffected)( )來找出多少行受到非`SELECT`查詢,并[size](qsqlquery.html#size)()找到多少被檢索由`SELECT`。 Oracle數據庫通過使用一個冒號名稱的語法,如查明佔位符`:name`。 ODBC只是使用`?`字符。 Qt支持這兩種語法,用,你不能將它們混合在同一個查詢的限制。 您可以使用檢索所有單個變量的字段的值(地圖)[boundValues](qsqlquery.html#boundValues)( ) 。 ### Approaches to Binding Values 下面,我們提出使用每四個不同的結合方式,以及結合值到存儲過程的一個例子相同的例子。 **Named binding using named placeholders:** ``` QSqlQuery query; 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:** ``` QSqlQuery query; 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):** ``` QSqlQuery query; 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):** ``` QSqlQuery query; 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:** 此代碼調用一個存儲過程調用`AsciiToInt()`在參數傳遞給它一個字符通過,并考慮其結果的輸出參數。 ``` QSqlQuery query; query.prepare("CALL AsciiToInt(?, ?)"); query.bindValue(0, "A"); query.bindValue(1, 0, [QSql](qsql.html).Out); query.exec(); int i = query.boundValue(1).toInt(); // i is 65 ``` 需要注意的是未綁定的參數將保留它們的值。 使用return語句返回值或返回多個結果集的存儲過程,不完全支持。對于具體細節見[SQL Database Drivers](index.htm)。 **Warning:**你必須載入SQL驅動程序并創建一個QSqlQuery之前打開連接。此外,該連接必須保持開放,而存在的查詢,否則, QSqlQuery的行為是未定義的。 * * * ## Type Documentation ``` QSqlQuery.BatchExecutionMode ``` | Constant | Value | Description | | --- | --- | --- | | `QSqlQuery.ValuesAsRows` | `0` | - 更新多行。黃柏中的每個條目[QVariantList](qvariant.html#QVariantList-typedef)作為用于更新的下一行的值。 | | `QSqlQuery.ValuesAsColumns` | `1` | - 更新一行。黃柏中的每個條目[QVariantList](qvariant.html#QVariantList-typedef)作為數組類型的單個值。 | * * * ## Method Documentation ``` QSqlQuery.__init__ (self, QSqlResult?r) ``` 構造一個[QSqlQuery](qsqlquery.html)對象,它使用了[QSqlResult](qsqlresult.html) _result_與數據庫進行通信。 ``` QSqlQuery.__init__ (self, QString?query?=?QString(), QSqlDatabase?db?=?QSqlDatabase()) ``` 構造一個[QSqlQuery](qsqlquery.html)使用SQL對象_query_和數據庫_db_。如果_db_如果未指定,或者是無效的,應用程序的默認數據庫被使用。如果_query_是不是空字符串,它就會被執行。 **See also** [QSqlDatabase](qsqldatabase.html)。 ``` QSqlQuery.__init__ (self, QSqlDatabase?db) ``` 構造一個[QSqlQuery](qsqlquery.html)使用數據庫對象_db_。如果_db_是無效的,應用程序的默認數據庫將被使用。 **See also** [QSqlDatabase](qsqldatabase.html)。 ``` QSqlQuery.__init__ (self, QSqlQuery?other) ``` 構造的副本_other_。 ``` QSqlQuery.addBindValue (self, QVariant?val, QSql.ParamType?type?=?QSql.In) ``` 增加值_val_使用位置值綁定時的值列表。該addBindValue ( )調用的順序確定哪個佔位符的值將在準備好的查詢綁定到。如果_paramType_ is [QSql.Out](qsql.html#ParamTypeFlag-enum) or [QSql.InOut](qsql.html#ParamTypeFlag-enum),佔位符將與后從數據庫中的數據復蓋[exec_](qsqlquery.html#exec)( )調用。 要綁定一個NULL值,使用空[QVariant](qvariant.html),例如,使用`QVariant(QVariant.String)`如果要綁定的字符串。 **See also** [bindValue](qsqlquery.html#bindValue)( )[prepare](qsqlquery.html#prepare)( )[exec_](qsqlquery.html#exec)( )[boundValue](qsqlquery.html#boundValue)()和[boundValues](qsqlquery.html#boundValues)( ) 。 ``` int QSqlQuery.at (self) ``` 返回查詢的當前內部位置。第一個記錄是在位置0 。如果位置是無效的,則函數返回[QSql.BeforeFirstRow](qsql.html#Location-enum) or [QSql.AfterLastRow](qsql.html#Location-enum),這是特殊的負值。 **See also** [previous](qsqlquery.html#previous)( )[next](qsqlquery.html#next)( )[first](qsqlquery.html#first)( )[last](qsqlquery.html#last)( )[seek](qsqlquery.html#seek)( )[isActive](qsqlquery.html#isActive)()和[isValid](qsqlquery.html#isValid)( ) 。 ``` QSqlQuery.bindValue (self, QString?placeholder, QVariant?val, QSql.ParamType?type?=?QSql.In) ``` 設置佔位符_placeholder_綁定到值_val_在準備好的語句。注意,佔位符標記(例如`:`)必須指定佔位符的名稱時,必須包括在內。如果_paramType_ is [QSql.Out](qsql.html#ParamTypeFlag-enum) or [QSql.InOut](qsql.html#ParamTypeFlag-enum),佔位符將與后從數據庫中的數據復蓋[exec_](qsqlquery.html#exec)( )調用。在這種情況下,有足夠的空間必須被預先分配給的結果存儲到。 要綁定一個NULL值,使用空[QVariant](qvariant.html),例如,使用`QVariant(QVariant.String)`如果要綁定的字符串。 值不能綁定到多個位置的查詢,例如: ``` INSERT INTO testtable (id, name, samename) VALUES (:id, :name, :name) ``` 綁定到名稱將綁定到第一:名字,但沒有第二個。 **See also** [addBindValue](qsqlquery.html#addBindValue)( )[prepare](qsqlquery.html#prepare)( )[exec_](qsqlquery.html#exec)( )[boundValue](qsqlquery.html#boundValue)()和[boundValues](qsqlquery.html#boundValues)( ) 。 ``` QSqlQuery.bindValue (self, int?pos, QVariant?val, QSql.ParamType?type?=?QSql.In) ``` 設置佔位符的位置_pos_綁定到值_val_在準備好的語句。字段編號從0開始。如果_paramType_ is [QSql.Out](qsql.html#ParamTypeFlag-enum) or [QSql.InOut](qsql.html#ParamTypeFlag-enum),佔位符將與后從數據庫中的數據復蓋[exec_](qsqlquery.html#exec)( )調用。 ``` QVariant QSqlQuery.boundValue (self, QString?placeholder) ``` 傳回值_placeholder_。 **See also** [boundValues](qsqlquery.html#boundValues)( )[bindValue](qsqlquery.html#bindValue)()和[addBindValue](qsqlquery.html#addBindValue)( ) 。 ``` QVariant QSqlQuery.boundValue (self, int?pos) ``` 返回在位置的佔位符的值_pos_。 ``` dict-of-QString-QVariant QSqlQuery.boundValues (self) ``` 返回綁定值的地圖。 與名為綁定,綁定的值可以檢查以下方面: ``` [QMapIterator](index.htm)<[QString](qstring.html), [QVariant](qvariant.html)> i(query.boundValues()); while (i.hasNext()) { i.next(); cout << i.key().toAscii().data() << ": " << i.value().toString().toAscii().data() << endl; } ``` 與位置綁定,代碼變為: ``` [QList](index.htm)<[QVariant](qvariant.html)> list = query.boundValues().values(); for (int i = 0; i < list.size(); ++i) cout << i << ": " << list.at(i).toString().toAscii().data() << endl; ``` **See also** [boundValue](qsqlquery.html#boundValue)( )[bindValue](qsqlquery.html#bindValue)()和[addBindValue](qsqlquery.html#addBindValue)( ) 。 ``` QSqlQuery.clear (self) ``` 清除結果集,并釋放該查詢持有的任何資源。設置查詢狀態為無效。你應該很少,如果需要調用這個函數。 ``` QSqlDriver QSqlQuery.driver (self) ``` [ 返回與查詢相關聯的數據庫驅動程序。 ``` bool QSqlQuery.exec_ (self, QString?query) ``` ](qsqldriver.html) [執行SQL中_query_。返回True ,并設置查詢狀態](qsqldriver.html)[active](qsqlquery.html#isActive)如果查詢成功,否則返回False 。該_query_字符串必須使用適當的語法為被查詢(例如,標準的SQL )的SQL數據庫。 查詢被執行后,查詢被定位在一個_invalid_記錄,并且必須被導航到一個有效記錄的數據值可以被檢索(例如,在使用前[next](qsqlquery.html#next)())。 請注意,此查詢的最后一個錯誤,當執行exec( )被調用復位。 對SQLite的查詢字符串可以一次只包含一個語句。如果多于一個語句被放棄,該函數返回False 。 例如: ``` [QSqlQuery](qsqlquery.html) query; query.exec("INSERT INTO employee (id, name, salary) " "VALUES (1001, 'Thad Beaumont', 65000)"); ``` **See also** [isActive](qsqlquery.html#isActive)( )[isValid](qsqlquery.html#isValid)( )[next](qsqlquery.html#next)( )[previous](qsqlquery.html#previous)( )[first](qsqlquery.html#first)( )[last](qsqlquery.html#last)()和[seek](qsqlquery.html#seek)( ) 。 ``` bool QSqlQuery.exec_ (self) ``` 執行先前準備的SQL查詢。返回True如果成功執行該查詢,否則返回False 。 請注意,此查詢的最后一個錯誤是,當復位[exec_](qsqlquery.html#exec)()被調用。 **See also** [prepare](qsqlquery.html#prepare)( )[bindValue](qsqlquery.html#bindValue)( )[addBindValue](qsqlquery.html#addBindValue)( )[boundValue](qsqlquery.html#boundValue)()和[boundValues](qsqlquery.html#boundValues)( ) 。 ``` bool QSqlQuery.execBatch (self, BatchExecutionMode?mode?=?QSqlQuery.ValuesAsRows) ``` 執行先前準備的SQL查詢中的批次。所有綁定參數必須是變種列表。如果數據庫不支持批量處決,驅動程序將使用傳統的模擬它[exec_](qsqlquery.html#exec)( )調用。 返回True如果查詢成功執行,否則返回False 。 例如: ``` [QSqlQuery](qsqlquery.html) q; q.prepare("insert into myTable values (?, ?)"); [QVariantList](qvariant.html#QVariantList-typedef) ints; ints << 1 << 2 << 3 << 4; q.addBindValue(ints); [QVariantList](qvariant.html#QVariantList-typedef) names; names << "Harald" << "Boris" << "Trond" << [QVariant](qvariant.html)([QVariant](qvariant.html).String); q.addBindValue(names); if (!q.execBatch()) qDebug() << q.lastError(); ``` 上面的例子中插入四個新行插入`myTable`: ``` 1 Harald 2 Boris 3 Trond 4 NULL ``` 要綁定NULL值,空[QVariant](qvariant.html)相關類型的已被添加到綁定[QVariantList](qvariant.html#QVariantList-typedef),例如,`QVariant(QVariant.String)`應該如果您使用的是字符串中使用。 **Note:**每一個綁定[QVariantList](qvariant.html#QVariantList-typedef)必須包含的變體是相同的。 **Note:**的類型[QVariants](index.htm#qvariants)在列表中不能改變。例如,您不能在一個混合整數和字符串變量[QVariantList](qvariant.html#QVariantList-typedef)。 該_mode_參數指示如何綁定[QVariantList](qvariant.html#QVariantList-typedef)將被解釋。如果_mode_ is `ValuesAsRows`,內部的每一個變種[QVariantList](qvariant.html#QVariantList-typedef)將被解釋為一個新的行的值。`ValuesAsColumns`對于Oracle驅動程序的一個特例。在這種模式下,在一個每條目[QVariantList](qvariant.html#QVariantList-typedef)將被解釋為一個存儲過程中的IN或OUT值的數組值。請注意,這只會工作,如果IN或OUT值是一個表型組成的基本型只有一列,例如`TYPE myType IS TABLE OF VARCHAR(64) INDEX BY BINARY_INTEGER;` 這個函數中引入了Qt 4.2中。 **See also** [prepare](qsqlquery.html#prepare)( )[bindValue](qsqlquery.html#bindValue)()和[addBindValue](qsqlquery.html#addBindValue)( ) 。 ``` QString QSqlQuery.executedQuery (self) ``` 返回成功執行的最后一個查詢。 在大多數情況下,這個函數返回相同的字符串[lastQuery](qsqlquery.html#lastQuery)( ) 。如果有一個佔位符編寫的查詢上不支持它的DBMS執行,這個查詢的制備效仿。在原始查詢中的佔位符替換為它們的綁定值,形成一個新的查詢。該函數返回修改后的查詢。它是用于調試目的大多是有用的。 **See also** [lastQuery](qsqlquery.html#lastQuery)( ) 。 ``` QSqlQuery.finish (self) ``` 指示沒有更多的數據將從這個查詢被取出,直到重新執行它的數據庫驅動程序。通常沒有必要調用這個函數,但它可能會有所幫助,以免費資源,例如鎖或游標,如果你打算重新使用查詢在以后的時間。 設置查詢為無效。綁定值保留它們的值。 此功能被引入Qt的4.3.2 。 **See also** [prepare](qsqlquery.html#prepare)( )[exec_](qsqlquery.html#exec)()和[isActive](qsqlquery.html#isActive)( ) 。 ``` bool QSqlQuery.first (self) ``` 獲取第一條記錄的結果,如果有的話,和對檢索到的記錄位置的查詢。請注意,其結果必然是在[active](qsqlquery.html#isActive)狀態[isSelect](qsqlquery.html#isSelect)()必須調用這個函數,否則將什么都不做,返回False才返回True。如果成功,則返回True 。如果不成功查詢位置被設置為無效位置,返回False 。 **See also** [next](qsqlquery.html#next)( )[previous](qsqlquery.html#previous)( )[last](qsqlquery.html#last)( )[seek](qsqlquery.html#seek)( )[at](qsqlquery.html#at)( )[isActive](qsqlquery.html#isActive)()和[isValid](qsqlquery.html#isValid)( ) 。 ``` bool QSqlQuery.isActive (self) ``` 返回True如果查詢_active_。一個活躍[QSqlQuery](qsqlquery.html)是一個已經[exec()'d](qsqlquery.html#exec)成功但尚未完成。當你完成了一個活躍的查詢,可以使使查詢無效的調用[finish](qsqlquery.html#finish)()或[clear](qsqlquery.html#clear)( ) ,或者你可以刪除[QSqlQuery](qsqlquery.html)實例。 **Note:**特別感興趣的是一種主動查詢,它是一個`SELECT`聲明。對于支持事務的一些數據庫,積極查詢,它是一個`SELECT`語句可以導致[commit()](qsqldatabase.html#commit)或[rollback()](qsqldatabase.html#rollback)失敗,因此提交或回滾之前,你應該讓你活躍`SELECT`語句查詢無效使用上面列出的方法之一。 **See also** [isSelect](qsqlquery.html#isSelect)( ) 。 ``` bool QSqlQuery.isForwardOnly (self) ``` 返回True如果你只能通過一個結果集向前滾動,否則返回False 。 **See also** [setForwardOnly](qsqlquery.html#setForwardOnly)()和[next](qsqlquery.html#next)( ) 。 ``` bool QSqlQuery.isNull (self, int?field) ``` 返回True如果查詢[active](qsqlquery.html#isActive)和定位在一個有效的記錄和_field_為NULL ,否則返回False 。請注意,對于某些驅動程序, ISNULL( )將不會返回準確的信息后,才試圖檢索數據。 **See also** [isActive](qsqlquery.html#isActive)( )[isValid](qsqlquery.html#isValid)()和[value](qsqlquery.html#value)( ) 。 ``` bool QSqlQuery.isSelect (self) ``` 返回True如果當前的查詢是`SELECT`聲明,否則返回False 。 ``` bool QSqlQuery.isValid (self) ``` 返回True如果查詢是目前定位在一個有效的記錄,否則返回False 。 ``` bool QSqlQuery.last (self) ``` 檢索記錄集中的最后結果,如果有的話,和對檢索到的記錄位置的查詢。請注意,其結果必然是在[active](qsqlquery.html#isActive)狀態[isSelect](qsqlquery.html#isSelect)()必須調用這個函數,否則將什么都不做,返回False才返回True。如果成功,則返回True 。如果不成功查詢位置被設置為無效位置,返回False 。 **See also** [next](qsqlquery.html#next)( )[previous](qsqlquery.html#previous)( )[first](qsqlquery.html#first)( )[seek](qsqlquery.html#seek)( )[at](qsqlquery.html#at)( )[isActive](qsqlquery.html#isActive)()和[isValid](qsqlquery.html#isValid)( ) 。 ``` QSqlError QSqlQuery.lastError (self) ``` [ 返回有關最后一個錯誤(如果有的話) ,與此查詢時發生的錯誤信息。 ](qsqlerror.html) [**See also**](qsqlerror.html) [QSqlError](qsqlerror.html)和[QSqlDatabase.lastError](qsqldatabase.html#lastError)( ) 。 ``` QVariant QSqlQuery.lastInsertId (self) ``` 返回最近插入的行的對象ID ,如果數據庫支持它。無效的[QVariant](qvariant.html)將被退回,如果查詢沒有插入任何值,或者如果數據庫沒有報告ID后面。如果不止一個行被感動的插入,該行為是未定義的。 對于MySQL數據庫行的自動遞增字段將被退回。 **Note:**對于這個功能在PSQL工作,該表的表必須包含的OID ,它可能沒有被創建的默認。檢查`default_with_oids`配置變量來確定。 **See also** [QSqlDriver.hasFeature](qsqldriver.html#hasFeature)( ) 。 ``` QString QSqlQuery.lastQuery (self) ``` 如果沒有當前的查詢文本返回當前查詢所使用的文字,或空字符串。 **See also** [executedQuery](qsqlquery.html#executedQuery)( ) 。 ``` bool QSqlQuery.next (self) ``` 檢索下一條記錄中的結果,如果有的話,和對檢索到的記錄位置的查詢。請注意,其結果必然是在[active](qsqlquery.html#isActive)狀態[isSelect](qsqlquery.html#isSelect)()必須調用這個函數,否則將什么都不做,返回False才返回True。 以下規則適用: * 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. 如果不能被檢索的記錄,結果是最后一條記錄并返回False后定位。如果記錄被成功取出,則返回True 。 **See also** [previous](qsqlquery.html#previous)( )[first](qsqlquery.html#first)( )[last](qsqlquery.html#last)( )[seek](qsqlquery.html#seek)( )[at](qsqlquery.html#at)( )[isActive](qsqlquery.html#isActive)()和[isValid](qsqlquery.html#isValid)( ) 。 ``` bool QSqlQuery.nextResult (self) ``` 丟棄當前的結果集,并導航到下一個(如果可用) 。 有些數據庫是可以返回多個結果集的存儲過程或SQL批處理(包含多個語句的查詢字符串)的。如果在執行一個查詢此功能可用于導航到下一個結果集(次)后,多個結果集可用。 如果一個新的結果集是可用此函數將返回True 。該查詢將在一個重新定位_invalid_在新的結果集的記錄,必須導航到一個有效的記錄數據值可以被檢索之前。如果一個新的結果集是不可用的函數返回False ,并且查詢被設置為無效。在任何情況下,舊的結果集合將被丟棄。 當語句之一是一個非select語句影響的行計數可能,而不是一個結果集可用。 需要注意的是一些數據庫,如微軟的SQL Server ,要求非滾動游標與多個結果集時。有些數據庫可以一次執行所有語句,而其他人可能會推遲執行,直到實際訪問的結果集,以及一些數據庫可能對哪些語句被允許在SQL批處理中使用的限制。 此功能被引入Qt的4.4 。 **See also** [QSqlDriver.hasFeature](qsqldriver.html#hasFeature)( )[setForwardOnly](qsqlquery.html#setForwardOnly)( )[next](qsqlquery.html#next)( )[isSelect](qsqlquery.html#isSelect)( )[numRowsAffected](qsqlquery.html#numRowsAffected)( )[isActive](qsqlquery.html#isActive)()和[lastError](qsqlquery.html#lastError)( ) 。 ``` QSql.NumericalPrecisionPolicy QSqlQuery.numericalPrecisionPolicy (self) ``` [ 返回當前的精度政策。 ](qsql.html#NumericalPrecisionPolicy-enum) [**See also**](qsql.html#NumericalPrecisionPolicy-enum) [QSql.NumericalPrecisionPolicy](qsql.html#NumericalPrecisionPolicy-enum)和[setNumericalPrecisionPolicy](qsqlquery.html#setNumericalPrecisionPolicy)( ) 。 ``` int QSqlQuery.numRowsAffected (self) ``` 返回受影響的結果的SQL語句,或者-1 ,如果它不能確定的行數。請注意,對于`SELECT`語句,該值是不確定的;使用[size](qsqlquery.html#size)( )來代替。如果該查詢是不[active](qsqlquery.html#isActive),則返回-1。 **See also** [size](qsqlquery.html#size)()和[QSqlDriver.hasFeature](qsqldriver.html#hasFeature)( ) 。 ``` bool QSqlQuery.prepare (self, QString?query) ``` 準備SQL查詢_query_用于執行。返回True如果查詢成功制備,否則返回False 。 該查詢可以包含佔位符綁定的值。這兩個Oracle風格冒號名稱(例如,`:surname`) ,和ODBC風格(`?`)佔位符的支持,但他們不能在同一查詢中混用。請參閱[Detailed Description](qsqlquery.html#qsqlquery-examples)為例子。 可移植性注:有些數據庫選擇延遲準備的查詢,直到它被執行的第一次。在這種情況下,準備一個語法錯誤的查詢成功,但每一個連續的[exec_](qsqlquery.html#exec)( )將失敗。 對SQLite的查詢字符串可以一次只包含一個語句。如果一個以上的語句給,函數返回False 。 例如: ``` [QSqlQuery](qsqlquery.html) query; 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** [exec_](qsqlquery.html#exec)( )[bindValue](qsqlquery.html#bindValue)()和[addBindValue](qsqlquery.html#addBindValue)( ) 。 ``` bool QSqlQuery.previous (self) ``` 檢索以前的記錄結果中,如果有的話,以及對檢索到的記錄位置的查詢。請注意,其結果必然是在[active](qsqlquery.html#isActive)狀態[isSelect](qsqlquery.html#isSelect)()必須調用這個函數,否則將什么都不做,返回False才返回True。 以下規則適用: * 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. 如果不能被檢索的記錄,結果被定位在第一個記錄并返回False之前。如果記錄被成功取出,則返回True 。 **See also** [next](qsqlquery.html#next)( )[first](qsqlquery.html#first)( )[last](qsqlquery.html#last)( )[seek](qsqlquery.html#seek)( )[at](qsqlquery.html#at)( )[isActive](qsqlquery.html#isActive)()和[isValid](qsqlquery.html#isValid)( ) 。 ``` QSqlRecord QSqlQuery.record (self) ``` [](qsqlrecord.html) [返回](qsqlrecord.html)[QSqlRecord](qsqlrecord.html)包含域信息的當前查詢。如果查詢指向一個有效的行([isValid](qsqlquery.html#isValid)( )返回True ) ,該記錄被填充了該行的值。當沒有主動查詢一個空的記錄,則返回([isActive](qsqlquery.html#isActive)( )返回False ) 。 從查詢中檢索值,[value](qsqlquery.html#value)( )應該被使用,因為它的基于索引的查找速度更快。 在下面的示例中,`SELECT * FROM`執行查詢。由于列的順序沒有被定義,[QSqlRecord.indexOf](qsqlrecord.html#indexOf)()是用來獲取的列的索引。 ``` [QSqlQuery](qsqlquery.html) q("select * from employees"); [QSqlRecord](qsqlrecord.html) rec = q.record(); qDebug() << "Number of columns: " << rec.count(); int nameCol = rec.indexOf("name"); // index of the field "name" while (q.next()) qDebug() << q.value(nameCol).toString(); // output all names ``` **See also** [value](qsqlquery.html#value)( ) 。 ``` QSqlResult QSqlQuery.result (self) ``` [ 返回與查詢相關的結果。 ``` bool QSqlQuery.seek (self, int?index, bool?relative?=?False) ``` ](qsqlresult.html) [檢索記錄位置_index_如果有的話,和立場上所檢索的記錄的查詢。第一個記錄是在位置0 。請注意,查詢必須是在](qsqlresult.html)[active](qsqlquery.html#isActive)狀態[isSelect](qsqlquery.html#isSelect)( )必須在調用這個函數之前返回True。 If _relative_為False(默認值) ,則適用以下規則: * If _index_ is 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 position _index_ 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. If _relative_是真的,應遵守下列規則: * If the result is currently positioned before the first record or on the first record, and _index_ is negative, there is no change, and false is returned. * If the result is currently located after the last record, and _index_ is positive, there is no change, and false is returned. * If the result is currently located somewhere in the middle, and the relative offset _index_ moves 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 _index_ records ahead of the current record (or _index_ records behind the current record if _index_ is negative). If the record at offset _index_ could not be retrieved, the result is positioned after the last record if _index_ &gt;= 0, (or before the first record if _index_ is negative), and false is returned. If the record is successfully retrieved, true is returned. **See also** [next](qsqlquery.html#next)( )[previous](qsqlquery.html#previous)( )[first](qsqlquery.html#first)( )[last](qsqlquery.html#last)( )[at](qsqlquery.html#at)( )[isActive](qsqlquery.html#isActive)()和[isValid](qsqlquery.html#isValid)( ) 。 ``` QSqlQuery.setForwardOnly (self, bool?forward) ``` 設置只進模式_forward_。如果_forward_是真的,只[next](qsqlquery.html#next)()和[seek](qsqlquery.html#seek)( )與正面的價值觀,是允許的導航結果。 只正向模式即可(這取決于驅動程序)更多的內存效率,因為結果并不需要被緩存。它也將提高某些數據庫的性能。對于這是真的,你必須調用`setForwardOnly()`查詢準備或執行之前。需要注意的是,需要一個查詢和數據庫的構造函數可以執行查詢。 只正向模式默認是關閉的。 前沖只為False是一個建議的數據庫引擎,它擁有最終決定權在結果集是否是只向前或滾動。[isForwardOnly](qsqlquery.html#isForwardOnly)( )將總是返回結果集的正確狀態。 **Note:**調用setForwardOnly后執行的查詢會導致意想不到的結果充其量和崩潰在最壞的情況。 **See also** [isForwardOnly](qsqlquery.html#isForwardOnly)( )[next](qsqlquery.html#next)( )[seek](qsqlquery.html#seek)()和[QSqlResult.setForwardOnly](qsqlresult.html#setForwardOnly)( ) 。 ``` QSqlQuery.setNumericalPrecisionPolicy (self, QSql.NumericalPrecisionPolicy?precisionPolicy) ``` 指示數據庫驅動程序返回的數值由指定的精度_precisionPolicy_。 Oracle驅動程序,例如,可以檢索數字值作為字符串來防止精度損失。如果精度高不要緊,使用此方法繞過字符串轉換來提高執行速度。 注意:不支持用低精度取數值的驅動程序將忽略精度政策。您可以使用[QSqlDriver.hasFeature](qsqldriver.html#hasFeature)( )來找出驅動程序是否支持此功能。 注意:設置精度策略不影響當前活動的查詢。通話[exec_](qsqlquery.html#exec)([QString](qstring.html))或[prepare](qsqlquery.html#prepare)() ,以激活該策略。 **See also** [QSql.NumericalPrecisionPolicy](qsql.html#NumericalPrecisionPolicy-enum)和[numericalPrecisionPolicy](qsqlquery.html#numericalPrecisionPolicy)( ) 。 ``` int QSqlQuery.size (self) ``` 返回結果的大小(返回的行數) ,或-1,如果大小無法確定,或者如果數據庫不支持報告有關查詢大小的信息。請注意,對于非`SELECT`報表([isSelect](qsqlquery.html#isSelect)( )返回False ) ,大小( )將返回-1 。如果查詢不活躍([isActive](qsqlquery.html#isActive)( )返回False ) ,則返回-1。 要確定一個非受影響的行數`SELECT`聲明中,使用[numRowsAffected](qsqlquery.html#numRowsAffected)( ) 。 **See also** [isActive](qsqlquery.html#isActive)( )[numRowsAffected](qsqlquery.html#numRowsAffected)()和[QSqlDriver.hasFeature](qsqldriver.html#hasFeature)( ) 。 ``` QVariant QSqlQuery.value (self, int?i) ``` 返回字段的值_index_在當前的記錄。 該字段使用的文本編號從左至右`SELECT`聲明中,例如在 ``` SELECT forename, surname FROM people; ``` 場0`forename`和現場1`surname`。運用`SELECT *`不建議,因為在查詢中字段的順序是不確定的。 無效的[QVariant](qvariant.html)返回如果場_index_不存在,如果查詢是無效的,或者如果該查詢被定位在一個無效的記錄。 **See also** [previous](qsqlquery.html#previous)( )[next](qsqlquery.html#next)( )[first](qsqlquery.html#first)( )[last](qsqlquery.html#last)( )[seek](qsqlquery.html#seek)( )[isActive](qsqlquery.html#isActive)()和[isValid](qsqlquery.html#isValid)( ) 。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看