source: trunk/doc/src/snippets/code/doc_src_sql-driver.qdoc

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:BSD$
10** You may use this file under the terms of the BSD license as follows:
11**
12** "Redistribution and use in source and binary forms, with or without
13** modification, are permitted provided that the following conditions are
14** met:
15** * Redistributions of source code must retain the above copyright
16** notice, this list of conditions and the following disclaimer.
17** * Redistributions in binary form must reproduce the above copyright
18** notice, this list of conditions and the following disclaimer in
19** the documentation and/or other materials provided with the
20** distribution.
21** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22** the names of its contributors may be used to endorse or promote
23** products derived from this software without specific prior written
24** permission.
25**
26** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41//! [0]
42-no-sql-<driver> ... Disable SQL <driver> entirely.
43-qt-sql-<driver> ... Enable a SQL <driver> in the Qt Library, by default
44 none are turned on.
45-plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to
46 at run time.
47
48 Possible values for <driver>:
49 [ db2 ibase mysql oci odbc psql sqlite sqlite2 tds ]
50//! [0]
51
52
53//! [1]
54create procedure qtestproc (OUT param1 INT, OUT param2 INT)
55BEGIN
56 set param1 = 42;
57 set param2 = 43;
58END
59//! [1]
60
61
62//! [2]
63QSqlQuery q;
64q.exec("call qtestproc (@outval1, @outval2)");
65q.exec("select @outval1, @outval2");
66q.next();
67qDebug() << q.value(0) << q.value(1); // outputs "42" and "43"
68//! [2]
69
70
71//! [3]
72cd $QTDIR/src/plugins/sqldrivers/mysql
73qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
74make
75//! [3]
76
77
78//! [4]
79cd $QTDIR/src/plugins/sqldrivers/mysql
80make install
81//! [4]
82
83
84//! [5]
85cd %QTDIR%\src\plugins\sqldrivers\mysql
86qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro
87nmake
88//! [5]
89
90
91//! [6]
92cd $QTDIR/src/plugins/sqldrivers/oci
93qmake "INCLUDEPATH+=$ORACLE_HOME/rdbms/public $ORACLE_HOME/rdbms/demo" "LIBS+=-L$ORACLE_HOME/lib -lclntsh -lwtc9" oci.pro
94make
95//! [6]
96
97
98//! [7]
99cd $QTDIR/src/plugins/sqldrivers/oci
100qmake "INCLUDEPATH+=/usr/include/oracle/10.1.0.3/client/" "LIBS+=-L/usr/lib/oracle/10.1.0.3/client/lib -lclntsh" oci.pro
101make
102//! [7]
103
104
105//! [8]
106set INCLUDE=%INCLUDE%;c:\oracle\oci\include
107set LIB=%LIB%;c:\oracle\oci\lib\msvc
108cd %QTDIR%\src\plugins\sqldrivers\oci
109qmake oci.pro
110nmake
111//! [8]
112
113
114//! [9]
115set PATH=%PATH%;c:\oracle\bin
116//! [9]
117
118
119//! [10]
120\\ STORED_PROC uses the return statement or returns multiple result sets
121QSqlQuery query;
122query.setForwardOnly(true);
123query.exec("{call STORED_PROC}");
124//! [10]
125
126
127//! [11]
128cd $QTDIR/src/plugins/sqldrivers/odbc
129qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc"
130make
131//! [11]
132
133
134//! [12]
135cd %QTDIR%\src\plugins\sqldrivers\odbc
136qmake odbc.pro
137nmake
138//! [12]
139
140
141//! [13]
142cd $QTDIR/src/plugins/sqldrivers/psql
143qmake "INCLUDEPATH+=/usr/include/pgsql" "LIBS+=-L/usr/lib -lpq" psql.pro
144make
145//! [13]
146
147
148//! [14]
149cd $QTDIR/src/plugins/sqldrivers/psql
150make install
151//! [14]
152
153
154//! [15]
155cd %QTDIR%\src\plugins\sqldrivers\psql
156qmake "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
157nmake
158//! [15]
159
160
161//! [16]
162cd $QTDIR/src/plugins/sqldrivers/tds
163qmake "INCLUDEPATH=$SYBASE/include" "LIBS=-L$SYBASE/lib -lsybdb"
164make
165//! [16]
166
167
168//! [17]
169cd %QTDIR%\src\plugins\sqldrivers\tds
170qmake "LIBS+=NTWDBLIB.LIB" tds.pro
171nmake
172//! [17]
173
174
175//! [18]
176cd $QTDIR/src/plugins/sqldrivers/db2
177qmake "INCLUDEPATH+=$DB2DIR/include" "LIBS+=-L$DB2DIR/lib -ldb2"
178make
179//! [18]
180
181
182//! [19]
183cd $QTDIR/src/plugins/sqldrivers/db2
184make install
185//! [19]
186
187
188//! [20]
189cd %QTDIR%\src\plugins\sqldrivers\db2
190qmake "INCLUDEPATH+=<DB2 home>/sqllib/include" "LIBS+=<DB2 home>/sqllib/lib/db2cli.lib"
191nmake
192//! [20]
193
194
195//! [21]
196cd $QTDIR/src/plugins/sqldrivers/sqlite
197qmake "INCLUDEPATH+=$SQLITE/include" "LIBS+=-L$SQLITE/lib -lsqlite"
198make
199//! [21]
200
201
202//! [22]
203cd $QTDIR/src/plugins/sqldrivers/sqlite
204make install
205//! [22]
206
207
208//! [23]
209cd %QTDIR%\src\plugins\sqldrivers\sqlite
210qmake "INCLUDEPATH+=C:\SQLITE\INCLUDE" "LIBS+=C:\SQLITE\LIB\SQLITE3.LIB" sqlite.pro
211nmake
212//! [23]
213
214
215//! [24]
216db.setHostName("MyServer");
217db.setDatabaseName("C:\\test.gdb");
218//! [24]
219
220
221//! [25]
222// connect to database using the Latin-1 character set
223db.setConnectOptions("ISC_DPB_LC_CTYPE=Latin1");
224db.open();
225//! [25]
226
227
228//! [26]
229QSqlQuery q;
230q.exec("execute procedure my_procedure");
231q.next();
232qDebug() << q.value(0); // outputs the first RETURN/OUT value
233//! [26]
234
235
236//! [27]
237cd $QTDIR/src/plugins/sqldrivers/ibase
238qmake "INCLUDEPATH+=/opt/interbase/include" "LIBS+=-L/opt/interbase/lib" ibase.pro
239make
240//! [27]
241
242
243//! [28]
244cd $QTDIR/src/plugins/sqldrivers/ibase
245qmake "INCLUDEPATH+=/opt/interbase/include" "LIBS+=-L/opt/interbase/lib -lfbclient" ibase.pro
246make
247//! [28]
248
249
250//! [29]
251cd %QTDIR%\src\plugins\sqldrivers\ibase
252qmake "INCLUDEPATH+=C:\interbase\include" ibase.pro
253nmake
254//! [29]
255
256
257//! [30]
258cd %QTDIR%\src\plugins\sqldrivers\ibase
259qmake "INCLUDEPATH+=C:\interbase\include" "LIBS+=-lfbclient" ibase.pro
260nmake
261//! [30]
262
263
264//! [31]
265QSqlDatabase: QMYSQL driver not loaded
266QSqlDatabase: available drivers: QMYSQL
267//! [31]
268
269//! [32]
270configure -I /usr/include/oracle/10.1.0.3/client -L /usr/lib/oracle/10.1.0.3/client/lib -R /usr/lib/oracle/10.1.0.3/client/lib -lclntsh -lnnz10
271make
272//! [32]
273
274//! [33]
275cd $QTDIR/src/plugins/sqldrivers/oci
276qmake "INCLUDEPATH+=/usr/include/oracle/10.1.0.3/client" "LIBS+=-L/usr/lib/oracle/10.1.0.3/client/lib -Wl,-rpath,/usr/lib/oracle/10.1.0.3/client/lib -lclntsh -lnnz10" oci.pro
277make
278//! [33]
279
Note: See TracBrowser for help on using the repository browser.