source: trunk/doc/html/sql-driver.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 30.2 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/sql-driver.doc:35 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>SQL Module - Drivers</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>SQL Module - Drivers</h1>
33
34
35<p> <ul>
36<li> <a href="#Introduction">Introduction</a>
37<li> <a href="#building">Building the drivers using configure</a>
38<li> <a href="#buildingmanually">Building the plugins manually</a>
39<ul>
40<li> <a href="#QDB2">QDB2</a> - IBM DB2 Driver (v7.1 and higher)
41<li> <a href="#QIBASE">QIBASE</a> - Borland Interbase Driver
42<li> <a href="#QMYSQL3">QMYSQL3</a> - MySQL Driver
43<li> <a href="#QOCI8">QOCI8</a> - Oracle Call Interface Driver, version 8 and 9
44<li> <a href="#QODBC3">QODBC3</a> - Open Database Connectivity Driver
45<li> <a href="#QPSQL7">QPSQL7</a> - PostgreSQL v6.x and v7.x Driver
46<li> <a href="#QSQLITE">QSQLITE</a> - SQLite Driver
47<li> <a href="#QTDS7">QTDS7</a> - Sybase Adaptive Server
48</ul>
49<li> <a href="#troubleshooting">Troubleshooting</a>
50<li> <a href="#development">How to write your own database driver</a>
51</ul>
52<p> <a name="Introduction"></a>
53<h2> Introduction
54</h2>
55<a name="1"></a><p> The <a href="sql.html">SQL Module</a> uses driver <a href="plugins-howto.html">plugins</a> in order to communicate with
56different database APIs. Since the SQL Module API is
57database-independent, all database-specific code is contained within
58these drivers. Several drivers are supplied with Qt and other drivers
59can be added. The driver source code is supplied and can be used as a
60model for <a href="#development">writing your own drivers</a>.
61<p> <em>Note:</em> To build a driver plugin you need to have the appropriate
62client library for your Database Management System (DBMS). This provides
63access to the API exposed by the DBMS, and is typically shipped with it.
64Most installation programs also allow you to install "development
65libraries", and these are what you need. These libraries are responsible
66for the low-level communication with the DBMS.
67<p> The drivers shipped with Qt are:
68<ul>
69<li> <a href="#QDB2">QDB2</a> - IBM DB2 Driver (v7.1 and higher)
70<li> <a href="#QIBASE">QIBASE</a> - Borland Interbase Driver
71<li> <a href="#QMYSQL3">QMYSQL3</a> - MySQL Driver
72<li> <a href="#QOCI8">QOCI8</a> - Oracle Call Interface Driver, version 8, 9 and 10
73<li> <a href="#QODBC3">QODBC3</a> - Open Database Connectivity Driver
74<li> <a href="#QPSQL7">QPSQL7</a> - PostgreSQL v6.x and v7.x Driver
75<li> <a href="#QSQLITE">QSQLITE</a> - SQLite Driver
76<li> <a href="#QTDS7">QTDS7</a> - Sybase Adaptive Server
77</ul>
78<p> Note that not all of the plugins are shipped with the Qt Open Source Edition
79due to license incompatibilities with the GPL.
80<p> <a name="building"></a>
81<h2> Building the drivers using configure
82</h2>
83<a name="2"></a><p> The Qt configure script automatically detects the available client
84libraries on your machine. Run "configure -help" to see what drivers
85can be built. You should get an output similar to this:
86<p> <pre>
87Possible values for &lt;driver&gt;: [ mysql oci odbc psql tds ]
88Auto-Detected on this system: [ mysql psql ]
89</pre>
90
91<p> Note that on Windows, the configure script doesn't do any
92auto-detection.
93<p> The configure script cannot detect the neccessary libraries and include
94files if they are not in the standard paths, so it may be necessary to
95specify these paths using the "-I" and "-L" switches. For example, if
96your MySQL include files are installed in <tt>/usr/local/mysql</tt> (or in
97<tt>C:&#92;mysql&#92;include</tt>
98
99configure: <tt>-I/usr/local/mysql</tt> (or <tt>-I C:&#92;mysql&#92;include</tt>
100
101Windows).
102<p> On Windows the -I parameter doesn't accept spaces in
103filenames, so use the 8.3 name instead, i.e. use <tt>C:&#92;progra~1&#92;mysql</tt>
104instead of <tt>C:&#92;program files&#92;mysql</tt>.
105<p> Use the <tt>-qt-sql-&lt;driver&gt;</tt> parameter to build the database driver
106statically into your Qt library or <tt>-plugin-sql-&lt;driver&gt;</tt> to build
107the driver as a plugin. Look at the sections that follow for
108additional information about required libraries.
109<p> <a name="buildingmanually"></a>
110<h2> Building the plugins manually
111</h2>
112<a name="3"></a><p> <a name="QMYSQL3"></a>
113<h3> QMYSQL3 - MySQL 3.x and MySQL 4.x
114</h3>
115<a name="3-1"></a><p> <!-- index QMYSQL3 --><a name="QMYSQL3"></a>
116<p> <h4> General information
117</h4>
118<a name="3-1-1"></a><p> MySQL 3.x doesn't support SQL transactions by default. There are some
119backends which offer this functionality. Recent versions of the MySQL
120client libraries (>3.23.34) allow you to use transactions on those
121modified servers.
122<p> If you have a recent client library and connect to a
123transaction-enabled MySQL server, a call to the
124<a href="qsqldriver.html#hasFeature">QSqlDriver::hasFeature</a>( QSqlDriver::Transactions ) function returns
125TRUE and SQL transactions can be used.
126<p> If the plugin is compiled against MySQL 4.x client libraries,
127transactions are enabled by default.
128<p> You can find information about MySQL on <a href="http://www.mysql.com">http://www.mysql.com</a>
129<p> <h4> How to build the plugin on Unix/Linux
130</h4>
131<a name="3-1-2"></a><p> You need the MySQL header files and as well as the shared library
132<tt>libmysqlclient.so</tt>. Depending on your Linux distribution you need to
133install a package which is usually called "mysql-devel".
134<p> Tell <a href="qmake-manual.html">qmake</a> where to find the MySQL
135header files and shared libraries (here it is assumed that MySQL is
136installed in <tt>/usr/local</tt>) and run <tt>make</tt>:
137<p> <pre>
138cd $QTDIR/plugins/src/sqldrivers/mysql
139qmake -o Makefile "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient" mysql.pro
140make
141</pre>
142
143<p> <h4> How to build the plugin on Windows
144</h4>
145<a name="3-1-3"></a><p> You need to get the MySQL installation files. Run SETUP.EXE and
146choose "Custom Install". Install the "Libs & Include Files" Module.
147Build the plugin as follows (here it is assumed that MySQL is
148installed in <tt>C:&#92;MYSQL</tt>):
149<p> <pre>
150cd %QTDIR%\plugins\src\sqldrivers\mysql
151qmake -o Makefile "INCLUDEPATH+=C:\MYSQL\INCLUDE" "LIBS+=C:\MYSQL\LIB\OPT\LIBMYSQL.LIB" mysql.pro
152nmake
153</pre>
154
155<p> If you are not using a Microsoft compiler, replace <tt>nmake</tt> with <tt>make</tt> in the statement above.
156<p> <a name="QOCI8"></a>
157<h3> QOCI8 - Oracle Call Interface (OCI)
158</h3>
159<a name="3-2"></a><p> <!-- index QOCI8 --><a name="QOCI8"></a>
160<p> <h4> General information
161</h4>
162<a name="3-2-1"></a><p> The Qt OCI plugin supports both Oracle 8 and Oracle 9. After
163connecting to the Oracle server, the plugin will auto-detect the
164database version and enable features accordingly.
165<p> <h4> Unicode support
166</h4>
167<a name="3-2-2"></a><p> If the Oracle server supports Unicode, the OCI plugin will use UTF-8
168encoding to communicate with the server.
169<p> <h4> BLOB/LOB support
170</h4>
171<a name="3-2-3"></a><p> Binary Large Objects (BLOBs) can be read and written, but be aware
172that this process may require a lot of memory.
173<p> Note that Oracle 9 doesn't support scrollable result sets with LOB
174columns, you have to use a forward only query to select LOB fields
175(see <a href="qsqlquery.html#setForwardOnly">QSqlQuery::setForwardOnly</a>()).
176<p> Inserting BLOBs should be done using either a prepared query where the
177BLOBs are bound to placeholders, or <a href="qsqlcursor.html">QSqlCursor</a> which uses a prepared
178query to do this internally (see $QTDIR/examples/sql/blob).
179<p> <h4> Know problems
180</h4>
181<a name="3-2-4"></a><p> When a query is in forward only mode a call to <a href="qsqlquery.html#last">QSqlQuery::last</a>() will
182position the query on the last record and return TRUE, but subsequent
183calls to <a href="qsqlquery.html#value">QSqlQuery::value</a>() will only return NULLs.
184<p> <h4> How to build the plugin on Unix/Linux
185</h4>
186<a name="3-2-5"></a><p> All files required to build driver should ship with the standard Oracle
187Client install.
188<p> Oracle library files required to build driver:
189<p> <ul>
190<li> <tt>libclntsh.so</tt> (all versions)
191<li> <tt>libwtc8.so</tt> (only Oracle 8) or <tt>libwtc9.so</tt> (only Oracle 9)
192</ul>
193<p> Tell <tt>qmake</tt> where to find the Oracle header files and shared
194libraries (it is assumed that the variable <tt>$ORACLE_HOME</tt> points to
195the directory where Oracle is installed) and run make:
196<p> If you are using Oracle 8:
197<pre>
198cd $QTDIR/plugins/src/sqldrivers/oci
199qmake -o Makefile "INCLUDEPATH+=$ORACLE_HOME/rdbms/public $ORACLE_HOME/rdbms/demo" "LIBS+=-L$ORACLE_HOME/lib -lclntsh -lwtc8" oci.pro
200make
201</pre>
202
203<p> For Oracle version 9:
204<pre>
205cd $QTDIR/plugins/src/sqldrivers/oci
206qmake -o Makefile "INCLUDEPATH+=$ORACLE_HOME/rdbms/public $ORACLE_HOME/rdbms/demo" "LIBS+=-L$ORACLE_HOME/lib -lclntsh -lwtc9" oci.pro
207make
208</pre>
209
210<p> For Oracle version 10:
211<pre>
212cd $QTDIR/plugins/src/sqldrivers/oci
213qmake -o Makefile "INCLUDEPATH+=$ORACLE_HOME/rdbms/public $ORACLE_HOME/rdbms/demo" "LIBS+=-L$ORACLE_HOME/lib -lclntsh" oci.pro
214make
215</pre>
216
217<p> Note that some versions of the OCI client libraries contain a bug
218that makes programs linked to these libraries segfault on exit. This
219only happens if the QOCI8 driver is compiled as a plugin. To work
220around this problem, either compile the driver into the Qt libray
221itself, or configure Qt with the option '-DQT_NO_LIBRARY_UNLOAD'.
222For Oracle 9, it is possible to link to the static OCI library by
223using "LIBS+=$ORACLE_HOME/lib/libclntst9.a".
224<p> <h4> How to build the plugin on Windows
225</h4>
226<a name="3-2-6"></a><p> Choosing the option "Programmer" in the Oracle Client Installer from
227the Oracle Client Installation CD is sufficient to build the plugin.
228<p> Build the plugin as follows (here it is assumed that Oracle Client is
229installed in <tt>C:&#92;oracle</tt>):
230<p> <pre>
231set INCLUDE=%INCLUDE%;c:\oracle\oci\include
232set LIB=%LIB%;c:\oracle\oci\lib\msvc
233cd %QTDIR%\plugins\src\sqldrivers\oci
234qmake -o Makefile oci.pro
235nmake
236</pre>
237
238<p> When you run your application you will also need to add the <tt>oci.dll</tt>
239path to your <tt>PATH</tt> environment variable:
240<p> <pre>
241set PATH=%PATH%;c:\oracle\bin
242</pre>
243
244<p> If you are not using a Microsoft compiler, replace <tt>nmake</tt> with <tt>make</tt> in the statement above.
245<p> <a name="QODBC3"></a>
246<h3> QODBC3 - Open Database Connectivity (ODBC)
247</h3>
248<a name="3-3"></a><p> <!-- index QODBC3 --><a name="QODBC3"></a>
249<p> <h4> General information
250</h4>
251<a name="3-3-1"></a><p> ODBC is a general interface that allows you to connect to multiple
252DBMS using a common interface. The QODBC3 driver allows you to connect
253to an ODBC driver manager and access the available data sources. Note
254that you also need to install and configure ODBC drivers for the ODBC
255driver manager that is installed on your system. The QODBC3 plugin
256then allows you to use these data sources in your Qt project.
257<p> On Windows systems after 95 an ODBC driver manager should be installed
258by default, for Unix systems there are some implementations which must
259be installed first. Note that every client that uses your application
260is required to have an ODBC driver manager installed, otherwise the
261QODBC3 plugin will not work.
262<p> Be aware that when connecting to an ODBC datasource you must pass in
263the name of the ODBC datasource to the <a href="qsqldatabase.html#setDatabaseName">QSqlDatabase::setDatabaseName</a>()
264function: not the actual database name.
265<p> The QODBC3 Plugin needs an ODBC compliant driver manager version 2.0 or
266later to work. Some ODBC drivers claim to be version 2.0 compliant,
267but do not offer all the necessary functionality. The QODBC3 plugin
268therefore checks whether the data source can be used after a
269connection has been established and refuses to work if the check
270fails. If you don't like this behaviour, you can remove the <tt>#define ODBC_CHECK_DRIVER</tt> line from the file <tt>qsql_odbc.cpp</tt>. Do this at
271your own risk!
272<p> If you experience very slow access of the ODBC datasource, make sure
273that ODBC call tracing is turned off in the ODBC datasource manager.
274<p> <h4> Unicode support
275</h4>
276<a name="3-3-2"></a><p> The QODBC3 Plugin will use the Unicode API if UNICODE is defined. On
277Windows NT based systems, this is the default. Note that the ODBC
278driver and the DBMS have to support Unicode as well.
279<p> For the Oracle 9 ODBC driver (Windows), it is neccessary to check
280"SQL_WCHAR support" in the ODBC driver manager otherwise Oracle
281will convert all Unicode strings to local 8 bit.
282<p> <h4> How to build the plugin on Unix/Linux
283</h4>
284<a name="3-3-3"></a><p> It is recommended that you use unixODBC. You can find the latest
285version and ODBC drivers at <a href="http://www.unixodbc.org">http://www.unixodbc.org</a>.
286You need the unixODBC header files and shared libraries.
287<p> Tell <tt>qmake</tt> where to find the unixODBC header files and shared
288libraries (here it is assumed that unixODBC is installed in
289<tt>/usr/local/unixODBC</tt>) and run <tt>make</tt>:
290<p> <pre>
291cd $QTDIR/plugins/src/sqldrivers/odbc
292qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc"
293make
294</pre>
295
296<p> <h4> How to build the plugin on Windows
297</h4>
298<a name="3-3-4"></a><p> The ODBC header and include files should already be installed in the
299right directories. You just have to build the plugin as follows:
300<p> <pre>
301cd %QTDIR%\plugins\src\sqldrivers\odbc
302qmake -o Makefile odbc.pro
303nmake
304</pre>
305
306<p> If you are not using a Microsoft compiler, replace <tt>nmake</tt> with <tt>make</tt> in the statement above.
307<p> <a name="QPSQL7"></a>
308<h3> QPSQL7 - PostgreSQL version 6 and 7
309</h3>
310<a name="3-4"></a><p> <!-- index QPSQL7 --><a name="QPSQL7"></a>
311<p> <h4> General information
312</h4>
313<a name="3-4-1"></a><p> The QPSQL7 driver supports both version 6 and 7 of PostgreSQL. We
314recommend compiling the plugin with a recent version of the PostgreSQL
315client library (libpq) because it is more stable and still backwards
316compatible.
317<p> If you want to link the plugin against the libpq shipped with version
3186 we recommend a recent version like PostgreSQL 6.5.3, otherwise a
319connection to a version 7 server may not work.
320<p> The driver auto-detects the server version of PostgreSQL after a
321connection was successful. If the server is too old or the version
322information cannot be determined a warning is issued.
323<p> For more information about PostgreSQL visit <a href="http://www.postgresql.org">http://www.postgresql.org</a>.
324<p> <h4> Unicode support
325</h4>
326<a name="3-4-2"></a><p> The QPSQL7 driver automatically detects whether the PostgreSQL
327database you are connecting to supports Unicode or not. Unicode is
328automatically used if the server supports it. Note that the driver
329only supports the UTF-8 encoding. If your database uses any other
330encoding, the server must be compiled with Unicode conversion
331support.
332<p> Unicode support was introduced in PostgreSQL version 7.1 and it will
333only work if both the server and the client library have been compiled
334with multibyte support. More information about how to set up a
335multibyte enabled PostgreSQL server can be found in the PostgreSQL
336Administrator Guide, Chapter 5.
337<p> <h4> BLOB support
338</h4>
339<a name="3-4-3"></a><p> Binary Large Objects are supported through the <tt>BYTEA</tt> field type in
340PostgreSQL versions >= 7.1. Fields of type <tt>OID</tt> can be read, but not
341written. Use the PostgreSQL command <tt>lo_import</tt> to insert binary data
342into <tt>OID</tt> fields.
343<p> <h4> How to build the plugin on Unix/Linux
344</h4>
345<a name="3-4-4"></a><p> Just installing the pq client library and the corresponding header
346files is not sufficient. You have to get the PostgreSQL source
347distribution and run the configure script. If you've already installed
348a binary distribution you don't need to build it. The source
349distribution is needed because the QPSQL7 plugin relies on a couple of
350header files that are usually not a part of the binary distribution.
351<p> To make <tt>qmake</tt> find the PostgreSQL header files and shared
352libraries, run <tt>qmake</tt> the following way (assuming that the
353PostgreSQL sources can be found in <tt>/usr/src/psql</tt>):
354<p> <pre>
355cd $QTDIR/plugins/src/sqldrivers/psql
356qmake -o Makefile "INCLUDEPATH+=/usr/src/psql/src/include /usr/src/psql/src/interfaces/libpq" "LIBS+=-L/usr/lib -lpq" psql.pro
357make
358</pre>
359
360<p> <h4> How to build the plugin on Windows
361</h4>
362<a name="3-4-5"></a><p> Unpack and build the PostgreSQL source distribution as described in
363the PostgreSQL documentation. Assuming the PostgreSQL sources resides
364in <tt>C:&#92;psql</tt>, build the plugin as follows:
365<p> <pre>
366cd %QTDIR%\plugins\src\sqldrivers\psql
367qmake -o Makefile "INCLUDEPATH+=C:\psql\src\include C:\psql\src\interfaces\libpq" psql.pro
368nmake
369</pre>
370
371<p> Remember to add the path to the <tt>libpq.dll</tt> library to your PATH
372environment variable so that Windows can find it. In this case that
373would be <tt>C:&#92;psql&#92;src&#92;interfaces&#92;libpq&#92;Release</tt>. If you are not using a
374Microsoft compiler, replace <tt>nmake</tt> with <tt>make</tt> in the statement
375above.
376<p> <a name="QTDS7"></a>
377<h3> QTDS7 - Sybase Adaptive Server
378</h3>
379<a name="3-5"></a><p> <!-- index QTDS7 --><a name="QTDS7"></a>
380<p> <h4> How to build the plugin on Unix/Linux
381</h4>
382<a name="3-5-1"></a><p> Under Unix, two libraries are available which support the TDS protocol:
383<p> - FreeTDS, a free implementation of the TDS protocol
384(<a href="http://www.freetds.org">http://www.freetds.org</a>). Note that FreeTDS is not yet stable,
385so some functionality may not work as expected.
386<p> - Sybase Open Client, available from <a href="http://www.sybase.com">http://www.sybase.com</a>.
387Note for Linux users: Get the Open Client RPM from
388<a href="http://linux.sybase.com">http://linux.sybase.com</a>.
389<p> Regardless of which library you use, the shared object file
390<tt>libsybdb.so</tt> is needed. Set the SYBASE environment variable to
391point to the directory where you installed the client library and
392execute <tt>qmake</tt>:
393<p> <pre>
394cd $QTDIR/plugins/src/sqldrivers/tds
395qmake -o Makefile "INCLUDEPATH=$SYBASE/include" "LIBS=-L$SYBASE/lib -lsybdb"
396make
397</pre>
398
399<p> <h4> How to build the plugin on Windows
400</h4>
401<a name="3-5-2"></a><p> You can either use the DB-Library supplied by Microsoft or the Sybase
402Open Client (<a href="http://www.sybase.com">http://www.sybase.com</a>). You must include <tt>NTWDBLIB.LIB</tt> to build the plugin:
403<p> <pre>
404cd %QTDIR%\plugins\src\sqldrivers\tds
405qmake -o Makefile "LIBS+=NTWDBLIB.LIB" tds.pro
406nmake
407</pre>
408
409<p> By default the Microsoft library is used on Windows, if you want to force
410the use of the Sybase Open Client, you must define
411<tt>Q_USE_SYBASE</tt> in <tt>%QTDIR%&#92;src&#92;sql&#92;drivers&#92;tds&#92;qsql_tds.cpp</tt>.
412<p> <a name="QDB2"></a>
413<h3> QDB2 - IBM DB2 Driver (v7.1 or higher)
414</h3>
415<a name="3-6"></a><p> <!-- index QDB2 --><a name="QDB2"></a>
416<p> <h4> General information
417</h4>
418<a name="3-6-1"></a><p> The Qt DB2 plugin makes it possible to access IBM DB2 databases. It
419has been tested with IBM DB2 v7.1 and 7.2. You have to install the IBM
420DB2 development client library, which contains the header and library
421files necessary for compiling the QDB2 plugin.
422<p> The QDB2 driver supports prepared queries, reading/writing of Unicode
423strings and reading/writing of BLOBs.
424<p> We suggest using a forward-only query when calling stored procedures
425in DB2 (see <a href="qsqlquery.html#setForwardOnly">QSqlQuery::setForwardOnly</a>()).
426<p> <h4> How to build the plugin on Unix/Linux
427</h4>
428<a name="3-6-2"></a><p> <pre>
429cd $QTDIR/plugins/src/sqldrivers/db2
430qmake -o Makefile "INCLUDEPATH+=$DB2DIR/include" "LIBS+=-L$DB2DIR/lib -ldb2"
431make
432</pre>
433
434<p> <h4> How to build the plugin on Windows
435</h4>
436<a name="3-6-3"></a><p> The DB2 header and include files should already be installed in the
437right directories. You just have to build the plugin as follows:
438<p> <pre>
439cd %QTDIR%\plugins\src\sqldrivers\db2
440qmake -o Makefile "INCLUDEPATH+=&lt;DB2 home&gt;/sqllib/include" "LIBS+=&lt;DB2 home&gt;/sqllib/lib/db2cli.lib"
441nmake
442</pre>
443
444<p> If you are not using a Microsoft compiler, replace <tt>nmake</tt>
445with <tt>make</tt> in the statement above.
446<p> <a name="QSQLITE"></a>
447<h3> QSQLITE - SQLite Driver
448</h3>
449<a name="3-7"></a><p> <!-- index QSQLITE --><a name="QSQLITE"></a>
450<p> The Qt SQLite plugin makes it possible to access SQLite databases.
451SQLite is an in-process database, meaning that it is not necessary
452to have a database server. SQLite operates on a single file, which has
453to be set as database name when opening a connection. If the file does
454not exist, SQLite will try to create it. SQLite also supports in-memory
455databases, simply pass ":memory:" as the database name.
456<p> SQLite has some restrictions regarding multiple users and
457multiple transactions. If you try to read/write on a resource from different
458transactions, your application might freeze until one transaction commits
459or rolls back.
460<p> SQLite has no support for types, every value is treated as character data.
461BLOBs are therefore not supported.
462<p> You can find information about SQLite on <a href="http://www.sqlite.org">http://www.sqlite.org</a>.
463<p> SQLite is shipped as third party library within Qt. It can be built by
464passing the following parameters to the configure script:
465<tt>-plugin-sql-sqlite</tt> (as plugin) or <tt>-qt-sql-sqlite</tt> (linked
466directly into the Qt library).
467<p> If you don't want to use the SQLite library shipped with Qt, you can
468build it manually (replace <tt>$SQLITE</tt> by the directory where SQLite
469resides):
470<p> <pre>
471cd $QTDIR/plugins/src/sqldrivers/sqlite
472qmake -o Makefile "INCLUDEPATH+=$SQLITE/include" "LIBS+=-L$SQLITE/lib -lsqlite"
473make
474</pre>
475
476<p> <a name="QIBASE"></a>
477<h3> QIBASE - Borland Interbase Driver
478</h3>
479<a name="3-8"></a><p> <!-- index QIBASE --><a name="QIBASE"></a>
480<p> <h4> General information
481</h4>
482<a name="3-8-1"></a><p> The Qt Interbase plugin makes it possible to access the Interbase and
483Firebird databases. Interbase can either be used as a client/server or
484without a server operating on local files. The database file must
485exist before a connection can be established.
486<p> Note that Interbase requires you to specify the full path to the
487database file, no matter whether it is stored locally or on another
488server.
489<p> <pre>
490 myDatabase-&gt;setHostName("MyServer");
491 myDatabase-&gt;setDatabaseName("C:\\test.gdb");
492</pre>
493
494<p> You need the Interbase/Firebird development headers and libraries
495to build this plugin.
496<p> Due to the GPL, users of the Qt Open Source Edition are not allowed to link
497this plugin to the commercial editions of Interbase. Please use Firebird
498or the free edition of Interbase.
499<p> <h4> How to build the plugin on Unix/Linux
500</h4>
501<a name="3-8-2"></a><p> The following assumes Interbase or Firebird is installed in
502<tt>/opt/interbase</tt>:
503<p> <pre>
504cd $QTDIR/plugins/src/sqldrivers/ibase
505qmake -o Makefile "INCLUDEPATH+=/opt/interbase/include" "LIBS+=-L/opt/interbase/lib" ibase.pro
506make
507</pre>
508
509<p> <h4> How to build the plugin on Windows
510</h4>
511<a name="3-8-3"></a><p> The following assumes Interbase or Firebird is installed in
512<tt>C:&#92;interbase</tt>:
513<p> <pre>
514cd %QTDIR%\plugins\src\sqldrivers\ibase
515qmake -o Makefile "INCLUDEPATH+=C:\interbase\include" ibase.pro
516nmake
517</pre>
518
519<p> If you are not using a Microsoft compiler, replace <tt>nmake</tt>
520with <tt>make</tt> in the statement above.
521<p> Note that <tt>C:&#92;interbase&#92;bin</tt> must be in the PATH.
522<p> <a name="troubleshooting"></a>
523<h2> Troubleshooting
524</h2>
525<a name="4"></a><p> You should always use client libraries that have been compiled with
526the same compiler as you are using for your project. If you cannot get
527a source distibution to compile the client libraries yourself, you
528must make sure that the pre-compiled library is compatible with
529your compiler, otherwise you will get a lot of "undefined symbols"
530errors. Some compilers have tools to convert libraries, e.g. Borland
531ships the tool <tt>COFF2OMF.EXE</tt> to convert libraries that have been
532generated with Microsoft Visual C++.
533<p> If the compilation of a plugin succeeds but it cannot be loaded,
534make sure that the following requirements are met:
535<p> <ul>
536<li> Ensure that you are using a shared Qt library; you cannot use the
537plugins with a static build.
538<li> Ensure that the environment variable <tt>QTDIR</tt> points to the right
539directory. Go to the <tt>$QTDIR/plugins/sqldrivers</tt> directory and
540make sure that the plugin exists in that directory.
541<li> Ensure that the client libraries of the DBMS are available on the
542system. On Unix, run the command <tt>ldd</tt> and pass the name of the
543plugin as parameter, for example <tt>ldd libqsqlmysql.so</tt>. You will
544get a warning if any of the client libraries couldn't be found.
545On Windows, you can use the dependency walker of Visual Studio.
546</ul>
547<p> If you are experiencing problems with loading plugins, and see output
548like this
549<p> <pre>
550QSqlDatabase warning: QMYSQL3 driver not loaded
551QSqlDatabase: available drivers: QMYSQL3
552</pre>
553
554<p> the problem is probably that the plugin had the wrong build key. For
555debugging purposes, remove the corresponding entry in the
556$HOME/.qt/qt_plugins_(qtversion).rc file.
557<p> The next time you try to load this plugin, it will give you a more detailed
558error message.
559<p> <a name="development"></a>
560<h2> How to write your own database driver
561</h2>
562<a name="5"></a><p> <a href="qsqldatabase.html">QSqlDatabase</a> is responsible for loading and managing database driver
563plugins. When a database is added (see <a href="qsqldatabase.html#addDatabase">QSqlDatabase::addDatabase</a>()),
564the appropriate driver plugin is loaded (using <a href="qsqldriverplugin.html">QSqlDriverPlugin</a>).
565QSqlDatabase relies on the driver plugin to provide interfaces for
566<a href="qsqldriver.html">QSqlDriver</a> and <a href="qsqlresult.html">QSqlResult</a>.
567<p> QSqlDriver is an abstract base class which defines the functionality
568of a SQL database driver. This includes functions such as
569<a href="qsqldriver.html#open">QSqlDriver::open</a>() and <a href="qsqldriver.html#close">QSqlDriver::close</a>(). QSqlDriver is responsible
570for connecting to a database, establish the proper environment, etc.
571In addition, QSqlDriver can create <a href="qsqlquery.html">QSqlQuery</a> objects appropriate for
572the particular database API. QSqlDatabase forwards many of its
573function calls directly to QSqlDriver which provides the concrete
574implementation.
575<p> QSqlResult is an abstract base class which defines the functionality
576of a SQL database query. This includes statements such as <tt>SELECT</tt>,
577<tt>UPDATE</tt>, and <tt>ALTER TABLE</tt>. QSqlResult contains functions such as
578QSqlResult::next() and QSqlResult::value(). QSqlResult is responsible
579for sending queries to the database, returning result data, etc.
580QSqlQuery forwards many of its function calls directly to <a href="qsqlresult.html">QSqlResult</a>
581which provides the concrete implementation.
582<p> <a href="qsqldriver.html">QSqlDriver</a> and QSqlResult are closely connected. When implementing a
583Qt SQL driver, both of these classes must to be subclassed and the
584abstract virtual methods in each class must be implemented.
585<p> To implement a Qt SQL driver as a plugin (so that it is recognized and
586loaded by the Qt library at runtime), the driver must use the
587<tt>Q_EXPORT_PLUGIN</tt> macro. Read the <a href="plugins-howto.html">Qt
588Plugin</a> documentation for more information on this. You can
589also check out how this is done in the SQL plugins that is provided
590with Qt in <tt>QTDIR/plugins/src/sqldrivers</tt> and
591<tt>QTDIR/src/sql/drivers</tt>.
592<p> The following code can be used as a skeleton for a SQL driver:
593<p> <pre>
594class QNullResult : public <a href="qsqlresult.html">QSqlResult</a>
595{
596public:
597 QNullResult( const <a href="qsqldriver.html">QSqlDriver</a>* d ): <a href="qsqlresult.html">QSqlResult</a>( d ) {}
598 ~QNullResult() {}
599protected:
600 <a href="qvariant.html">QVariant</a> data( int ) { return QVariant(); }
601 bool reset ( const <a href="qstring.html">QString</a>&amp; ) { return FALSE; }
602 bool fetch( int ) { return FALSE; }
603 bool fetchFirst() { return FALSE; }
604 bool fetchLast() { return FALSE; }
605 bool isNull( int ) { return FALSE; }
606 <a href="qsqlrecord.html">QSqlRecord</a> record() { return QSqlRecord(); }
607 int size() { return 0; }
608 int numRowsAffected() { return 0; }
609};
610
611class QNullDriver : public <a href="qsqldriver.html">QSqlDriver</a>
612{
613public:
614 QNullDriver(): <a href="qsqldriver.html">QSqlDriver</a>() {}
615 ~QNullDriver() {}
616 bool hasFeature( DriverFeature ) const { return FALSE; }
617 bool open( const <a href="qstring.html">QString</a>&amp;,
618 const <a href="qstring.html">QString</a>&amp;,
619 const <a href="qstring.html">QString</a>&amp;,
620 const <a href="qstring.html">QString</a>&amp;,
621 int ) { return FALSE; }
622 void close() {}
623 <a href="qsqlquery.html">QSqlQuery</a> createQuery() const { return QSqlQuery( new QNullResult( this ) ); }
624};
625</pre>
626
627<p>
628<!-- eof -->
629<p><address><hr><div align=center>
630<table width=100% cellspacing=0 border=0><tr>
631<td>Copyright &copy; 2007
632<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
633<td align=right><div align=right>Qt 3.3.8</div>
634</table></div></address></body>
635</html>
Note: See TracBrowser for help on using the repository browser.