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

Last change on this file since 728 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 6.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42//! [0]
43-no-sql-<driver> ... Disable SQL <driver> entirely.
44-qt-sql-<driver> ... Enable a SQL <driver> in the Qt Library, by default
45 none are turned on.
46-plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to
47 at run time.
48
49 Possible values for <driver>:
50 [ db2 ibase mysql oci odbc psql sqlite sqlite2 tds ]
51//! [0]
52
53
54//! [1]
55create procedure qtestproc (OUT param1 INT, OUT param2 INT)
56BEGIN
57 set param1 = 42;
58 set param2 = 43;
59END
60//! [1]
61
62
63//! [2]
64QSqlQuery q;
65q.exec("call qtestproc (@outval1, @outval2)");
66q.exec("select @outval1, @outval2");
67q.next();
68qDebug() << q.value(0) << q.value(1); // outputs "42" and "43"
69//! [2]
70
71
72//! [3]
73cd $QTDIR/src/plugins/sqldrivers/mysql
74qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
75make
76//! [3]
77
78
79//! [4]
80cd $QTDIR/src/plugins/sqldrivers/mysql
81make install
82//! [4]
83
84
85//! [5]
86cd %QTDIR%\src\plugins\sqldrivers\mysql
87qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro
88nmake
89//! [5]
90
91
92//! [6]
93cd $QTDIR/src/plugins/sqldrivers/oci
94qmake "INCLUDEPATH+=$ORACLE_HOME/rdbms/public $ORACLE_HOME/rdbms/demo" "LIBS+=-L$ORACLE_HOME/lib -lclntsh -lwtc9" oci.pro
95make
96//! [6]
97
98
99//! [7]
100cd $QTDIR/src/plugins/sqldrivers/oci
101qmake "INCLUDEPATH+=/usr/include/oracle/10.1.0.3/client/" "LIBS+=-L/usr/lib/oracle/10.1.0.3/client/lib -lclntsh" oci.pro
102make
103//! [7]
104
105
106//! [8]
107set INCLUDE=%INCLUDE%;c:\oracle\oci\include
108set LIB=%LIB%;c:\oracle\oci\lib\msvc
109cd %QTDIR%\src\plugins\sqldrivers\oci
110qmake oci.pro
111nmake
112//! [8]
113
114
115//! [9]
116set PATH=%PATH%;c:\oracle\bin
117//! [9]
118
119
120//! [10]
121\\ STORED_PROC uses the return statement or returns multiple result sets
122QSqlQuery query;
123query.setForwardOnly(true);
124query.exec("{call STORED_PROC}");
125//! [10]
126
127
128//! [11]
129cd $QTDIR/src/plugins/sqldrivers/odbc
130qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc"
131make
132//! [11]
133
134
135//! [12]
136cd %QTDIR%\src\plugins\sqldrivers\odbc
137qmake odbc.pro
138nmake
139//! [12]
140
141
142//! [13]
143cd $QTDIR/src/plugins/sqldrivers/psql
144qmake "INCLUDEPATH+=/usr/include/pgsql" "LIBS+=-L/usr/lib -lpq" psql.pro
145make
146//! [13]
147
148
149//! [14]
150cd $QTDIR/src/plugins/sqldrivers/psql
151make install
152//! [14]
153
154
155//! [15]
156cd %QTDIR%\src\plugins\sqldrivers\psql
157qmake "INCLUDEPATH+=C:\psql\include" "LIBS+=C:\psql\lib\ms\libpq.lib" psql.pro
158nmake
159//! [15]
160
161
162//! [16]
163cd $QTDIR/src/plugins/sqldrivers/tds
164qmake "INCLUDEPATH=$SYBASE/include" "LIBS=-L$SYBASE/lib -lsybdb"
165make
166//! [16]
167
168
169//! [17]
170cd %QTDIR%\src\plugins\sqldrivers\tds
171qmake "LIBS+=NTWDBLIB.LIB" tds.pro
172nmake
173//! [17]
174
175
176//! [18]
177cd $QTDIR/src/plugins/sqldrivers/db2
178qmake "INCLUDEPATH+=$DB2DIR/include" "LIBS+=-L$DB2DIR/lib -ldb2"
179make
180//! [18]
181
182
183//! [19]
184cd $QTDIR/src/plugins/sqldrivers/db2
185make install
186//! [19]
187
188
189//! [20]
190cd %QTDIR%\src\plugins\sqldrivers\db2
191qmake "INCLUDEPATH+=<DB2 home>/sqllib/include" "LIBS+=<DB2 home>/sqllib/lib/db2cli.lib"
192nmake
193//! [20]
194
195
196//! [21]
197cd $QTDIR/src/plugins/sqldrivers/sqlite
198qmake "INCLUDEPATH+=$SQLITE/include" "LIBS+=-L$SQLITE/lib -lsqlite"
199make
200//! [21]
201
202
203//! [22]
204cd $QTDIR/src/plugins/sqldrivers/sqlite
205make install
206//! [22]
207
208
209//! [23]
210cd %QTDIR%\src\plugins\sqldrivers\sqlite
211qmake "INCLUDEPATH+=C:\SQLITE\INCLUDE" "LIBS+=C:\SQLITE\LIB\SQLITE3.LIB" sqlite.pro
212nmake
213//! [23]
214
215
216//! [24]
217db.setHostName("MyServer");
218db.setDatabaseName("C:\\test.gdb");
219//! [24]
220
221
222//! [25]
223// connect to database using the Latin-1 character set
224db.setConnectOptions("ISC_DPB_LC_CTYPE=Latin1");
225db.open();
226//! [25]
227
228
229//! [26]
230QSqlQuery q;
231q.exec("execute procedure my_procedure");
232q.next();
233qDebug() << q.value(0); // outputs the first RETURN/OUT value
234//! [26]
235
236
237//! [27]
238cd $QTDIR/src/plugins/sqldrivers/ibase
239qmake "INCLUDEPATH+=/opt/interbase/include" "LIBS+=-L/opt/interbase/lib" ibase.pro
240make
241//! [27]
242
243
244//! [28]
245cd $QTDIR/src/plugins/sqldrivers/ibase
246qmake "INCLUDEPATH+=/opt/interbase/include" "LIBS+=-L/opt/interbase/lib -lfbclient" ibase.pro
247make
248//! [28]
249
250
251//! [29]
252cd %QTDIR%\src\plugins\sqldrivers\ibase
253qmake "INCLUDEPATH+=C:\interbase\include" ibase.pro
254nmake
255//! [29]
256
257
258//! [30]
259cd %QTDIR%\src\plugins\sqldrivers\ibase
260qmake "INCLUDEPATH+=C:\interbase\include" "LIBS+=-lfbclient" ibase.pro
261nmake
262//! [30]
263
264
265//! [31]
266QSqlDatabase: QMYSQL driver not loaded
267QSqlDatabase: available drivers: QMYSQL
268//! [31]
269
270//! [32]
271configure -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
272make
273//! [32]
274
275//! [33]
276cd $QTDIR/src/plugins/sqldrivers/oci
277qmake "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
278make
279//! [33]
280
Note: See TracBrowser for help on using the repository browser.