<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- /home/reggie/tmp/qt-3.1-reggie-23625/qt-x11-free-3.1.1/src/sql/qsqldriver.cpp:51 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>QSqlDriver Class</title> <style type="text/css"><!-- h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } body { background: #ffffff; color: black; } --></style> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr bgcolor="#E5E5E5"> <td 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="mainclasses.html"> <font color="#004faf">Main Classes</font></a> | <a href="annotated.html"> <font color="#004faf">Annotated</font></a> | <a href="groups.html"> <font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"> <font color="#004faf">Functions</font></a> </td> <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QSqlDriver Class Reference<br><small>[<a href="sql.html">sql module</a>]</small></h1> <p>The QSqlDriver class is an abstract base class for accessing SQL databases. <a href="#details">More...</a> <p><tt>#include <<a href="qsqldriver-h.html">qsqldriver.h</a>></tt> <p>Inherits <a href="qobject.html">QObject</a>. <p><a href="qsqldriver-members.html">List of all member functions.</a> <h2>Public Members</h2> <ul> <li><div class=fn>enum <a href="#DriverFeature-enum"><b>DriverFeature</b></a> { Transactions, QuerySize, BLOB, Unicode, PreparedQueries, NamedPlaceholders, PositionalPlaceholders }</div></li> <li><div class=fn><a href="#QSqlDriver"><b>QSqlDriver</b></a> ( QObject * parent = 0, const char * name = 0 )</div></li> <li><div class=fn><a href="#~QSqlDriver"><b>~QSqlDriver</b></a> ()</div></li> <li><div class=fn>bool <a href="#isOpen"><b>isOpen</b></a> () const</div></li> <li><div class=fn>bool <a href="#isOpenError"><b>isOpenError</b></a> () const</div></li> <li><div class=fn>virtual bool <a href="#beginTransaction"><b>beginTransaction</b></a> ()</div></li> <li><div class=fn>virtual bool <a href="#commitTransaction"><b>commitTransaction</b></a> ()</div></li> <li><div class=fn>virtual bool <a href="#rollbackTransaction"><b>rollbackTransaction</b></a> ()</div></li> <li><div class=fn>virtual QStringList <a href="#tables"><b>tables</b></a> ( const QString & user ) const</div></li> <li><div class=fn>virtual QSqlIndex <a href="#primaryIndex"><b>primaryIndex</b></a> ( const QString & tableName ) const</div></li> <li><div class=fn>virtual QSqlRecord <a href="#record"><b>record</b></a> ( const QString & tableName ) const</div></li> <li><div class=fn>virtual QSqlRecord <a href="#record-2"><b>record</b></a> ( const QSqlQuery & query ) const</div></li> <li><div class=fn>virtual QSqlRecordInfo <a href="#recordInfo"><b>recordInfo</b></a> ( const QString & tablename ) const</div></li> <li><div class=fn>virtual QSqlRecordInfo <a href="#recordInfo-2"><b>recordInfo</b></a> ( const QSqlQuery & query ) const</div></li> <li><div class=fn>virtual QString <a href="#nullText"><b>nullText</b></a> () const</div></li> <li><div class=fn>virtual QString <a href="#formatValue"><b>formatValue</b></a> ( const QSqlField * field, bool trimStrings = FALSE ) const</div></li> <li><div class=fn>QSqlError <a href="#lastError"><b>lastError</b></a> () const</div></li> <li><div class=fn>virtual bool <a href="#hasFeature"><b>hasFeature</b></a> ( DriverFeature f ) const = 0</div></li> <li><div class=fn>virtual bool <a href="#open"><b>open</b></a> ( const QString & db, const QString & user = QString::null, const QString & password = QString::null, const QString & host = QString::null, int port = -1 ) = 0</div></li> <li><div class=fn>virtual void <a href="#close"><b>close</b></a> () = 0</div></li> <li><div class=fn>virtual QSqlQuery <a href="#createQuery"><b>createQuery</b></a> () const = 0</div></li> </ul> <h2>Protected Members</h2> <ul> <li><div class=fn>virtual void <a href="#setOpen"><b>setOpen</b></a> ( bool o )</div></li> <li><div class=fn>virtual void <a href="#setOpenError"><b>setOpenError</b></a> ( bool e )</div></li> <li><div class=fn>virtual void <a href="#setLastError"><b>setLastError</b></a> ( const QSqlError & e )</div></li> </ul> <hr><a name="details"></a><h2>Detailed Description</h2> The QSqlDriver class is an abstract base class for accessing SQL databases. <p> <p> This class should not be used directly. Use <a href="qsqldatabase.html">QSqlDatabase</a> instead. <p>See also <a href="database.html">Database Classes</a>. <hr><h2>Member Type Documentation</h2> <h3 class=fn><a name="DriverFeature-enum"></a>QSqlDriver::DriverFeature</h3> <p> This enum contains a list of features a driver may support. Use <a href="#hasFeature">hasFeature</a>() to query whether a feature is supported or not. <ul> <li><tt>QSqlDriver::Transactions</tt> - whether the driver supports SQL transactions <li><tt>QSqlDriver::QuerySize</tt> - 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 <li><tt>QSqlDriver::BLOB</tt> - whether the driver supports Binary Large Object fields <li><tt>QSqlDriver::Unicode</tt> - whether the driver supports Unicode strings if the database server does <li><tt>QSqlDriver::PreparedQueries</tt> - whether the driver supports prepared query execution <li><tt>QSqlDriver::NamedPlaceholders</tt> - whether the driver supports usage of named placeholders <li><tt>QSqlDriver::PositionalPlaceholders</tt> - whether the driver supports usage of positional placeholders </ul><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="#hasFeature">hasFeature</a>(). <hr><h2>Member Function Documentation</h2> <h3 class=fn><a name="QSqlDriver"></a>QSqlDriver::QSqlDriver ( <a href="qobject.html">QObject</a> * parent = 0, const char * name = 0 ) </h3> Default constructor. Creates a new driver with parent <em>parent</em>, called <em>name</em>. <p> <h3 class=fn><a name="~QSqlDriver"></a>QSqlDriver::~QSqlDriver () </h3> Destroys the object and frees any allocated resources. <h3 class=fn>bool <a name="beginTransaction"></a>QSqlDriver::beginTransaction ()<tt> [virtual]</tt> </h3> Protected function which derived classes can reimplement to begin a transaction. If successful, return TRUE, otherwise return FALSE. The default implementation returns FALSE. <p> <p>See also <a href="#commitTransaction">commitTransaction</a>() and <a href="#rollbackTransaction">rollbackTransaction</a>(). <h3 class=fn>void <a name="close"></a>QSqlDriver::close ()<tt> [pure virtual]</tt> </h3> <p> Derived classes must reimplement this abstract virtual function in order to close the database connection. Return TRUE on success, FALSE on failure. <p> <p>See also <a href="#setOpen">setOpen</a>(). <p> <h3 class=fn>bool <a name="commitTransaction"></a>QSqlDriver::commitTransaction ()<tt> [virtual]</tt> </h3> Protected function which derived classes can reimplement to commit a transaction. If successful, return TRUE, otherwise return FALSE. The default implementation returns FALSE. <p> <p>See also <a href="#beginTransaction">beginTransaction</a>() and <a href="#rollbackTransaction">rollbackTransaction</a>(). <h3 class=fn><a href="qsqlquery.html">QSqlQuery</a> <a name="createQuery"></a>QSqlDriver::createQuery () const<tt> [pure virtual]</tt> </h3> <p> Creates an empty SQL result on the database. Derived classes must reimplement this function and return a <a href="qsqlquery.html">QSqlQuery</a> object appropriate for their database to the caller. <p> <h3 class=fn><a href="qstring.html">QString</a> <a name="formatValue"></a>QSqlDriver::formatValue ( const <a href="qsqlfield.html">QSqlField</a> * field, bool trimStrings = FALSE ) const<tt> [virtual]</tt> </h3> Returns a string representation of the <em>field</em> value for the database. This is used, for example, when constructing INSERT and UPDATE statements. <p> The default implementation returns the value formatted as a string according to the following rules: <p> <ul> <p> <li> If <em>field</em> is NULL, <a href="#nullText">nullText</a>() is returned. <p> <li> If <em>field</em> is character data, the value is returned enclosed in single quotation marks, which is appropriate for many SQL databases. Any embedded single-quote characters are escaped (replaced with two single-quote characters). If <em>trimStrings</em> is TRUE (the default is FALSE), all trailing whitespace is trimmed from the field. <p> <li> If <em>field</em> is date/time data, the value is formatted in ISO format and enclosed in single quotation marks. If the date/time data is invalid, nullText() is returned. <p> <li> If <em>field</em> is bytearray data, and the driver can edit binary fields, the value is formatted as a hexadecimal string. <p> <li> For any other field type toString() will be called on its value and the result returned. <p> </ul> <p> <p>See also <a href="qvariant.html#toString">QVariant::toString</a>(). <p> <h3 class=fn>bool <a name="hasFeature"></a>QSqlDriver::hasFeature ( <a href="qsqldriver.html#DriverFeature-enum">DriverFeature</a> f ) const<tt> [pure virtual]</tt> </h3> <p> Returns TRUE if the driver supports feature <em>f</em>; otherwise returns FALSE. <p> Note that some databases need to be <a href="#open">open</a>() before this can be determined. <p> <p>See also <a href="#DriverFeature-enum">DriverFeature</a>. <h3 class=fn>bool <a name="isOpen"></a>QSqlDriver::isOpen () const </h3> Returns TRUE if the database connection is open; otherwise returns FALSE. <h3 class=fn>bool <a name="isOpenError"></a>QSqlDriver::isOpenError () const </h3> Returns TRUE if the there was an error opening the database connection; otherwise returns FALSE. <h3 class=fn><a href="qsqlerror.html">QSqlError</a> <a name="lastError"></a>QSqlDriver::lastError () const </h3> Returns a <a href="qsqlerror.html">QSqlError</a> object which contains information about the last error that occurred on the database. <h3 class=fn><a href="qstring.html">QString</a> <a name="nullText"></a>QSqlDriver::nullText () const<tt> [virtual]</tt> </h3> Returns a string representation of the NULL value for the database. This is used, for example, when constructing INSERT and UPDATE statements. The default implementation returns the string "NULL". <h3 class=fn>bool <a name="open"></a>QSqlDriver::open ( const <a href="qstring.html">QString</a> & db, const <a href="qstring.html">QString</a> & user = QString::null, const <a href="qstring.html">QString</a> & password = QString::null, const <a href="qstring.html">QString</a> & host = QString::null, int port = -1 )<tt> [pure virtual]</tt> </h3> <p> Derived classes must reimplement this abstract virtual function in order to open a database connection on database <em>db</em>, using user name <em>user</em>, password <em>password</em>, host <em>host</em> and port <em>port</em>. <p> The function <em>must</em> return TRUE on success and FALSE on failure. <p> <p>See also <a href="#setOpen">setOpen</a>(). <p> <h3 class=fn><a href="qsqlindex.html">QSqlIndex</a> <a name="primaryIndex"></a>QSqlDriver::primaryIndex ( const <a href="qstring.html">QString</a> & tableName ) const<tt> [virtual]</tt> </h3> Returns the primary index for table <em>tableName</em>. 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. <h3 class=fn><a href="qsqlrecord.html">QSqlRecord</a> <a name="record"></a>QSqlDriver::record ( const <a href="qstring.html">QString</a> & tableName ) const<tt> [virtual]</tt> </h3> Returns a <a href="qsqlrecord.html">QSqlRecord</a> populated with the names of the fields in table <em>tableName</em>. If no such table exists, an empty record is returned. The default implementation returns an empty record. <h3 class=fn><a href="qsqlrecord.html">QSqlRecord</a> <a name="record-2"></a>QSqlDriver::record ( const <a href="qsqlquery.html">QSqlQuery</a> & query ) const<tt> [virtual]</tt> </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 the fields in the SQL <em>query</em>. The default implementation returns an empty record. <h3 class=fn><a href="qsqlrecordinfo.html">QSqlRecordInfo</a> <a name="recordInfo"></a>QSqlDriver::recordInfo ( const <a href="qstring.html">QString</a> & tablename ) const<tt> [virtual]</tt> </h3> Returns a <a href="qsqlrecordinfo.html">QSqlRecordInfo</a> object with meta data about the table <em>tablename</em>. <h3 class=fn><a href="qsqlrecordinfo.html">QSqlRecordInfo</a> <a name="recordInfo-2"></a>QSqlDriver::recordInfo ( const <a href="qsqlquery.html">QSqlQuery</a> & query ) const<tt> [virtual]</tt> </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 less information than the <a href="#recordInfo">recordInfo</a>() function which takes the name of a table as parameter. <h3 class=fn>bool <a name="rollbackTransaction"></a>QSqlDriver::rollbackTransaction ()<tt> [virtual]</tt> </h3> Protected function which derived classes can reimplement to rollback a transaction. If successful, return TRUE, otherwise return FALSE. The default implementation returns FALSE. <p> <p>See also <a href="#beginTransaction">beginTransaction</a>() and <a href="#commitTransaction">commitTransaction</a>(). <h3 class=fn>void <a name="setLastError"></a>QSqlDriver::setLastError ( const <a href="qsqlerror.html">QSqlError</a> & e )<tt> [virtual protected]</tt> </h3> Protected function which allows derived classes to set the value of the last error, <em>e</em>, that occurred on the database. <p> <p>See also <a href="#lastError">lastError</a>(). <h3 class=fn>void <a name="setOpen"></a>QSqlDriver::setOpen ( bool o )<tt> [virtual protected]</tt> </h3> Protected function which sets the open state of the database to <em>o</em>. Derived classes can use this function to report the status of <a href="#open">open</a>(). <p> <p>See also <a href="#open">open</a>() and <a href="#setOpenError">setOpenError</a>(). <h3 class=fn>void <a name="setOpenError"></a>QSqlDriver::setOpenError ( bool e )<tt> [virtual protected]</tt> </h3> Protected function which sets the open error state of the database to <em>e</em>. Derived classes can use this function to report the status of <a href="#open">open</a>(). Note that if <em>e</em> is TRUE the open state of the database is set to closed (i.e. <a href="#isOpen">isOpen</a>() returns FALSE). <p> <p>See also <a href="#open">open</a>(). <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="tables"></a>QSqlDriver::tables ( const <a href="qstring.html">QString</a> & user ) const<tt> [virtual]</tt> </h3> Returns a list of tables in the database. The default implementation returns an empty list. <p> Currently the <em>user</em> argument is unused. <!-- eof --> <hr><p> This file is part of the <a href="index.html">Qt toolkit</a>. Copyright © 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 © 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.1.1</div> </table></div></address></body> </html>