qsqldatabase.html

来自「QT 下载资料仅供参考」· HTML 代码 · 共 344 行 · 第 1/2 页

HTML
344
字号
<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="drivers"></a>QSqlDatabase::drivers ()<tt> [static]</tt></h3> Returns a list of all available database drivers.<p> Note that if you want to iterate over the list, you shoulditerate over a copy, e.g.<pre>    <a href="qstringlist.html">QStringList</a> list = myDatabase.drivers();    QStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();    while( it != list.<a href="qvaluelist.html#end">end</a>() ) {        myProcessing( *it );        ++it;    }    </pre> <h3 class=fn><a href="qsqlquery.html">QSqlQuery</a> <a name="exec"></a>QSqlDatabase::exec ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;query = QString::null ) const</h3> Executes an SQL statement (e.g. an INSERT, UPDATE or DELETE statement)on the database, and returns a <a href="qsqlquery.html">QSqlQuery</a> object.  Use <a href="#lastError">lastError</a>()to retrieve error information. If <em>query</em> is <a href="qstring.html#QString-null">QString::null</a>, anempty, invalid query is returned and lastError() is not affected.<p> <p>See also <a href="qsqlquery.html">QSqlQuery</a> and <a href="#lastError">lastError</a>().<h3 class=fn><a href="qstring.html">QString</a> <a name="hostName"></a>QSqlDatabase::hostName () const</h3><p>Returns the host name where the database resides.See the <a href="qsqldatabase.html#hostName-prop">"hostName"</a> property for details.<h3 class=fn>bool <a name="isOpen"></a>QSqlDatabase::isOpen () const</h3> Returns TRUE if the database connection is currently open, otherwisereturns FALSE.<p> <h3 class=fn>bool <a name="isOpenError"></a>QSqlDatabase::isOpenError () const</h3> Returns TRUE if there was an error opening the database connection,otherwise returns FALSE. Error information can be retrievedusing the <a href="#lastError">lastError</a>() function.<p> <h3 class=fn><a href="qsqlerror.html">QSqlError</a> <a name="lastError"></a>QSqlDatabase::lastError () const</h3> Returns information about the last error that occurred on the database.  See<a href="qsqlerror.html">QSqlError</a> for more information.<p> <p>Examples: <a href="sql.html#x2149">sql/overview/create_connections/main.cpp</a> and <a href="sqltable-example.html#x2794">sql/sqltable/main.cpp</a>.<h3 class=fn>bool <a name="open"></a>QSqlDatabase::open ()</h3> Opens the database connection using the current connection values.  ReturnsTRUE on success, and FALSE if there was an error.  Errorinformation can be retrieved using the <a href="#lastError">lastError</a>() function.<p> <p>See also <a href="#lastError">lastError</a>().<p>Examples: <a href="sql.html#x2142">sql/overview/connect1/main.cpp</a>, <a href="sql.html#x2150">sql/overview/create_connections/main.cpp</a> and <a href="sqltable-example.html#x2795">sql/sqltable/main.cpp</a>.<h3 class=fn>bool <a name="open-2"></a>QSqlDatabase::open ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;user, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;password )</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Opens the database connection using <em>user</em> name and <em>password</em>.  ReturnsTRUE on success, and FALSE if there was an error.  Error informationcan be retrieved using the <a href="#lastError">lastError</a>() function.<p> <p>See also <a href="#lastError">lastError</a>().<h3 class=fn><a href="qstring.html">QString</a> <a name="password"></a>QSqlDatabase::password () const</h3><p>Returns the password used to connect to the database.See the <a href="qsqldatabase.html#password-prop">"password"</a> property for details.<h3 class=fn>int <a name="port"></a>QSqlDatabase::port () const</h3><p>Returns the port used to connect to the database.See the <a href="qsqldatabase.html#port-prop">"port"</a> property for details.<h3 class=fn><a href="qsqlindex.html">QSqlIndex</a> <a name="primaryIndex"></a>QSqlDatabase::primaryIndex ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;tablename ) const</h3>Returns the primary index for table <em>tablename</em>.  If noprimary index exists an empty <a href="qsqlindex.html">QSqlIndex</a> will be returned.<p> <h3 class=fn><a href="qsqlrecord.html">QSqlRecord</a> <a name="record"></a>QSqlDatabase::record ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;tablename ) const</h3>  Returns a <a href="qsqlrecord.html">QSqlRecord</a> populated with the names of all the fields inthe table (or view) named <em>tablename</em>. The order in which the fields arereturned is undefined.  If no such table (or view) exists, an emptyrecord is returned.<p> <p>See also <a href="#recordInfo">recordInfo</a>().<h3 class=fn><a href="qsqlrecord.html">QSqlRecord</a> <a name="record-2"></a>QSqlDatabase::record ( const&nbsp;<a href="qsqlquery.html">QSqlQuery</a>&nbsp;&amp;&nbsp;query ) const</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Returns a <a href="qsqlrecord.html">QSqlRecord</a> populated with the names of all the fields usedin the SQL <em>query</em>. If the query is a "SELECT *" the order in whichfields are returned is undefined.<p> <p>See also <a href="#recordInfo">recordInfo</a>().<h3 class=fn><a href="qsqlrecordinfo.html">QSqlRecordInfo</a> <a name="recordInfo"></a>QSqlDatabase::recordInfo ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;tablename ) const</h3>Returns a <a href="qsqlrecordinfo.html">QSqlRecordInfo</a> populated with meta-data about the table (or view)<em>tablename</em>. If no such table (or view) exists, an empty record is returned.<p> <p>See also <a href="qsqlrecordinfo.html">QSqlRecordInfo</a>, <a href="qsqlfieldinfo.html">QSqlFieldInfo</a> and <a href="#record">record</a>().<h3 class=fn><a href="qsqlrecordinfo.html">QSqlRecordInfo</a> <a name="recordInfo-2"></a>QSqlDatabase::recordInfo ( const&nbsp;<a href="qsqlquery.html">QSqlQuery</a>&nbsp;&amp;&nbsp;query ) const</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.<p> Returns a <a href="qsqlrecordinfo.html">QSqlRecordInfo</a> object with meta data for the <a href="qsqlquery.html">QSqlQuery</a> <em>query</em>.Note that this overloaded function may return not as much information asthe recordInfo function which takes the name of a table as parameter.<p> <p>See also <a href="qsqlrecordinfo.html">QSqlRecordInfo</a>, <a href="qsqlfieldinfo.html">QSqlFieldInfo</a> and <a href="#record">record</a>().<h3 class=fn>void <a name="removeDatabase"></a>QSqlDatabase::removeDatabase ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;connectionName )<tt> [static]</tt></h3>  Removes the database connection <em>connectionName</em> from the listof database connections.  Note that there should be no open querieson the database connection when this function is called, otherwise aresource leak will occur.<p> <h3 class=fn>bool <a name="rollback"></a>QSqlDatabase::rollback ()</h3> Rolls a transaction back on the database if the driver supports transactions.Returns TRUE if the operation succeeded, FALSE otherwise.<p> <p>See also <a href="qsqldriver.html#hasFeature">QSqlDriver::hasFeature</a>(), <a href="#commit">commit</a>() and <a href="#transaction">transaction</a>().<h3 class=fn>void <a name="setDatabaseName"></a>QSqlDatabase::setDatabaseName ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name )<tt> [virtual]</tt></h3><p>Sets the name of the database. Note that the database name is the TNS Service Name for the QOCI8 (Oracle) driver, and the Data Source Name for the QODBC3 driver to <em>name</em>.See the <a href="qsqldatabase.html#databaseName-prop">"databaseName"</a> property for details.<h3 class=fn>void <a name="setHostName"></a>QSqlDatabase::setHostName ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;host )<tt> [virtual]</tt></h3><p>Sets the host name where the database resides to <em>host</em>.See the <a href="qsqldatabase.html#hostName-prop">"hostName"</a> property for details.<h3 class=fn>void <a name="setPassword"></a>QSqlDatabase::setPassword ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;password )<tt> [virtual]</tt></h3><p>Sets the password used to connect to the database to <em>password</em>.See the <a href="qsqldatabase.html#password-prop">"password"</a> property for details.<h3 class=fn>void <a name="setPort"></a>QSqlDatabase::setPort ( int&nbsp;p )<tt> [virtual]</tt></h3><p>Sets the port used to connect to the database to <em>p</em>.See the <a href="qsqldatabase.html#port-prop">"port"</a> property for details.<h3 class=fn>void <a name="setUserName"></a>QSqlDatabase::setUserName ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name )<tt> [virtual]</tt></h3><p>Sets the user name connected to the database to <em>name</em>.See the <a href="qsqldatabase.html#userName-prop">"userName"</a> property for details.<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="tables"></a>QSqlDatabase::tables () const</h3>Returns a list of tables in the database.<p> Note that if you want to iterate over the list, you shoulditerate over a copy, e.g.<pre>    <a href="qstringlist.html">QStringList</a> list = myDatabase.tables();    QStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();    while( it != list.<a href="qvaluelist.html#end">end</a>() ) {        myProcessing( *it );        ++it;    }    </pre> <h3 class=fn>bool <a name="transaction"></a>QSqlDatabase::transaction ()</h3> Begins a transaction on the database if the driver supports transactions.Returns TRUE if the operation succeeded, FALSE otherwise.<p> <p>See also <a href="qsqldriver.html#hasFeature">QSqlDriver::hasFeature</a>(), <a href="#commit">commit</a>() and <a href="#rollback">rollback</a>().<h3 class=fn><a href="qstring.html">QString</a> <a name="userName"></a>QSqlDatabase::userName () const</h3><p>Returns the user name connected to the database.See the <a href="qsqldatabase.html#userName-prop">"userName"</a> property for details.<hr><h2>Property Documentation</h2><h3 class=fn><a href="qstring.html">QString</a> <a name="databaseName-prop"></a>databaseName</h3> <p>This property holds the name of the database. Note that the database name is the TNS Service Name for the <a href="sql-driver.html#QOCI8">QOCI8</a> (Oracle) driver, and the Data Source Name for the <a href="sql-driver.html#QODBC3">QODBC3</a> driver.<p>There is no default value.<p>Set this property's value with <a href="#setDatabaseName">setDatabaseName</a>() and get this property's value with <a href="#databaseName">databaseName</a>().<h3 class=fn><a href="qstring.html">QString</a> <a name="hostName-prop"></a>hostName</h3> <p>This property holds the host name where the database resides.<p>There is no default value.<p> <p>Set this property's value with <a href="#setHostName">setHostName</a>() and get this property's value with <a href="#hostName">hostName</a>().<h3 class=fn><a href="qstring.html">QString</a> <a name="password-prop"></a>password</h3> <p>This property holds the password used to connect to the database.<p>There is no default value.<p> <p>Set this property's value with <a href="#setPassword">setPassword</a>() and get this property's value with <a href="#password">password</a>().<h3 class=fn>int <a name="port-prop"></a>port</h3> <p>This property holds the port used to connect to the database.<p>There is no default value.<p> <p>Set this property's value with <a href="#setPort">setPort</a>() and get this property's value with <a href="#port">port</a>().<h3 class=fn><a href="qstring.html">QString</a> <a name="userName-prop"></a>userName</h3> <p>This property holds the user name connected to the database.<p>There is no default value.<p> <p>Set this property's value with <a href="#setUserName">setUserName</a>() and get this property's value with <a href="#userName">userName</a>().<!-- eof --><hr><p>This file is part of the <a href="index.html">Qt toolkit</a>.Copyright &copy; 1995-2002<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright &copy; 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?