1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
<?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>QSqlDriver 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">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QSqlDriver Class Reference<br /><sup><sup>[<a href="qtsql.html">QtSql</a> module]</sup></sup></h1><p>The QSqlDriver class is an abstract base class for accessing specific SQL databases. <a href="#details">More...</a></p>
<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qsqldriver.html#DriverFeature-enum">DriverFeature</a></b> { Transactions, QuerySize, BLOB, Unicode, ..., BatchOperations }</li><li><div class="fn" />enum <b><a href="qsqldriver.html#IdentifierType-enum">IdentifierType</a></b> { FieldName, TableName }</li><li><div class="fn" />enum <b><a href="qsqldriver.html#StatementType-enum">StatementType</a></b> { WhereStatement, SelectStatement, UpdateStatement, InsertStatement, DeleteStatement }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qsqldriver.html#QSqlDriver">__init__</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" />bool <b><a href="qsqldriver.html#beginTransaction">beginTransaction</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsqldriver.html#close">close</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldriver.html#commitTransaction">commitTransaction</a></b> (<i>self</i>)</li><li><div class="fn" />QSqlResult <b><a href="qsqldriver.html#createResult">createResult</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsqldriver.html#escapeIdentifier">escapeIdentifier</a></b> (<i>self</i>, QString <i>identifier</i>, IdentifierType <i>type</i>)</li><li><div class="fn" />QString <b><a href="qsqldriver.html#formatValue">formatValue</a></b> (<i>self</i>, QSqlField <i>field</i>, bool <i>trimStrings</i> = False)</li><li><div class="fn" />QVariant <b><a href="qsqldriver.html#handle">handle</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldriver.html#hasFeature">hasFeature</a></b> (<i>self</i>, DriverFeature <i>f</i>)</li><li><div class="fn" />bool <b><a href="qsqldriver.html#isOpen">isOpen</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldriver.html#isOpenError">isOpenError</a></b> (<i>self</i>)</li><li><div class="fn" />QSqlError <b><a href="qsqldriver.html#lastError">lastError</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqldriver.html#open">open</a></b> (<i>self</i>, QString <i>db</i>, QString <i>user</i> = QString(), QString <i>password</i> = QString(), QString <i>host</i> = QString(), int <i>port</i> = -1, QString <i>connOpts</i> = QString())</li><li><div class="fn" />QSqlIndex <b><a href="qsqldriver.html#primaryIndex">primaryIndex</a></b> (<i>self</i>, QString <i>tableName</i>)</li><li><div class="fn" />QSqlRecord <b><a href="qsqldriver.html#record">record</a></b> (<i>self</i>, QString <i>tableName</i>)</li><li><div class="fn" />bool <b><a href="qsqldriver.html#rollbackTransaction">rollbackTransaction</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsqldriver.html#setLastError">setLastError</a></b> (<i>self</i>, QSqlError <i>e</i>)</li><li><div class="fn" /><b><a href="qsqldriver.html#setOpen">setOpen</a></b> (<i>self</i>, bool <i>o</i>)</li><li><div class="fn" /><b><a href="qsqldriver.html#setOpenError">setOpenError</a></b> (<i>self</i>, bool <i>e</i>)</li><li><div class="fn" />QString <b><a href="qsqldriver.html#sqlStatement">sqlStatement</a></b> (<i>self</i>, StatementType <i>type</i>, QString <i>tableName</i>, QSqlRecord <i>rec</i>, bool <i>preparedStatement</i>)</li><li><div class="fn" />QStringList <b><a href="qsqldriver.html#tables">tables</a></b> (<i>self</i>, QSql.TableType <i>tableType</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSqlDriver class is an abstract base class for accessing specific SQL databases.</p>
<p>This class should not be used directly. Use <a href="qsqldatabase.html">QSqlDatabase</a> instead.</p>
<p>If you want to create your own SQL drivers, you can subclass this class and reimplement its pure virtual functions and those virtual functions that you need. 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>See also <a href="qsqldatabase.html">QSqlDatabase</a> and <a href="qsqlresult.html">QSqlResult</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="DriverFeature-enum" />QSqlDriver.DriverFeature</h3><p>This enum contains a list of features a driver might support. Use <a href="qsqldriver.html#hasFeature">hasFeature</a>() to query whether a feature is supported or not.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.Transactions</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">Whether the driver supports SQL transactions.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.QuerySize</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">Whether the database is capable of reporting the size of a query. Note that some databases do not support returning the size (i.e. number of rows returned) of a query, in which case <a href="qsqlquery.html#size">QSqlQuery.size</a>() will return -1.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.BLOB</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top">Whether the driver supports Binary Large Object fields.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.Unicode</tt></td>
<td align="center" valign="top"><tt>3</tt></td>
<td valign="top">Whether the driver supports Unicode strings if the database server does.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.PreparedQueries</tt></td>
<td align="center" valign="top"><tt>4</tt></td>
<td valign="top">Whether the driver supports prepared query execution.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.NamedPlaceholders</tt></td>
<td align="center" valign="top"><tt>5</tt></td>
<td valign="top">Whether the driver supports the use of named placeholders.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.PositionalPlaceholders</tt></td>
<td align="center" valign="top"><tt>6</tt></td>
<td valign="top">Whether the driver supports the use of positional placeholders.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.LastInsertId</tt></td>
<td align="center" valign="top"><tt>7</tt></td>
<td valign="top">Whether the driver supports returning the Id of the last touched row.</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.BatchOperations</tt></td>
<td align="center" valign="top"><tt>8</tt></td>
<td valign="top">Whether the driver supports batched operations, see QSqlResult.execBatch()</td>
</tr>
</table>
<br />
<br />
<p>More information about supported features can be found in the <a href="sql-driver.html">Qt SQL driver</a> documentation.</p>
<p>See also <a href="qsqldriver.html#hasFeature">hasFeature</a>().</p>
<h3 class="fn"><a name="IdentifierType-enum" />QSqlDriver.IdentifierType</h3><p>This enum contains a list of SQL identifier types.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.FieldName</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">A SQL field name</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.TableName</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">A SQL table name</td>
</tr>
</table>
<br />
<br />
<h3 class="fn"><a name="StatementType-enum" />QSqlDriver.StatementType</h3><p>This enum contains a list of SQL statement (or clause) types the driver can create.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.WhereStatement</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">An SQL <tt>WHERE</tt> statement (e.g., <tt>WHERE f = 5</tt>).</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.SelectStatement</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top">An SQL <tt>SELECT</tt> statement (e.g., <tt>SELECT f FROM t</tt>).</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.UpdateStatement</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top">An SQL <tt>UPDATE</tt> statement (e.g., <tt>UPDATE TABLE t set f = 1</tt>).</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.InsertStatement</tt></td>
<td align="center" valign="top"><tt>3</tt></td>
<td valign="top">An SQL <tt>INSERT</tt> statement (e.g., <tt>INSERT INTO t (f) values (1)</tt>).</td>
</tr>
<tr>
<td valign="top"><tt>QSqlDriver.DeleteStatement</tt></td>
<td align="center" valign="top"><tt>4</tt></td>
<td valign="top">An SQL <tt>DELETE</tt> statement (e.g., <tt>DELETE FROM t</tt>).</td>
</tr>
</table>
<br />
<br />
<p>See also <a href="qsqldriver.html#sqlStatement">sqlStatement</a>().</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QSqlDriver" />QSqlDriver.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new driver with the given <i>parent</i>.</p>
<h3 class="fn"><a name="beginTransaction" />bool QSqlDriver.beginTransaction (<i>self</i>)</h3><p>This function is called to begin a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns false.</p>
<p>See also <a href="qsqldriver.html#commitTransaction">commitTransaction</a>() and <a href="qsqldriver.html#rollbackTransaction">rollbackTransaction</a>().</p>
<h3 class="fn"><a name="close" />QSqlDriver.close (<i>self</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Derived classes must reimplement this pure virtual function in order to close the database connection. Return true on success, false on failure.</p>
<p>See also <a href="qsqldriver.html#open">open</a>() and <a href="qsqldriver.html#setOpen">setOpen</a>().</p>
<h3 class="fn"><a name="commitTransaction" />bool QSqlDriver.commitTransaction (<i>self</i>)</h3><p>This function is called to commit a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns false.</p>
<p>See also <a href="qsqldriver.html#beginTransaction">beginTransaction</a>() and <a href="qsqldriver.html#rollbackTransaction">rollbackTransaction</a>().</p>
<h3 class="fn"><a name="createResult" /><a href="qsqlresult.html">QSqlResult</a> QSqlDriver.createResult (<i>self</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Creates an empty SQL result on the database. Derived classes must reimplement this function and return a <a href="qsqlresult.html">QSqlResult</a> object appropriate for their database to the caller.</p>
<h3 class="fn"><a name="escapeIdentifier" /><a href="qstring.html">QString</a> QSqlDriver.escapeIdentifier (<i>self</i>, <a href="qstring.html">QString</a> <i>identifier</i>, <a href="qsqldriver.html#IdentifierType-enum">IdentifierType</a> <i>type</i>)</h3><p>Returns the <i>identifier</i> escaped according to the database rules. <i>identifier</i> can either be a table name or field name, dependent on <i>type</i>.</p>
<p>The default implementation does nothing.</p>
<h3 class="fn"><a name="formatValue" /><a href="qstring.html">QString</a> QSqlDriver.formatValue (<i>self</i>, <a href="qsqlfield.html">QSqlField</a> <i>field</i>, bool <i>trimStrings</i> = False)</h3><h3 class="fn"><a name="handle" /><a href="qvariant.html">QVariant</a> QSqlDriver.handle (<i>self</i>)</h3><p>Returns the low-level database handle wrapped in a <a href="qvariant.html">QVariant</a> or an invalid variant if there is no handle.</p>
<p><b>Warning:</b> Use this with uttermost care and only if you know what you're doing.</p>
<p><b>Warning:</b> The handle returned here can become a stale pointer if the connection is modified (for example, if you close the connection).</p>
<p><b>Warning:</b> The handle can be NULL if the connection is not open yet.</p>
<p>The handle returned here is database-dependent, you should query the type name of the variant before accessing it.</p>
<p>This example retrieves the handle for a connection to sqlite:</p>
<pre>
QSqlDatabase db = ...;
QVariant v = db.driver()->handle();
if (v.isValid() && v.typeName() == "sqlite3*") {
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle != 0) { // check that it is not NULL
...
}
}
</pre>
<p>This snippet returns the handle for PostgreSQL or MySQL:</p>
<pre>
if (v.typeName() == "PGconn*") {
PGconn *handle = *static_cast<PGconn **>(v.data());
if (handle != 0) ...
}
if (v.typeName() == "MYSQL*") {
MYSQL *handle = *static_cast<MYSQL **>(v.data());
if (handle != 0) ...
}
</pre>
<p>See also <a href="qsqlresult.html#handle">QSqlResult.handle</a>().</p>
<h3 class="fn"><a name="hasFeature" />bool QSqlDriver.hasFeature (<i>self</i>, <a href="qsqldriver.html#DriverFeature-enum">DriverFeature</a> <i>f</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Returns true if the driver supports feature <i>feature</i>; otherwise returns false.</p>
<p>Note that some databases need to be <a href="qsqldriver.html#open">open</a>() before this can be determined.</p>
<p>See also <a href="qsqldriver.html#DriverFeature-enum">DriverFeature</a>.</p>
<h3 class="fn"><a name="isOpen" />bool QSqlDriver.isOpen (<i>self</i>)</h3><p>Returns true if the database connection is open; otherwise returns false.</p>
<h3 class="fn"><a name="isOpenError" />bool QSqlDriver.isOpenError (<i>self</i>)</h3><p>Returns true if the there was an error opening the database connection; otherwise returns false.</p>
<h3 class="fn"><a name="lastError" /><a href="qsqlerror.html">QSqlError</a> QSqlDriver.lastError (<i>self</i>)</h3><p>Returns a <a href="qsqlerror.html">QSqlError</a> object which contains information about the last error that occurred on the database.</p>
<p>See also <a href="qsqldriver.html#setLastError">setLastError</a>().</p>
<h3 class="fn"><a name="open" />bool QSqlDriver.open (<i>self</i>, <a href="qstring.html">QString</a> <i>db</i>, <a href="qstring.html">QString</a> <i>user</i> = QString(), <a href="qstring.html">QString</a> <i>password</i> = QString(), <a href="qstring.html">QString</a> <i>host</i> = QString(), int <i>port</i> = -1, <a href="qstring.html">QString</a> <i>connOpts</i> = QString())</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><p>Derived classes must reimplement this pure virtual function to open a database connection on database <i>db</i>, using user name <i>user</i>, password <i>password</i>, host <i>host</i>, port <i>port</i> and connection options <i>options</i>.</p>
<p>The function must return true on success and false on failure.</p>
<p>See also <a href="qsqldriver.html#setOpen">setOpen</a>().</p>
<h3 class="fn"><a name="primaryIndex" /><a href="qsqlindex.html">QSqlIndex</a> QSqlDriver.primaryIndex (<i>self</i>, <a href="qstring.html">QString</a> <i>tableName</i>)</h3><p>Returns the primary index for table <i>tableName</i>. Returns an empty <a href="qsqlindex.html">QSqlIndex</a> if the table doesn't have a primary index. The default implementation returns an empty index.</p>
<h3 class="fn"><a name="record" /><a href="qsqlrecord.html">QSqlRecord</a> QSqlDriver.record (<i>self</i>, <a href="qstring.html">QString</a> <i>tableName</i>)</h3><p>Returns a <a href="qsqlrecord.html">QSqlRecord</a> populated with the names of the fields in table <i>tableName</i>. If no such table exists, an empty record is returned. The default implementation returns an empty record.</p>
<h3 class="fn"><a name="rollbackTransaction" />bool QSqlDriver.rollbackTransaction (<i>self</i>)</h3><p>This function is called to rollback a transaction. If successful, return true, otherwise return false. The default implementation does nothing and returns false.</p>
<p>See also <a href="qsqldriver.html#beginTransaction">beginTransaction</a>() and <a href="qsqldriver.html#commitTransaction">commitTransaction</a>().</p>
<h3 class="fn"><a name="setLastError" />QSqlDriver.setLastError (<i>self</i>, <a href="qsqlerror.html">QSqlError</a> <i>e</i>)</h3><p>This function is used to set the value of the last error, <i>error</i>, that occurred on the database.</p>
<p>See also <a href="qsqldriver.html#lastError">lastError</a>().</p>
<h3 class="fn"><a name="setOpen" />QSqlDriver.setOpen (<i>self</i>, bool <i>o</i>)</h3><p>This function sets the open state of the database to <i>open</i>. Derived classes can use this function to report the status of <a href="qsqldriver.html#open">open</a>().</p>
<p>See also <a href="qsqldriver.html#open">open</a>() and <a href="qsqldriver.html#setOpenError">setOpenError</a>().</p>
<h3 class="fn"><a name="setOpenError" />QSqlDriver.setOpenError (<i>self</i>, bool <i>e</i>)</h3><p>This function sets the open error state of the database to <i>error</i>. Derived classes can use this function to report the status of <a href="qsqldriver.html#open">open</a>(). Note that if <i>error</i> is true the open state of the database is set to closed (i.e., <a href="qsqldriver.html#isOpen">isOpen</a>() returns false).</p>
<p>See also <a href="qsqldriver.html#isOpenError">isOpenError</a>(), <a href="qsqldriver.html#open">open</a>(), and <a href="qsqldriver.html#setOpen">setOpen</a>().</p>
<h3 class="fn"><a name="sqlStatement" /><a href="qstring.html">QString</a> QSqlDriver.sqlStatement (<i>self</i>, <a href="qsqldriver.html#StatementType-enum">StatementType</a> <i>type</i>, <a href="qstring.html">QString</a> <i>tableName</i>, <a href="qsqlrecord.html">QSqlRecord</a> <i>rec</i>, bool <i>preparedStatement</i>)</h3><p>Returns a SQL statement of type <i>type</i> for the table <i>tableName</i> with the values from <i>rec</i>. If <i>preparedStatement</i> is true, the string will contain placeholders instead of values.</p>
<p>This method can be used to manipulate tables without having to worry about database-dependend SQL dialects. For non-prepared statements, the values will be properly escaped.</p>
<h3 class="fn"><a name="tables" /><a href="qstringlist.html">QStringList</a> QSqlDriver.tables (<i>self</i>, <a href="qsql.html#TableType-enum">QSql.TableType</a> <i>tableType</i>)</h3><p>Returns a list of the names of the tables in the database. The default implementation returns an empty list.</p>
<p>The <i>tableType</i> argument describes what types of tables should be returned. Due to binary compatibility, the string contains the value of the enum QSql.TableTypes as text. An empty string should be treated as <a href="qsql.html#TableType-enum">QSql.Tables</a> for backward compatibility.</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt 4.0.1 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.trolltech.com">Trolltech AS</a> 2006</td><td align="right" width="25%">Qt 4.1.4</td></tr></table></div></address></body></html>
|