Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > 28b9e36e96ce34b2567ae5b47a27b2c5 > files > 1017

python-qt4-doc-4.10.3-3.mga4.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QSqlDatabase Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QSqlDatabase Class Reference<br /><sup><sup>[<a href="qtsql.html">QtSql</a> module]</sup></sup></h1><p>The QSqlDatabase class represents a connection to a database.
<a href="#details">More...</a></p>

<h3>Methods</h3><ul><li><div class="fn" /><b><a href="qsqldatabase.html#QSqlDatabase">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#QSqlDatabase-2">__init__</a></b> (<i>self</i>, QSqlDatabase&#160;<i>other</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#QSqlDatabase-3">__init__</a></b> (<i>self</i>, QString&#160;<i>type</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#QSqlDatabase-4">__init__</a></b> (<i>self</i>, QSqlDriver&#160;<i>driver</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#close">close</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#commit">commit</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsqldatabase.html#connectionName">connectionName</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsqldatabase.html#connectOptions">connectOptions</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsqldatabase.html#databaseName">databaseName</a></b> (<i>self</i>)</li><li><div class="fn" />QSqlDriver <b><a href="qsqldatabase.html#driver">driver</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsqldatabase.html#driverName">driverName</a></b> (<i>self</i>)</li><li><div class="fn" />QSqlQuery <b><a href="qsqldatabase.html#exec">exec_</a></b> (<i>self</i>, QString&#160;<i>query</i>&#160;=&#160;QString())</li><li><div class="fn" />QString <b><a href="qsqldatabase.html#hostName">hostName</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#isOpen">isOpen</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#isOpenError">isOpenError</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#isValid">isValid</a></b> (<i>self</i>)</li><li><div class="fn" />QSqlError <b><a href="qsqldatabase.html#lastError">lastError</a></b> (<i>self</i>)</li><li><div class="fn" />QSql.NumericalPrecisionPolicy <b><a href="qsqldatabase.html#numericalPrecisionPolicy">numericalPrecisionPolicy</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#open">open</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#open-2">open</a></b> (<i>self</i>, QString&#160;<i>user</i>, QString&#160;<i>password</i>)</li><li><div class="fn" />QString <b><a href="qsqldatabase.html#password">password</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qsqldatabase.html#port">port</a></b> (<i>self</i>)</li><li><div class="fn" />QSqlIndex <b><a href="qsqldatabase.html#primaryIndex">primaryIndex</a></b> (<i>self</i>, QString&#160;<i>tablename</i>)</li><li><div class="fn" />QSqlRecord <b><a href="qsqldatabase.html#record">record</a></b> (<i>self</i>, QString&#160;<i>tablename</i>)</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#rollback">rollback</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a></b> (<i>self</i>, QString&#160;<i>options</i>&#160;=&#160;QString())</li><li><div class="fn" /><b><a href="qsqldatabase.html#setDatabaseName">setDatabaseName</a></b> (<i>self</i>, QString&#160;<i>name</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#setHostName">setHostName</a></b> (<i>self</i>, QString&#160;<i>host</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#setNumericalPrecisionPolicy">setNumericalPrecisionPolicy</a></b> (<i>self</i>, QSql.NumericalPrecisionPolicy&#160;<i>precisionPolicy</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#setPassword">setPassword</a></b> (<i>self</i>, QString&#160;<i>password</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#setPort">setPort</a></b> (<i>self</i>, int&#160;<i>p</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#setUserName">setUserName</a></b> (<i>self</i>, QString&#160;<i>name</i>)</li><li><div class="fn" />QStringList <b><a href="qsqldatabase.html#tables">tables</a></b> (<i>self</i>, QSql.TableType&#160;<i>type</i>&#160;=&#160;QSql.Tables)</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#transaction">transaction</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsqldatabase.html#userName">userName</a></b> (<i>self</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QSqlDatabase <b><a href="qsqldatabase.html#addDatabase">addDatabase</a></b> (QString&#160;<i>type</i>, QString&#160;<i>connectionName</i>&#160;=&#160;QLatin1String(QSqlDatabase.defaultConnection))</li><li><div class="fn" />QSqlDatabase <b><a href="qsqldatabase.html#addDatabase-2">addDatabase</a></b> (QSqlDriver&#160;<i>driver</i>, QString&#160;<i>connectionName</i>&#160;=&#160;QLatin1String(QSqlDatabase.defaultConnection))</li><li><div class="fn" />QSqlDatabase <b><a href="qsqldatabase.html#cloneDatabase">cloneDatabase</a></b> (QSqlDatabase&#160;<i>other</i>, QString&#160;<i>connectionName</i>)</li><li><div class="fn" />QStringList <b><a href="qsqldatabase.html#connectionNames">connectionNames</a></b> ()</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#contains">contains</a></b> (QString&#160;<i>connectionName</i>&#160;=&#160;QLatin1String(QSqlDatabase.defaultConnection))</li><li><div class="fn" />QSqlDatabase <b><a href="qsqldatabase.html#database">database</a></b> (QString&#160;<i>connectionName</i>&#160;=&#160;QLatin1String(QSqlDatabase.defaultConnection), bool&#160;<i>open</i>&#160;=&#160;True)</li><li><div class="fn" />QStringList <b><a href="qsqldatabase.html#drivers">drivers</a></b> ()</li><li><div class="fn" />bool <b><a href="qsqldatabase.html#isDriverAvailable">isDriverAvailable</a></b> (QString&#160;<i>name</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#registerSqlDriver">registerSqlDriver</a></b> (QString&#160;<i>name</i>, QSqlDriverCreatorBase&#160;<i>creator</i>)</li><li><div class="fn" /><b><a href="qsqldatabase.html#removeDatabase">removeDatabase</a></b> (QString&#160;<i>connectionName</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSqlDatabase class represents a connection to a
database.</p>
<p>The QSqlDatabase class provides an interface for accessing a
database through a connection. An instance of QSqlDatabase
represents the connection. The connection provides access to the
database via one of the <a href="sql-driver.html#supported-databases">supported database
drivers</a>, which are derived from <a href="qsqldriver.html">QSqlDriver</a>. Alternatively, you can subclass
your own database driver from <a href="qsqldriver.html">QSqlDriver</a>. See <a href="sql-driver.html#how-to-write-your-own-database-driver">How to
Write Your Own Database Driver</a> for more information.</p>
<p>Create a connection (i.e., an instance of QSqlDatabase) by
calling one of the static <a href="qsqldatabase.html#addDatabase">addDatabase</a>() functions, where
you specify <a href="sql-driver.html#supported-databases">the
driver or type of driver</a> to use (i.e., what kind of database
will you access?) and a connection name. A connection is known by
its own name, <i>not</i> by the name of the database it connects
to. You can have multiple connections to one database. QSqlDatabase
also supports the concept of a <i>default</i> connection, which is
the unnamed connection. To create the default connection, don't
pass the connection name argument when you call <a href="qsqldatabase.html#addDatabase">addDatabase</a>(). Subsequently,
when you call any static member function that takes the connection
name argument, if you don't pass the connection name argument, the
default connection is assumed. The following snippet shows how to
create and open a default connection to a PostgreSQL database:</p>
<pre class="cpp">
     <span class="type">QSqlDatabase</span> db <span class="operator">=</span> <span class="type">QSqlDatabase</span><span class="operator">.</span>addDatabase(<span class="string">"QPSQL"</span>);
     db<span class="operator">.</span>setHostName(<span class="string">"acidalia"</span>);
     db<span class="operator">.</span>setDatabaseName(<span class="string">"customdb"</span>);
     db<span class="operator">.</span>setUserName(<span class="string">"mojito"</span>);
     db<span class="operator">.</span>setPassword(<span class="string">"J0a1m8"</span>);
     <span class="type">bool</span> ok <span class="operator">=</span> db<span class="operator">.</span>open();
</pre>
<p>Once the QSqlDatabase object has been created, set the
connection parameters with <a href="qsqldatabase.html#setDatabaseName">setDatabaseName</a>(), <a href="qsqldatabase.html#setUserName">setUserName</a>(), <a href="qsqldatabase.html#setPassword">setPassword</a>(), <a href="qsqldatabase.html#setHostName">setHostName</a>(), <a href="qsqldatabase.html#setPort">setPort</a>(), and <a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a>(). Then
call <a href="qsqldatabase.html#open">open</a>() to activate the
physical connection to the database. The connection is not usable
until you open it.</p>
<p>The connection defined above will be the <i>default</i>
connection, because we didn't give a connection name to <a href="qsqldatabase.html#addDatabase">addDatabase()</a>. Subsequently,
you can get the default connection by calling <a href="qsqldatabase.html#database">database</a>() without the connection
name argument:</p>
<pre class="cpp">
     <span class="type">QSqlDatabase</span> db <span class="operator">=</span> <span class="type">QSqlDatabase</span><span class="operator">.</span>database();
</pre>
<p>QSqlDatabase is a value class. Changes made to a database
connection via one instance of QSqlDatabase will affect other
instances of QSqlDatabase that represent the same connection. Use
<a href="qsqldatabase.html#cloneDatabase">cloneDatabase</a>() to
create an independent database connection based on an existing
one.</p>
<p>If you create multiple database connections, specify a unique
connection name for each one, when you call <a href="qsqldatabase.html#addDatabase">addDatabase</a>(). Use <a href="qsqldatabase.html#database">database</a>() with a connection name
to get that connection. Use <a href="qsqldatabase.html#removeDatabase">removeDatabase</a>() with a
connection name to remove a connection. QSqlDatabase outputs a
warning if you try to remove a connection referenced by other
QSqlDatabase objects. Use <a href="qsqldatabase.html#contains">contains</a>() to see if a given
connection name is in the list of connections.</p>
<p>Once a connection is established, you can call <a href="qsqldatabase.html#tables">tables</a>() to get the list of tables
in the database, call <a href="qsqldatabase.html#primaryIndex">primaryIndex</a>() to get a
table's primary index, and call <a href="qsqldatabase.html#record">record</a>() to get meta-information
about a table's fields (e.g., field names).</p>
<p><b>Note:</b> <a href="qsqldatabase.html#exec">QSqlDatabase.exec</a>() is deprecated.
Use <a href="qsqlquery.html#exec">QSqlQuery.exec</a>()
instead.</p>
<p>If the driver supports transactions, use <a href="qsqldatabase.html#transaction">transaction</a>() to start a
transaction, and <a href="qsqldatabase.html#commit">commit</a>() or
<a href="qsqldatabase.html#rollback">rollback</a>() to complete it.
Use <a href="qsqldriver.html#hasFeature">hasFeature()</a> to ask if
the driver supports transactions. <b>Note:</b> When using
transactions, you must start the transaction before you create your
query.</p>
<p>If an error occurrs, <a href="qsqldatabase.html#lastError">lastError</a>() will return
information about it.</p>
<p>Get the names of the available SQL drivers with <a href="qsqldatabase.html#drivers">drivers</a>(). Check for the presence
of a particular driver with <a href="qsqldatabase.html#isDriverAvailable">isDriverAvailable</a>(). If
you have created your own custom driver, you must register it with
<a href="qsqldatabase.html#registerSqlDriver">registerSqlDriver</a>().</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QSqlDatabase" />QSqlDatabase.__init__ (<i>self</i>)</h3><p>Creates an empty, invalid <a href="qsqldatabase.html">QSqlDatabase</a> object. Use <a href="qsqldatabase.html#addDatabase">addDatabase</a>(), <a href="qsqldatabase.html#removeDatabase">removeDatabase</a>(), and
<a href="qsqldatabase.html#database">database</a>() to get valid
<a href="qsqldatabase.html">QSqlDatabase</a> objects.</p>


<h3 class="fn"><a name="QSqlDatabase-2" />QSqlDatabase.__init__ (<i>self</i>, <a href="qsqldatabase.html">QSqlDatabase</a>&#160;<i>other</i>)</h3><p>Creates a copy of <i>other</i>.</p>


<h3 class="fn"><a name="QSqlDatabase-3" />QSqlDatabase.__init__ (<i>self</i>, QString&#160;<i>type</i>)</h3><p>This is an overloaded function.</p>
<p>Creates a <a href="qsqldatabase.html">QSqlDatabase</a>
connection that uses the driver referred to by <i>type</i>. If the
<i>type</i> is not recognized, the database connection will have no
functionality.</p>
<p>The currently available driver types are:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Driver Type</th>
<th>Description</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>QDB2</td>
<td>IBM DB2</td>
</tr>
<tr class="even" valign="top">
<td>QIBASE</td>
<td>Borland InterBase Driver</td>
</tr>
<tr class="odd" valign="top">
<td>QMYSQL</td>
<td>MySQL Driver</td>
</tr>
<tr class="even" valign="top">
<td>QOCI</td>
<td>Oracle Call Interface Driver</td>
</tr>
<tr class="odd" valign="top">
<td>QODBC</td>
<td>ODBC Driver (includes Microsoft SQL Server)</td>
</tr>
<tr class="even" valign="top">
<td>QPSQL</td>
<td>PostgreSQL Driver</td>
</tr>
<tr class="odd" valign="top">
<td>QSQLITE</td>
<td>SQLite version 3 or above</td>
</tr>
<tr class="even" valign="top">
<td>QSQLITE2</td>
<td>SQLite version 2</td>
</tr>
<tr class="odd" valign="top">
<td>QTDS</td>
<td>Sybase Adaptive Server</td>
</tr>
</table>
<p>Additional third party drivers, including your own custom
drivers, can be loaded dynamically.</p>
<p><b>See also</b> <a href="sql-driver.html">SQL Database
Drivers</a>, <a href="qsqldatabase.html#registerSqlDriver">registerSqlDriver</a>(), and
<a href="qsqldatabase.html#drivers">drivers</a>().</p>


<h3 class="fn"><a name="QSqlDatabase-4" />QSqlDatabase.__init__ (<i>self</i>, <a href="qsqldriver.html">QSqlDriver</a>&#160;<i>driver</i>)</h3><p>This is an overloaded function.</p>
<p>Creates a database connection using the given <i>driver</i>.</p>


<h3 class="fn"><a name="addDatabase" /><a href="qsqldatabase.html">QSqlDatabase</a> QSqlDatabase.addDatabase (QString&#160;<i>type</i>, QString&#160;<i>connectionName</i>&#160;=&#160;QLatin1String(QSqlDatabase.defaultConnection))</h3><p>Adds a database to the list of database connections using the
driver <i>type</i> and the connection name <i>connectionName</i>.
If there already exists a database connection called
<i>connectionName</i>, that connection is removed.</p>
<p>The database connection is referred to by <i>connectionName</i>.
The newly added database connection is returned.</p>
<p>If <i>type</i> is not available or could not be loaded, <a href="qsqldatabase.html#isValid">isValid</a>() returns false.</p>
<p>If <i>connectionName</i> is not specified, the new connection
becomes the default connection for the application, and subsequent
calls to <a href="qsqldatabase.html#database">database</a>()
without the connection name argument will return the default
connection. If a <i>connectionName</i> is provided here, use
database(<i>connectionName</i>) to retrieve the connection.</p>
<p><b>Warning:</b> If you add a connection with the same name as an
existing connection, the new connection replaces the old one. If
you call this function more than once without specifying
<i>connectionName</i>, the default connection will be the one
replaced.</p>
<p>Before using the connection, it must be initialized. e.g., call
some or all of <a href="qsqldatabase.html#setDatabaseName">setDatabaseName</a>(), <a href="qsqldatabase.html#setUserName">setUserName</a>(), <a href="qsqldatabase.html#setPassword">setPassword</a>(), <a href="qsqldatabase.html#setHostName">setHostName</a>(), <a href="qsqldatabase.html#setPort">setPort</a>(), and <a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a>(), and,
finally, <a href="qsqldatabase.html#open">open</a>().</p>
<p><b>Note:</b> This function is <a href="threads-reentrancy.html#thread-safe">thread-safe</a>.</p>
<p><b>See also</b> <a href="qsqldatabase.html#database">database</a>(), <a href="qsqldatabase.html#removeDatabase">removeDatabase</a>(), and
<a href="threads-modules.html#threads-and-the-sql-module">Threads
and the SQL Module</a>.</p>


<h3 class="fn"><a name="addDatabase-2" /><a href="qsqldatabase.html">QSqlDatabase</a> QSqlDatabase.addDatabase (<a href="qsqldriver.html">QSqlDriver</a>&#160;<i>driver</i>, QString&#160;<i>connectionName</i>&#160;=&#160;QLatin1String(QSqlDatabase.defaultConnection))</h3><p>This overload is useful when you want to create a database
connection with a <a href="qsqldriver.html">driver</a> you
instantiated yourself. It might be your own database driver, or you
might just need to instantiate one of the Qt drivers yourself. If
you do this, it is recommended that you include the driver code in
your application. For example, you can create a PostgreSQL
connection with your own QPSQL driver like this:</p>
<pre class="cpp">
 <span class="preprocessor">#include "qtdir/src/sql/drivers/psql/qsql_psql.cpp"</span>

 PGconn <span class="operator">*</span>con <span class="operator">=</span> PQconnectdb(<span class="string">"host=server user=bart password=simpson dbname=springfield"</span>);
 <span class="type">QPSQLDriver</span> <span class="operator">*</span>drv <span class="operator">=</span>  <span class="keyword">new</span> <span class="type">QPSQLDriver</span>(con);
 <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span> db <span class="operator">=</span> <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span><a href="qsqldatabase.html#addDatabase">addDatabase</a>(drv); <span class="comment">// becomes the new default connection</span>
 <span class="type"><a href="qsqlquery.html">QSqlQuery</a></span> query;
 query<span class="operator">.</span><a href="qsqldatabase.html#exec">exec_</a>(<span class="string">"SELECT NAME, ID FROM STAFF"</span>);
 <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
</pre>
<p>The above code sets up a PostgreSQL connection and instantiates
a QPSQLDriver object. Next, <a href="qsqldatabase.html#addDatabase">addDatabase</a>() is called to add
the connection to the known connections so that it can be used by
the Qt SQL classes. When a driver is instantiated with a connection
handle (or set of handles), Qt assumes that you have already opened
the database connection.</p>
<p><b>Note:</b> We assume that <tt>qtdir</tt> is the directory
where Qt is installed. This will pull in the code that is needed to
use the PostgreSQL client library and to instantiate a QPSQLDriver
object, assuming that you have the PostgreSQL headers somewhere in
your include search path.</p>
<p>Remember that you must link your application against the
database client library. Make sure the client library is in your
linker's search path, and add lines like these to your
<tt>.pro</tt> file:</p>
<pre class="cpp">
 unix:LIBS <span class="operator">+</span><span class="operator">=</span> <span class="operator">-</span>lpq
 win32:LIBS <span class="operator">+</span><span class="operator">=</span> libpqdll<span class="operator">.</span>lib
</pre>
<p>The method described works for all the supplied drivers. The
only difference will be in the driver constructor arguments. Here
is a table of the drivers included with Qt, their source code
files, and their constructor arguments:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>Driver</th>
<th>Class name</th>
<th>Constructor arguments</th>
<th>File to include</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>QPSQL</td>
<td>QPSQLDriver</td>
<td>PGconn *connection</td>
<td><tt>qsql_psql.cpp</tt></td>
</tr>
<tr class="even" valign="top">
<td>QMYSQL</td>
<td>QMYSQLDriver</td>
<td>MYSQL *connection</td>
<td><tt>qsql_mysql.cpp</tt></td>
</tr>
<tr class="odd" valign="top">
<td>QOCI</td>
<td>QOCIDriver</td>
<td>OCIEnv *environment, OCISvcCtx *serviceContext</td>
<td><tt>qsql_oci.cpp</tt></td>
</tr>
<tr class="even" valign="top">
<td>QODBC</td>
<td>QODBCDriver</td>
<td>SQLHANDLE environment, SQLHANDLE connection</td>
<td><tt>qsql_odbc.cpp</tt></td>
</tr>
<tr class="odd" valign="top">
<td>QDB2</td>
<td>QDB2</td>
<td>SQLHANDLE environment, SQLHANDLE connection</td>
<td><tt>qsql_db2.cpp</tt></td>
</tr>
<tr class="even" valign="top">
<td>QTDS</td>
<td>QTDSDriver</td>
<td>LOGINREC *loginRecord, DBPROCESS *dbProcess, const <a href="qstring.html">QString</a> &amp;hostName</td>
<td><tt>qsql_tds.cpp</tt></td>
</tr>
<tr class="odd" valign="top">
<td>QSQLITE</td>
<td>QSQLiteDriver</td>
<td>sqlite *connection</td>
<td><tt>qsql_sqlite.cpp</tt></td>
</tr>
<tr class="even" valign="top">
<td>QIBASE</td>
<td>QIBaseDriver</td>
<td>isc_db_handle connection</td>
<td><tt>qsql_ibase.cpp</tt></td>
</tr>
</table>
<p>The host name (or service name) is needed when constructing the
QTDSDriver for creating new connections for internal queries. This
is to prevent blocking when several <a href="qsqlquery.html">QSqlQuery</a> objects are used simultaneously.</p>
<p><b>Warning:</b> Adding a database connection with the same
connection name as an existing connection, causes the existing
connection to be replaced by the new one.</p>
<p><b>Warning:</b> The SQL framework takes ownership of the
<i>driver</i>. It must not be deleted. To remove the connection,
use <a href="qsqldatabase.html#removeDatabase">removeDatabase</a>().</p>
<p><b>See also</b> <a href="qsqldatabase.html#drivers">drivers</a>().</p>


<h3 class="fn"><a name="cloneDatabase" /><a href="qsqldatabase.html">QSqlDatabase</a> QSqlDatabase.cloneDatabase (<a href="qsqldatabase.html">QSqlDatabase</a>&#160;<i>other</i>, QString&#160;<i>connectionName</i>)</h3><p>Clones the database connection <i>other</i> and and stores it as
<i>connectionName</i>. All the settings from the original database,
e.g. <a href="qsqldatabase.html#databaseName">databaseName</a>(),
<a href="qsqldatabase.html#hostName">hostName</a>(), etc., are
copied across. Does nothing if <i>other</i> is an invalid database.
Returns the newly created database connection.</p>
<p><b>Note:</b> The new connection has not been opened. Before
using the new connection, you must call <a href="qsqldatabase.html#open">open</a>().</p>


<h3 class="fn"><a name="close" />QSqlDatabase.close (<i>self</i>)</h3><p>Closes the database connection, freeing any resources acquired,
and invalidating any existing <a href="qsqlquery.html">QSqlQuery</a> objects that are used with the
database.</p>
<p>This will also affect copies of this <a href="qsqldatabase.html">QSqlDatabase</a> object.</p>
<p><b>See also</b> <a href="qsqldatabase.html#removeDatabase">removeDatabase</a>().</p>


<h3 class="fn"><a name="commit" />bool QSqlDatabase.commit (<i>self</i>)</h3><p>Commits a transaction to the database if the driver supports
transactions and a <a href="qsqldatabase.html#transaction">transaction</a>() has been started.
Returns <tt>true</tt> if the operation succeeded. Otherwise it
returns <tt>false</tt>.</p>
<p><b>Note:</b> For some databases, the commit will fail and return
<tt>false</tt> if there is an <a href="qsqlquery.html#isActive">active query</a> using the database for a
<tt>SELECT</tt>. Make the query <a href="qsqlquery.html#isActive">inactive</a> before doing the commit.</p>
<p>Call <a href="qsqldatabase.html#lastError">lastError</a>() to
get information about errors.</p>
<p><b>See also</b> <a href="qsqlquery.html#isActive">QSqlQuery.isActive</a>(), <a href="qsqldriver.html#hasFeature">QSqlDriver.hasFeature</a>(), and
<a href="qsqldatabase.html#rollback">rollback</a>().</p>


<h3 class="fn"><a name="connectionName" />QString QSqlDatabase.connectionName (<i>self</i>)</h3><p>Returns the connection name, which may be empty. <b>Note:</b>
The connection name is not the <a href="qsqldatabase.html#databaseName">database name</a>.</p>
<p>This function was introduced in Qt 4.4.</p>
<p><b>See also</b> <a href="qsqldatabase.html#addDatabase">addDatabase</a>().</p>


<h3 class="fn"><a name="connectionNames" />QStringList QSqlDatabase.connectionNames ()</h3><p>Returns a list containing the names of all connections.</p>
<p><b>Note:</b> This function is <a href="threads-reentrancy.html#thread-safe">thread-safe</a>.</p>
<p><b>See also</b> <a href="qsqldatabase.html#contains">contains</a>(), <a href="qsqldatabase.html#database">database</a>(), and <a href="threads-modules.html#threads-and-the-sql-module">Threads and the
SQL Module</a>.</p>


<h3 class="fn"><a name="connectOptions" />QString QSqlDatabase.connectOptions (<i>self</i>)</h3><p>Returns the connection options string used for this connection.
The string may be empty.</p>
<p><b>See also</b> <a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a>().</p>


<h3 class="fn"><a name="contains" />bool QSqlDatabase.contains (QString&#160;<i>connectionName</i>&#160;=&#160;QLatin1String(QSqlDatabase.defaultConnection))</h3><p>Returns true if the list of database connections contains
<i>connectionName</i>; otherwise returns false.</p>
<p><b>Note:</b> This function is <a href="threads-reentrancy.html#thread-safe">thread-safe</a>.</p>
<p><b>See also</b> <a href="qsqldatabase.html#connectionNames">connectionNames</a>(), <a href="qsqldatabase.html#database">database</a>(), and <a href="threads-modules.html#threads-and-the-sql-module">Threads and the
SQL Module</a>.</p>


<h3 class="fn"><a name="database" /><a href="qsqldatabase.html">QSqlDatabase</a> QSqlDatabase.database (QString&#160;<i>connectionName</i>&#160;=&#160;QLatin1String(QSqlDatabase.defaultConnection), bool&#160;<i>open</i>&#160;=&#160;True)</h3><p>Returns the database connection called <i>connectionName</i>.
The database connection must have been previously added with
<a href="qsqldatabase.html#addDatabase">addDatabase</a>(). If
<i>open</i> is true (the default) and the database connection is
not already open it is opened now. If no <i>connectionName</i> is
specified the default connection is used. If <i>connectionName</i>
does not exist in the list of databases, an invalid connection is
returned.</p>
<p><b>Note:</b> This function is <a href="threads-reentrancy.html#thread-safe">thread-safe</a>.</p>
<p><b>See also</b> <a href="qsqldatabase.html#isOpen">isOpen</a>()
and <a href="threads-modules.html#threads-and-the-sql-module">Threads and the
SQL Module</a>.</p>


<h3 class="fn"><a name="databaseName" />QString QSqlDatabase.databaseName (<i>self</i>)</h3><p>Returns the connection's database name, which may be empty.
<b>Note:</b> The database name is not the connection name.</p>
<p><b>See also</b> <a href="qsqldatabase.html#setDatabaseName">setDatabaseName</a>().</p>


<h3 class="fn"><a name="driver" /><a href="qsqldriver.html">QSqlDriver</a> QSqlDatabase.driver (<i>self</i>)</h3><p>Returns the database driver used to access the database
connection.</p>
<p><b>See also</b> <a href="qsqldatabase.html#addDatabase">addDatabase</a>() and <a href="qsqldatabase.html#drivers">drivers</a>().</p>


<h3 class="fn"><a name="driverName" />QString QSqlDatabase.driverName (<i>self</i>)</h3><p>Returns the connection's driver name.</p>
<p><b>See also</b> <a href="qsqldatabase.html#addDatabase">addDatabase</a>() and <a href="qsqldatabase.html#driver">driver</a>().</p>


<h3 class="fn"><a name="drivers" />QStringList QSqlDatabase.drivers ()</h3><p>Returns a list of all the available database drivers.</p>
<p><b>See also</b> <a href="qsqldatabase.html#registerSqlDriver">registerSqlDriver</a>().</p>


<h3 class="fn"><a name="exec" /><a href="qsqlquery.html">QSqlQuery</a> QSqlDatabase.exec_ (<i>self</i>, QString&#160;<i>query</i>&#160;=&#160;QString())</h3><p>Executes a SQL statement on the database and returns a <a href="qsqlquery.html">QSqlQuery</a> object. Use <a href="qsqldatabase.html#lastError">lastError</a>() to retrieve error
information. If <i>query</i> is empty, an empty, invalid query is
returned and <a href="qsqldatabase.html#lastError">lastError</a>()
is not affected.</p>
<p><b>See also</b> <a href="qsqlquery.html">QSqlQuery</a> and
<a href="qsqldatabase.html#lastError">lastError</a>().</p>


<h3 class="fn"><a name="hostName" />QString QSqlDatabase.hostName (<i>self</i>)</h3><p>Returns the connection's host name; it may be empty.</p>
<p><b>See also</b> <a href="qsqldatabase.html#setHostName">setHostName</a>().</p>


<h3 class="fn"><a name="isDriverAvailable" />bool QSqlDatabase.isDriverAvailable (QString&#160;<i>name</i>)</h3><p>Returns true if a driver called <i>name</i> is available;
otherwise returns false.</p>
<p><b>See also</b> <a href="qsqldatabase.html#drivers">drivers</a>().</p>


<h3 class="fn"><a name="isOpen" />bool QSqlDatabase.isOpen (<i>self</i>)</h3><p>Returns true if the database connection is currently open;
otherwise returns false.</p>


<h3 class="fn"><a name="isOpenError" />bool QSqlDatabase.isOpenError (<i>self</i>)</h3><p>Returns true if there was an error opening the database
connection; otherwise returns false. Error information can be
retrieved using the <a href="qsqldatabase.html#lastError">lastError</a>() function.</p>


<h3 class="fn"><a name="isValid" />bool QSqlDatabase.isValid (<i>self</i>)</h3><p>Returns true if the <a href="qsqldatabase.html">QSqlDatabase</a>
has a valid driver.</p>
<p>Example:</p>
<pre class="cpp">
 <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span> db;
 <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> db<span class="operator">.</span>isValid();    <span class="comment">// Returns false</span>

 db <span class="operator">=</span> <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span><a href="qsqldatabase.html#database">database</a>(<span class="string">"sales"</span>);
 <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> db<span class="operator">.</span>isValid();    <span class="comment">// Returns true if "sales" connection exists</span>

 <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span><a href="qsqldatabase.html#removeDatabase">removeDatabase</a>(<span class="string">"sales"</span>);
 <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> db<span class="operator">.</span>isValid();    <span class="comment">// Returns false</span>
</pre>


<h3 class="fn"><a name="lastError" /><a href="qsqlerror.html">QSqlError</a> QSqlDatabase.lastError (<i>self</i>)</h3><p>Returns information about the last error that occurred on the
database.</p>
<p>Failures that occur in conjunction with an individual query are
reported by <a href="qsqlquery.html#lastError">QSqlQuery.lastError</a>().</p>
<p><b>See also</b> <a href="qsqlerror.html">QSqlError</a> and
<a href="qsqlquery.html#lastError">QSqlQuery.lastError</a>().</p>


<h3 class="fn"><a name="numericalPrecisionPolicy" /><a href="qsql.html#NumericalPrecisionPolicy-enum">QSql.NumericalPrecisionPolicy</a> QSqlDatabase.numericalPrecisionPolicy (<i>self</i>)</h3><p>Returns the current default precision policy for the database
connection.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also</b> <a href="qsql.html#NumericalPrecisionPolicy-enum">QSql.NumericalPrecisionPolicy</a>,
<a href="qsqldatabase.html#setNumericalPrecisionPolicy">setNumericalPrecisionPolicy</a>(),
<a href="qsqlquery.html#numericalPrecisionPolicy">QSqlQuery.numericalPrecisionPolicy</a>(),
and <a href="qsqlquery.html#setNumericalPrecisionPolicy">QSqlQuery.setNumericalPrecisionPolicy</a>().</p>


<h3 class="fn"><a name="open" />bool QSqlDatabase.open (<i>self</i>)</h3><p>Opens the database connection using the current connection
values. Returns true on success; otherwise returns false. Error
information can be retrieved using <a href="qsqldatabase.html#lastError">lastError</a>().</p>
<p><b>See also</b> <a href="qsqldatabase.html#lastError">lastError</a>(), <a href="qsqldatabase.html#setDatabaseName">setDatabaseName</a>(), <a href="qsqldatabase.html#setUserName">setUserName</a>(), <a href="qsqldatabase.html#setPassword">setPassword</a>(), <a href="qsqldatabase.html#setHostName">setHostName</a>(), <a href="qsqldatabase.html#setPort">setPort</a>(), and <a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a>().</p>


<h3 class="fn"><a name="open-2" />bool QSqlDatabase.open (<i>self</i>, QString&#160;<i>user</i>, QString&#160;<i>password</i>)</h3><p>This is an overloaded function.</p>
<p>Opens the database connection using the given <i>user</i> name
and <i>password</i>. Returns true on success; otherwise returns
false. Error information can be retrieved using the <a href="qsqldatabase.html#lastError">lastError</a>() function.</p>
<p>This function does not store the password it is given. Instead,
the password is passed directly to the driver for opening the
connection and it is then discarded.</p>
<p><b>See also</b> <a href="qsqldatabase.html#lastError">lastError</a>().</p>


<h3 class="fn"><a name="password" />QString QSqlDatabase.password (<i>self</i>)</h3><p>Returns the connection's password. If the password was not set
with <a href="qsqldatabase.html#setPassword">setPassword</a>(), and
if the password was given in the <a href="qsqldatabase.html#open">open</a>() call, or if no password was
used, an empty string is returned.</p>
<p><b>See also</b> <a href="qsqldatabase.html#setPassword">setPassword</a>().</p>


<h3 class="fn"><a name="port" />int QSqlDatabase.port (<i>self</i>)</h3><p>Returns the connection's port number. The value is undefined if
the port number has not been set.</p>
<p><b>See also</b> <a href="qsqldatabase.html#setPort">setPort</a>().</p>


<h3 class="fn"><a name="primaryIndex" /><a href="qsqlindex.html">QSqlIndex</a> QSqlDatabase.primaryIndex (<i>self</i>, QString&#160;<i>tablename</i>)</h3><p>Returns the primary index for table <i>tablename</i>. If no
primary index exists an empty <a href="qsqlindex.html">QSqlIndex</a> is returned.</p>
<p><b>See also</b> <a href="qsqldatabase.html#tables">tables</a>()
and <a href="qsqldatabase.html#record">record</a>().</p>


<h3 class="fn"><a name="record" /><a href="qsqlrecord.html">QSqlRecord</a> QSqlDatabase.record (<i>self</i>, QString&#160;<i>tablename</i>)</h3><p>Returns a <a href="qsqlrecord.html">QSqlRecord</a> populated
with the names of all the fields in the table (or view) called
<i>tablename</i>. The order in which the fields appear in the
record is undefined. If no such table (or view) exists, an empty
record is returned.</p>


<h3 class="fn"><a name="registerSqlDriver" />QSqlDatabase.registerSqlDriver (QString&#160;<i>name</i>, <a href="qsqldrivercreatorbase.html">QSqlDriverCreatorBase</a>&#160;<i>creator</i>)</h3><p>The <i>creator</i> argument has it's ownership transferred to Qt.</p><p>This function registers a new SQL driver called <i>name</i>,
within the SQL framework. This is useful if you have a custom SQL
driver and don't want to compile it as a plugin.</p>
<p>Example:</p>
<pre class="cpp">
 <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span>registerSqlDriver(<span class="string">"MYDRIVER"</span><span class="operator">,</span>
                                 <span class="keyword">new</span> <span class="type"><a href="qsqldrivercreator.html">QSqlDriverCreator</a></span><span class="operator">&lt;</span>MyDatabaseDriver<span class="operator">&gt;</span>);
 <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span> db <span class="operator">=</span> <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span><a href="qsqldatabase.html#addDatabase">addDatabase</a>(<span class="string">"MYDRIVER"</span>);
</pre>
<p><a href="qsqldatabase.html">QSqlDatabase</a> takes ownership of
the <i>creator</i> pointer, so you mustn't delete it yourself.</p>
<p><b>See also</b> <a href="qsqldatabase.html#drivers">drivers</a>().</p>


<h3 class="fn"><a name="removeDatabase" />QSqlDatabase.removeDatabase (QString&#160;<i>connectionName</i>)</h3><p>Removes the database connection <i>connectionName</i> from the
list of database connections.</p>
<p><b>Warning:</b> There should be no open queries on the database
connection when this function is called, otherwise a resource leak
will occur.</p>
<p>Example:</p>
<pre class="cpp">
 <span class="comment">// WRONG</span>
 <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span> db <span class="operator">=</span> <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span><a href="qsqldatabase.html#database">database</a>(<span class="string">"sales"</span>);
 <span class="type"><a href="qsqlquery.html">QSqlQuery</a></span> query(<span class="string">"SELECT NAME, DOB FROM EMPLOYEES"</span><span class="operator">,</span> db);
 <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span>removeDatabase(<span class="string">"sales"</span>); <span class="comment">// will output a warning</span>

 <span class="comment">// "db" is now a dangling invalid database connection,</span>
 <span class="comment">// "query" contains an invalid result set</span>
</pre>
<p>The correct way to do it:</p>
<pre class="cpp">
 {
     <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span> db <span class="operator">=</span> <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span>database(<span class="string">"sales"</span>);
     <span class="type"><a href="qsqlquery.html">QSqlQuery</a></span> query(<span class="string">"SELECT NAME, DOB FROM EMPLOYEES"</span><span class="operator">,</span> db);
 }
 <span class="comment">// Both "db" and "query" are destroyed because they are out of scope</span>
 <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span>removeDatabase(<span class="string">"sales"</span>); <span class="comment">// correct</span>
</pre>
<p>To remove the default connection, which may have been created
with a call to <a href="qsqldatabase.html#addDatabase">addDatabase</a>() not specifying a
connection name, you can retrieve the default connection name by
calling <a href="qsqldatabase.html#connectionName">connectionName</a>() on the
database returned by <a href="qsqldatabase.html#database">database</a>(). Note that if a default
database hasn't been created an invalid database will be
returned.</p>
<p><b>Note:</b> This function is <a href="threads-reentrancy.html#thread-safe">thread-safe</a>.</p>
<p><b>See also</b> <a href="qsqldatabase.html#database">database</a>(), <a href="qsqldatabase.html#connectionName">connectionName</a>(), and
<a href="threads-modules.html#threads-and-the-sql-module">Threads
and the SQL Module</a>.</p>


<h3 class="fn"><a name="rollback" />bool QSqlDatabase.rollback (<i>self</i>)</h3><p>Rolls back a transaction on the database, if the driver supports
transactions and a <a href="qsqldatabase.html#transaction">transaction</a>() has been started.
Returns <tt>true</tt> if the operation succeeded. Otherwise it
returns <tt>false</tt>.</p>
<p><b>Note:</b> For some databases, the rollback will fail and
return <tt>false</tt> if there is an <a href="qsqlquery.html#isActive">active query</a> using the database for a
<tt>SELECT</tt>. Make the query <a href="qsqlquery.html#isActive">inactive</a> before doing the
rollback.</p>
<p>Call <a href="qsqldatabase.html#lastError">lastError</a>() to
get information about errors.</p>
<p><b>See also</b> <a href="qsqlquery.html#isActive">QSqlQuery.isActive</a>(), <a href="qsqldriver.html#hasFeature">QSqlDriver.hasFeature</a>(), and
<a href="qsqldatabase.html#commit">commit</a>().</p>


<h3 class="fn"><a name="setConnectOptions" />QSqlDatabase.setConnectOptions (<i>self</i>, QString&#160;<i>options</i>&#160;=&#160;QString())</h3><p>Sets database-specific <i>options</i>. This must be done before
the connection is opened or it has no effect (or you can <a href="qsqldatabase.html#close">close</a>() the connection, call this
function and <a href="qsqldatabase.html#open">open</a>() the
connection again).</p>
<p>The format of the <i>options</i> string is a semicolon separated
list of option names or option=value pairs. The options depend on
the database client used:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>ODBC</th>
<th>MySQL</th>
<th>PostgreSQL</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>
<ul>
<li>SQL_ATTR_ACCESS_MODE</li>
<li>SQL_ATTR_LOGIN_TIMEOUT</li>
<li>SQL_ATTR_CONNECTION_TIMEOUT</li>
<li>SQL_ATTR_CURRENT_CATALOG</li>
<li>SQL_ATTR_METADATA_ID</li>
<li>SQL_ATTR_PACKET_SIZE</li>
<li>SQL_ATTR_TRACEFILE</li>
<li>SQL_ATTR_TRACE</li>
<li>SQL_ATTR_CONNECTION_POOLING</li>
<li>SQL_ATTR_ODBC_VERSION</li>
</ul>
</td>
<td>
<ul>
<li>CLIENT_COMPRESS</li>
<li>CLIENT_FOUND_ROWS</li>
<li>CLIENT_IGNORE_SPACE</li>
<li>CLIENT_SSL</li>
<li>CLIENT_ODBC</li>
<li>CLIENT_NO_SCHEMA</li>
<li>CLIENT_INTERACTIVE</li>
<li>UNIX_SOCKET</li>
<li>MYSQL_OPT_RECONNECT</li>
</ul>
</td>
<td>
<ul>
<li>connect_timeout</li>
<li>options</li>
<li>tty</li>
<li>requiressl</li>
<li>service</li>
</ul>
</td>
</tr>
<thead>
<tr class="qt-style">
<th>DB2</th>
<th>OCI</th>
<th>TDS</th>
</tr>
</thead>
<tr class="even" valign="top">
<td>
<ul>
<li>SQL_ATTR_ACCESS_MODE</li>
<li>SQL_ATTR_LOGIN_TIMEOUT</li>
</ul>
</td>
<td>
<ul>
<li>OCI_ATTR_PREFETCH_ROWS</li>
<li>OCI_ATTR_PREFETCH_MEMORY</li>
</ul>
</td>
<td><i>none</i></td>
</tr>
<thead>
<tr class="qt-style">
<th>SQLite</th>
<th>Interbase</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>
<ul>
<li>QSQLITE_BUSY_TIMEOUT</li>
<li>QSQLITE_OPEN_READONLY</li>
<li>QSQLITE_ENABLE_SHARED_CACHE</li>
</ul>
</td>
<td>
<ul>
<li>ISC_DPB_LC_CTYPE</li>
<li>ISC_DPB_SQL_ROLE_NAME</li>
</ul>
</td>
</tr>
</table>
<p>Examples:</p>
<pre class="cpp">
 <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 <span class="comment">// MySQL connection</span>
 db<span class="operator">.</span>setConnectOptions(<span class="string">"CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1"</span>); <span class="comment">// use an SSL connection to the server</span>
 <span class="keyword">if</span> (<span class="operator">!</span>db<span class="operator">.</span>open()) {
     db<span class="operator">.</span>setConnectOptions(); <span class="comment">// clears the connect option string</span>
     <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 }
 <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 <span class="comment">// PostgreSQL connection</span>
 db<span class="operator">.</span>setConnectOptions(<span class="string">"requiressl=1"</span>); <span class="comment">// enable PostgreSQL SSL connections</span>
 <span class="keyword">if</span> (<span class="operator">!</span>db<span class="operator">.</span>open()) {
     db<span class="operator">.</span>setConnectOptions(); <span class="comment">// clear options</span>
     <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 }
 <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 <span class="comment">// ODBC connection</span>
 db<span class="operator">.</span>setConnectOptions(<span class="string">"SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY;SQL_ATTR_TRACE=SQL_OPT_TRACE_ON"</span>); <span class="comment">// set ODBC options</span>
 <span class="keyword">if</span> (<span class="operator">!</span>db<span class="operator">.</span>open()) {
     db<span class="operator">.</span>setConnectOptions(); <span class="comment">// don't try to set this option</span>
     <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 }
</pre>
<p>Refer to the client library documentation for more information
about the different options.</p>
<p><b>See also</b> <a href="qsqldatabase.html#connectOptions">connectOptions</a>().</p>


<h3 class="fn"><a name="setDatabaseName" />QSqlDatabase.setDatabaseName (<i>self</i>, QString&#160;<i>name</i>)</h3><p>Sets the connection's database name to <i>name</i>. To have
effect, the database name must be set <i>before</i> the connection
is <a href="qsqldatabase.html#open">opened</a>. Alternatively, you
can <a href="qsqldatabase.html#close">close</a>() the connection,
set the database name, and call <a href="qsqldatabase.html#open">open</a>() again. <b>Note:</b> The
<i>database name</i> is not the <i>connection name</i>. The
connection name must be passed to <a href="qsqldatabase.html#addDatabase">addDatabase</a>() at connection
object create time.</p>
<p>For the QOCI (Oracle) driver, the database name is the TNS
Service Name.</p>
<p>For the QODBC driver, the <i>name</i> can either be a DSN, a DSN
filename (in which case the file must have a <tt>.dsn</tt>
extension), or a connection string.</p>
<p>For example, Microsoft Access users can use the following
connection string to open an <tt>.mdb</tt> file directly, instead
of having to create a DSN entry in the ODBC manager:</p>
<pre class="cpp">
 <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
 db <span class="operator">=</span> <span class="type"><a href="qsqldatabase.html">QSqlDatabase</a></span><span class="operator">.</span><a href="qsqldatabase.html#addDatabase">addDatabase</a>(<span class="string">"QODBC"</span>);
 db<span class="operator">.</span>setDatabaseName(<span class="string">"DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb"</span>);
 <span class="keyword">if</span> (db<span class="operator">.</span>open()) {
     <span class="comment">// success!</span>
 }
 <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
</pre>
<p>There is no default value.</p>
<p><b>See also</b> <a href="qsqldatabase.html#databaseName">databaseName</a>(), <a href="qsqldatabase.html#setUserName">setUserName</a>(), <a href="qsqldatabase.html#setPassword">setPassword</a>(), <a href="qsqldatabase.html#setHostName">setHostName</a>(), <a href="qsqldatabase.html#setPort">setPort</a>(), <a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a>(), and
<a href="qsqldatabase.html#open">open</a>().</p>


<h3 class="fn"><a name="setHostName" />QSqlDatabase.setHostName (<i>self</i>, QString&#160;<i>host</i>)</h3><p>Sets the connection's host name to <i>host</i>. To have effect,
the host name must be set <i>before</i> the connection is <a href="qsqldatabase.html#open">opened</a>. Alternatively, you can
<a href="qsqldatabase.html#close">close</a>() the connection, set
the host name, and call <a href="qsqldatabase.html#open">open</a>()
again.</p>
<p>There is no default value.</p>
<p><b>See also</b> <a href="qsqldatabase.html#hostName">hostName</a>(), <a href="qsqldatabase.html#setUserName">setUserName</a>(), <a href="qsqldatabase.html#setPassword">setPassword</a>(), <a href="qsqldatabase.html#setDatabaseName">setDatabaseName</a>(), <a href="qsqldatabase.html#setPort">setPort</a>(), <a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a>(), and
<a href="qsqldatabase.html#open">open</a>().</p>


<h3 class="fn"><a name="setNumericalPrecisionPolicy" />QSqlDatabase.setNumericalPrecisionPolicy (<i>self</i>, <a href="qsql.html#NumericalPrecisionPolicy-enum">QSql.NumericalPrecisionPolicy</a>&#160;<i>precisionPolicy</i>)</h3><p>Sets the default numerical precision policy used by queries
created on this database connection to <i>precisionPolicy</i>.</p>
<p>Note: Drivers that don't support fetching numerical values with
low precision will ignore the precision policy. You can use
<a href="qsqldriver.html#hasFeature">QSqlDriver.hasFeature</a>()
to find out whether a driver supports this feature.</p>
<p>Note: Setting the default precision policy to
<i>precisionPolicy</i> doesn't affect any currently active
queries.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also</b> <a href="qsql.html#NumericalPrecisionPolicy-enum">QSql.NumericalPrecisionPolicy</a>,
<a href="qsqldatabase.html#numericalPrecisionPolicy">numericalPrecisionPolicy</a>(),
<a href="qsqlquery.html#setNumericalPrecisionPolicy">QSqlQuery.setNumericalPrecisionPolicy</a>(),
and <a href="qsqlquery.html#numericalPrecisionPolicy">QSqlQuery.numericalPrecisionPolicy</a>().</p>


<h3 class="fn"><a name="setPassword" />QSqlDatabase.setPassword (<i>self</i>, QString&#160;<i>password</i>)</h3><p>Sets the connection's password to <i>password</i>. To have
effect, the password must be set <i>before</i> the connection is
<a href="qsqldatabase.html#open">opened</a>. Alternatively, you can
<a href="qsqldatabase.html#close">close</a>() the connection, set
the password, and call <a href="qsqldatabase.html#open">open</a>()
again.</p>
<p>There is no default value.</p>
<p><b>Warning:</b> This function stores the password in plain text
within Qt. Use the <a href="qsqldatabase.html#open">open</a>() call
that takes a password as parameter to avoid this behavior.</p>
<p><b>See also</b> <a href="qsqldatabase.html#password">password</a>(), <a href="qsqldatabase.html#setUserName">setUserName</a>(), <a href="qsqldatabase.html#setDatabaseName">setDatabaseName</a>(), <a href="qsqldatabase.html#setHostName">setHostName</a>(), <a href="qsqldatabase.html#setPort">setPort</a>(), <a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a>(), and
<a href="qsqldatabase.html#open">open</a>().</p>


<h3 class="fn"><a name="setPort" />QSqlDatabase.setPort (<i>self</i>, int&#160;<i>p</i>)</h3><p>Sets the connection's port number to <i>port</i>. To have
effect, the port number must be set <i>before</i> the connection is
<a href="qsqldatabase.html#open">opened</a>. Alternatively, you can
<a href="qsqldatabase.html#close">close</a>() the connection, set
the port number, and call <a href="qsqldatabase.html#open">open</a>() again..</p>
<p>There is no default value.</p>
<p><b>See also</b> <a href="qsqldatabase.html#port">port</a>(),
<a href="qsqldatabase.html#setUserName">setUserName</a>(), <a href="qsqldatabase.html#setPassword">setPassword</a>(), <a href="qsqldatabase.html#setHostName">setHostName</a>(), <a href="qsqldatabase.html#setDatabaseName">setDatabaseName</a>(), <a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a>(), and
<a href="qsqldatabase.html#open">open</a>().</p>


<h3 class="fn"><a name="setUserName" />QSqlDatabase.setUserName (<i>self</i>, QString&#160;<i>name</i>)</h3><p>Sets the connection's user name to <i>name</i>. To have effect,
the user name must be set <i>before</i> the connection is <a href="qsqldatabase.html#open">opened</a>. Alternatively, you can
<a href="qsqldatabase.html#close">close</a>() the connection, set
the user name, and call <a href="qsqldatabase.html#open">open</a>()
again.</p>
<p>There is no default value.</p>
<p><b>See also</b> <a href="qsqldatabase.html#userName">userName</a>(), <a href="qsqldatabase.html#setDatabaseName">setDatabaseName</a>(), <a href="qsqldatabase.html#setPassword">setPassword</a>(), <a href="qsqldatabase.html#setHostName">setHostName</a>(), <a href="qsqldatabase.html#setPort">setPort</a>(), <a href="qsqldatabase.html#setConnectOptions">setConnectOptions</a>(), and
<a href="qsqldatabase.html#open">open</a>().</p>


<h3 class="fn"><a name="tables" />QStringList QSqlDatabase.tables (<i>self</i>, <a href="qsql.html#TableType-enum">QSql.TableType</a>&#160;<i>type</i>&#160;=&#160;QSql.Tables)</h3><p>Returns a list of the database's tables, system tables and
views, as specified by the parameter <i>type</i>.</p>
<p><b>See also</b> <a href="qsqldatabase.html#primaryIndex">primaryIndex</a>() and <a href="qsqldatabase.html#record">record</a>().</p>


<h3 class="fn"><a name="transaction" />bool QSqlDatabase.transaction (<i>self</i>)</h3><p>Begins a transaction on the database if the driver supports
transactions. Returns <tt>true</tt> if the operation succeeded.
Otherwise it returns <tt>false</tt>.</p>
<p><b>See also</b> <a href="qsqldriver.html#hasFeature">QSqlDriver.hasFeature</a>(), <a href="qsqldatabase.html#commit">commit</a>(), and <a href="qsqldatabase.html#rollback">rollback</a>().</p>


<h3 class="fn"><a name="userName" />QString QSqlDatabase.userName (<i>self</i>)</h3><p>Returns the connection's user name; it may be empty.</p>
<p><b>See also</b> <a href="qsqldatabase.html#setUserName">setUserName</a>().</p>


<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.10.3 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.5</td></tr></table></div></address></body></html>