<?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>QSqlError 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="index.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">QSqlError Class Reference<br /><sup><sup>[<a href="qtsql.html">QtSql</a> module]</sup></sup></h1><p>The QSqlError class provides SQL database error information. <a href="#details">More...</a></p> <h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qsqlerror.html#ErrorType-enum">ErrorType</a></b> { NoError, ConnectionError, StatementError, TransactionError, UnknownError }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qsqlerror.html#QSqlError">__init__</a></b> (<i>self</i>, QString <i>driverText</i> = QString(), QString <i>databaseText</i> = QString(), ErrorType <i>type</i> = QSqlError.NoError, int <i>number</i> = -1)</li><li><div class="fn" /><b><a href="qsqlerror.html#QSqlError-2">__init__</a></b> (<i>self</i>, QSqlError <i>other</i>)</li><li><div class="fn" />QString <b><a href="qsqlerror.html#databaseText">databaseText</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qsqlerror.html#driverText">driverText</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qsqlerror.html#isValid">isValid</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qsqlerror.html#number">number</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qsqlerror.html#setDatabaseText">setDatabaseText</a></b> (<i>self</i>, QString <i>databaseText</i>)</li><li><div class="fn" /><b><a href="qsqlerror.html#setDriverText">setDriverText</a></b> (<i>self</i>, QString <i>driverText</i>)</li><li><div class="fn" /><b><a href="qsqlerror.html#setNumber">setNumber</a></b> (<i>self</i>, int <i>number</i>)</li><li><div class="fn" /><b><a href="qsqlerror.html#setType">setType</a></b> (<i>self</i>, ErrorType <i>type</i>)</li><li><div class="fn" />QString <b><a href="qsqlerror.html#text">text</a></b> (<i>self</i>)</li><li><div class="fn" />ErrorType <b><a href="qsqlerror.html#type">type</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QSqlError class provides SQL database error information.</p> <p>A QSqlError object can provide database-specific error data, including the <a href="qsqlerror.html#driverText">driverText</a>() and <a href="qsqlerror.html#databaseText">databaseText</a>() messages (or both concatenated together as <a href="qsqlerror.html#text">text</a>()), and the error <a href="qsqlerror.html#number">number</a>() and <a href="qsqlerror.html#type">type</a>(). The functions all have setters so that you can create and return QSqlError objects from your own classes, for example from your own SQL drivers.</p> <hr /><h2>Type Documentation</h2><h3 class="fn"><a name="ErrorType-enum" />QSqlError.ErrorType</h3><p>This enum type describes the context in which the error occurred, e.g., a connection error, a statement error, etc.</p> <table class="valuelist"> <tr class="odd" valign="top"> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QSqlError.NoError</tt></td> <td class="topAlign"><tt>0</tt></td> <td class="topAlign">No error occurred.</td> </tr> <tr> <td class="topAlign"><tt>QSqlError.ConnectionError</tt></td> <td class="topAlign"><tt>1</tt></td> <td class="topAlign">Connection error.</td> </tr> <tr> <td class="topAlign"><tt>QSqlError.StatementError</tt></td> <td class="topAlign"><tt>2</tt></td> <td class="topAlign">SQL statement syntax error.</td> </tr> <tr> <td class="topAlign"><tt>QSqlError.TransactionError</tt></td> <td class="topAlign"><tt>3</tt></td> <td class="topAlign">Transaction failed error.</td> </tr> <tr> <td class="topAlign"><tt>QSqlError.UnknownError</tt></td> <td class="topAlign"><tt>4</tt></td> <td class="topAlign">Unknown error.</td> </tr> </table> <hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QSqlError" />QSqlError.__init__ (<i>self</i>, QString <i>driverText</i> = QString(), QString <i>databaseText</i> = QString(), <a href="qsqlerror.html#ErrorType-enum">ErrorType</a> <i>type</i> = QSqlError.NoError, int <i>number</i> = -1)</h3><p>Constructs an error containing the driver error text <i>driverText</i>, the database-specific error text <i>databaseText</i>, the type <i>type</i> and the optional error number <i>number</i>.</p> <h3 class="fn"><a name="QSqlError-2" />QSqlError.__init__ (<i>self</i>, <a href="qsqlerror.html">QSqlError</a> <i>other</i>)</h3><p>Creates a copy of <i>other</i>.</p> <h3 class="fn"><a name="databaseText" />QString QSqlError.databaseText (<i>self</i>)</h3><p>Returns the text of the error as reported by the database. This may contain database-specific descriptions; it may be empty.</p> <p><b>See also</b> <a href="qsqlerror.html#setDatabaseText">setDatabaseText</a>(), <a href="qsqlerror.html#driverText">driverText</a>(), and <a href="qsqlerror.html#text">text</a>().</p> <h3 class="fn"><a name="driverText" />QString QSqlError.driverText (<i>self</i>)</h3><p>Returns the text of the error as reported by the driver. This may contain database-specific descriptions. It may also be empty.</p> <p><b>See also</b> <a href="qsqlerror.html#setDriverText">setDriverText</a>(), <a href="qsqlerror.html#databaseText">databaseText</a>(), and <a href="qsqlerror.html#text">text</a>().</p> <h3 class="fn"><a name="isValid" />bool QSqlError.isValid (<i>self</i>)</h3><p>Returns true if an error is set, otherwise false.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qsqlquerymodel.html">QSqlQueryModel</a></span> model; model<span class="operator">.</span>setQuery(<span class="string">"select * from myTable"</span>); <span class="keyword">if</span> (model<span class="operator">.</span>lastError()<span class="operator">.</span>isValid()) <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> model<span class="operator">.</span>lastError(); </pre> <p><b>See also</b> <a href="qsqlerror.html#type">type</a>().</p> <h3 class="fn"><a name="number" />int QSqlError.number (<i>self</i>)</h3><p>Returns the database-specific error number, or -1 if it cannot be determined.</p> <p><b>See also</b> <a href="qsqlerror.html#setNumber">setNumber</a>().</p> <h3 class="fn"><a name="setDatabaseText" />QSqlError.setDatabaseText (<i>self</i>, QString <i>databaseText</i>)</h3><p>Sets the database error text to the value of <i>databaseText</i>.</p> <p><b>See also</b> <a href="qsqlerror.html#databaseText">databaseText</a>(), <a href="qsqlerror.html#setDriverText">setDriverText</a>(), and <a href="qsqlerror.html#text">text</a>().</p> <h3 class="fn"><a name="setDriverText" />QSqlError.setDriverText (<i>self</i>, QString <i>driverText</i>)</h3><p>Sets the driver error text to the value of <i>driverText</i>.</p> <p><b>See also</b> <a href="qsqlerror.html#driverText">driverText</a>(), <a href="qsqlerror.html#setDatabaseText">setDatabaseText</a>(), and <a href="qsqlerror.html#text">text</a>().</p> <h3 class="fn"><a name="setNumber" />QSqlError.setNumber (<i>self</i>, int <i>number</i>)</h3><p>Sets the database-specific error number to <i>number</i>.</p> <p><b>See also</b> <a href="qsqlerror.html#number">number</a>().</p> <h3 class="fn"><a name="setType" />QSqlError.setType (<i>self</i>, <a href="qsqlerror.html#ErrorType-enum">ErrorType</a> <i>type</i>)</h3><p>Sets the error type to the value of <i>type</i>.</p> <p><b>See also</b> <a href="qsqlerror.html#type">type</a>().</p> <h3 class="fn"><a name="text" />QString QSqlError.text (<i>self</i>)</h3><p>This is a convenience function that returns <a href="qsqlerror.html#databaseText">databaseText</a>() and <a href="qsqlerror.html#driverText">driverText</a>() concatenated into a single string.</p> <p><b>See also</b> <a href="qsqlerror.html#driverText">driverText</a>() and <a href="qsqlerror.html#databaseText">databaseText</a>().</p> <h3 class="fn"><a name="type" /><a href="qsqlerror.html#ErrorType-enum">ErrorType</a> QSqlError.type (<i>self</i>)</h3><p>Returns the error type, or -1 if the type cannot be determined.</p> <p><b>See also</b> <a href="qsqlerror.html#setType">setType</a>().</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.10.3 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt 4.8.5</td></tr></table></div></address></body></html>