summaryrefslogtreecommitdiffstats
path: root/doc/html/qsqldatabase.html
blob: 5c4e0f90b32631f4b0383795bfd272b258991a61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/sql/qsqldatabase.cpp:353 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQSqlDatabase Class</title>
<style type="text/css"><!--
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&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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>TQSqlDatabase Class Reference<br><small>[<a href="sql.html">sql module</a>]</small></h1>

<p>The TQSqlDatabase class is used to create SQL database
connections and to provide transaction handling.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qsqldatabase-h.html">qsqldatabase.h</a>&gt;</tt>
<p>Inherits <a href="qobject.html">TQObject</a>.
<p><a href="qsqldatabase-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#~TQSqlDatabase"><b>~TQSqlDatabase</b></a> ()</li>
<li class=fn>bool <a href="#open"><b>open</b></a> ()</li>
<li class=fn>bool <a href="#open-2"><b>open</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;user, const&nbsp;TQString&nbsp;&amp;&nbsp;password )</li>
<li class=fn>void <a href="#close"><b>close</b></a> ()</li>
<li class=fn>bool <a href="#isOpen"><b>isOpen</b></a> () const</li>
<li class=fn>bool <a href="#isOpenError"><b>isOpenError</b></a> () const</li>
<li class=fn>TQStringList <a href="#tables-2"><b>tables</b></a> () const</li>
<li class=fn>TQStringList <a href="#tables"><b>tables</b></a> ( TQSql::TableType&nbsp;type ) const</li>
<li class=fn>TQSqlIndex <a href="#primaryIndex"><b>primaryIndex</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;tablename ) const</li>
<li class=fn>TQSqlRecord <a href="#record"><b>record</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;tablename ) const</li>
<li class=fn>TQSqlRecord <a href="#record-2"><b>record</b></a> ( const&nbsp;TQSqlQuery&nbsp;&amp;&nbsp;query ) const</li>
<li class=fn>TQSqlRecordInfo <a href="#recordInfo"><b>recordInfo</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;tablename ) const</li>
<li class=fn>TQSqlRecordInfo <a href="#recordInfo-2"><b>recordInfo</b></a> ( const&nbsp;TQSqlQuery&nbsp;&amp;&nbsp;query ) const</li>
<li class=fn>TQSqlQuery <a href="#exec"><b>exec</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;query = TQString::null ) const</li>
<li class=fn>TQSqlError <a href="#lastError"><b>lastError</b></a> () const</li>
<li class=fn>bool <a href="#transaction"><b>transaction</b></a> ()</li>
<li class=fn>bool <a href="#commit"><b>commit</b></a> ()</li>
<li class=fn>bool <a href="#rollback"><b>rollback</b></a> ()</li>
<li class=fn>virtual void <a href="#setDatabaseName"><b>setDatabaseName</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;name )</li>
<li class=fn>virtual void <a href="#setUserName"><b>setUserName</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;name )</li>
<li class=fn>virtual void <a href="#setPassword"><b>setPassword</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;password )</li>
<li class=fn>virtual void <a href="#setHostName"><b>setHostName</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;host )</li>
<li class=fn>virtual void <a href="#setPort"><b>setPort</b></a> ( int&nbsp;p )</li>
<li class=fn>void <a href="#setConnectOptions"><b>setConnectOptions</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;options = TQString::null )</li>
<li class=fn>TQString <a href="#databaseName"><b>databaseName</b></a> () const</li>
<li class=fn>TQString <a href="#userName"><b>userName</b></a> () const</li>
<li class=fn>TQString <a href="#password"><b>password</b></a> () const</li>
<li class=fn>TQString <a href="#hostName"><b>hostName</b></a> () const</li>
<li class=fn>TQString <a href="#driverName"><b>driverName</b></a> () const</li>
<li class=fn>int <a href="#port"><b>port</b></a> () const</li>
<li class=fn>TQString <a href="#connectOptions"><b>connectOptions</b></a> () const</li>
<li class=fn>TQSqlDriver * <a href="#driver"><b>driver</b></a> () const</li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li class=fn>TQSqlDatabase * <a href="#addDatabase"><b>addDatabase</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;type, const&nbsp;TQString&nbsp;&amp;&nbsp;connectionName = defaultConnection )</li>
<li class=fn>TQSqlDatabase * <a href="#addDatabase-2"><b>addDatabase</b></a> ( TQSqlDriver&nbsp;*&nbsp;driver, const&nbsp;TQString&nbsp;&amp;&nbsp;connectionName = defaultConnection )</li>
<li class=fn>TQSqlDatabase * <a href="#database"><b>database</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;connectionName = defaultConnection, bool&nbsp;open = TRUE )</li>
<li class=fn>void <a href="#removeDatabase"><b>removeDatabase</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;connectionName )</li>
<li class=fn>void <a href="#removeDatabase-2"><b>removeDatabase</b></a> ( TQSqlDatabase&nbsp;*&nbsp;db )</li>
<li class=fn>bool <a href="#contains"><b>contains</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;connectionName = defaultConnection )</li>
<li class=fn>TQStringList <a href="#drivers"><b>drivers</b></a> ()</li>
<li class=fn>void <a href="#registerSqlDriver"><b>registerSqlDriver</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;name, const&nbsp;TQSqlDriverCreatorBase&nbsp;*&nbsp;creator )</li>
<li class=fn>bool <a href="#isDriverAvailable"><b>isDriverAvailable</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;name )</li>
</ul>
<h2>Properties</h2>
<ul>
<li class=fn>TQString <a href="#connectOptions-prop"><b>connectOptions</b></a>&nbsp;- the database connect options</li>
<li class=fn>TQString <a href="#databaseName-prop"><b>databaseName</b></a>&nbsp;- the name of the database</li>
<li class=fn>TQString <a href="#hostName-prop"><b>hostName</b></a>&nbsp;- the host name where the database resides</li>
<li class=fn>TQString <a href="#password-prop"><b>password</b></a>&nbsp;- the password used to connect to the database</li>
<li class=fn>int <a href="#port-prop"><b>port</b></a>&nbsp;- the port used to connect to the database</li>
<li class=fn>TQString <a href="#userName-prop"><b>userName</b></a>&nbsp;- the user name connected to the database</li>
</ul>
<h2>Protected Members</h2>
<ul>
<li class=fn><a href="#TQSqlDatabase"><b>TQSqlDatabase</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;type, const&nbsp;TQString&nbsp;&amp;&nbsp;name, TQObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;objname = 0 )</li>
<li class=fn><a href="#TQSqlDatabase-2"><b>TQSqlDatabase</b></a> ( TQSqlDriver&nbsp;*&nbsp;driver, TQObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;objname = 0 )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The TQSqlDatabase class is used to create SQL database
connections and to provide transaction handling.
<p> 


<p> Note that transaction handling is not supported by every SQL
database. You can find out whether transactions are supported
using <a href="qsqldriver.html#hasFeature">TQSqlDriver::hasFeature</a>().
<p> The TQSqlDatabase class provides an abstract interface for
accessing many types of database backends. Database-specific
drivers are used internally to actually access and manipulate
data, (see <a href="qsqldriver.html">TQSqlDriver</a>). Result set objects provide the interface
for executing and manipulating SQL queries (see <a href="qsqlquery.html">TQSqlQuery</a>).
<p>See also <a href="database.html">Database Classes</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="TQSqlDatabase"></a>TQSqlDatabase::TQSqlDatabase ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;type, const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;name, <a href="qobject.html">TQObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;objname = 0 )<tt> [protected]</tt>
</h3>
Creates a TQSqlDatabase connection called <em>name</em> that uses the
driver referred to by <em>type</em>, with the parent <em>parent</em> and the
object name <em>objname</em>. If the <em>type</em> is not recognized, the
database connection will have no functionality.
<p> The currently available drivers are:
<p> <center><table cellpadding="4" cellspacing="2" border="0">
<tr bgcolor="#a2c511"> <th valign="top">Driver Type <th valign="top">Description
<tr bgcolor="#f0f0f0"> <td valign="top"><a href="sql-driver.html#TQODBC3">TQODBC3</a> <td valign="top">ODBC Driver (includes Microsoft SQL Server)
<tr bgcolor="#d0d0d0"> <td valign="top"><a href="sql-driver.html#TQOCI8">TQOCI8</a> <td valign="top">Oracle Call Interface Driver
<tr bgcolor="#f0f0f0"> <td valign="top"><a href="sql-driver.html#TQPSQL7">TQPSQL7</a> <td valign="top">PostgreSQL v6.x and v7.x Driver
<tr bgcolor="#d0d0d0"> <td valign="top"><a href="sql-driver.html#TQTDS7">TQTDS7</a> <td valign="top">Sybase Adaptive Server
<tr bgcolor="#f0f0f0"> <td valign="top"><a href="sql-driver.html#TQMYSQL3">TQMYSQL3</a> <td valign="top">MySQL Driver
<tr bgcolor="#d0d0d0"> <td valign="top"><a href="sql-driver.html#TQDB2">TQDB2</a> <td valign="top">IBM DB2, v7.1 and higher
<tr bgcolor="#f0f0f0"> <td valign="top"><a href="sql-driver.html#TQSQLITE">TQSQLITE</a> <td valign="top">SQLite Driver
<tr bgcolor="#d0d0d0"> <td valign="top"><a href="sql-driver.html#TQIBASE">TQIBASE</a> <td valign="top">Borland Interbase Driver
</table></center>
<p> Additional third party drivers, including your own custom drivers,
can be loaded dynamically.
<p> <p>See also <a href="#registerSqlDriver">registerSqlDriver</a>().

<h3 class=fn><a name="TQSqlDatabase-2"></a>TQSqlDatabase::TQSqlDatabase ( <a href="qsqldriver.html">TQSqlDriver</a>&nbsp;*&nbsp;driver, <a href="qobject.html">TQObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;objname = 0 )<tt> [protected]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Creates a database connection using the driver <em>driver</em>, with
the parent <em>parent</em> and the object name <em>objname</em>.
<p> <b>Warning:</b> The framework takes ownership of the <em>driver</em> pointer,
so it should not be deleted.

<h3 class=fn><a name="~TQSqlDatabase"></a>TQSqlDatabase::~TQSqlDatabase ()
</h3>
Destroys the object and frees any allocated resources.

<h3 class=fn><a href="qsqldatabase.html">TQSqlDatabase</a>&nbsp;* <a name="addDatabase"></a>TQSqlDatabase::addDatabase ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;type, const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;connectionName = defaultConnection )<tt> [static]</tt>
</h3>
Adds a database to the list of database connections using the
driver <em>type</em> and the connection name <em>connectionName</em>.
<p> The database connection is referred to by <em>connectionName</em>. The
newly added database connection is returned. This pointer is owned
by TQSqlDatabase and will be deleted on program exit or when
<a href="#removeDatabase">removeDatabase</a>() is called.
<p> If <em>connectionName</em> is not specified, the newly added database
connection becomes the default database connection for the
application, and subsequent calls to <a href="#database">database</a>() (without a
database name parameter) will return a pointer to it. If <em>connectionName</em> is given, use <a href="#database">database(connectionName)</a> to retrieve a pointer to the
database connection.
<p> <b>Warning:</b> If you add a database with the same name as an
existing database, the new database will replace the old one.
This will happen automatically if you call this function more
than once without specifying <em>connectionName</em>.
<p> <p>See also <a href="#database">database</a>() and <a href="#removeDatabase">removeDatabase</a>().

<p>Examples: <a href="sql.html#x2141">sql/overview/connect1/main.cpp</a>, <a href="sql.html#x2147">sql/overview/connection.cpp</a>, and <a href="sqltable-example.html#x2454">sql/sqltable/main.cpp</a>.
<h3 class=fn><a href="qsqldatabase.html">TQSqlDatabase</a>&nbsp;* <a name="addDatabase-2"></a>TQSqlDatabase::addDatabase ( <a href="qsqldriver.html">TQSqlDriver</a>&nbsp;*&nbsp;driver, const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;connectionName = defaultConnection )<tt> [static]</tt>
</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> This function is useful if you need to set up the database
connection and instantiate the driver yourself. If you do this, it
is recommended that you include the driver code in your own
application. For example, setting up a custom PostgreSQL
connection and instantiating the <a href="sql-driver.html#TQPSQL7">TQPSQL7</a> driver can be done the
following way:
<p> <pre>
    #include "qtdir/src/sql/drivers/psql/qsql_psql.cpp"
    </pre>
 
(We assume that <tt>qtdir</tt> is the directory where TQt is installed.)
This will pull in the code that is needed to use the PostgreSQL
client library and to instantiate a TQPSQLDriver object, assuming
that you have the PostgreSQL headers somewhere in your include
search path.
<p> <pre>
    PGconn* con = PQconnectdb( "host=server user=bart password=simpson dbname=springfield" );
    TQPSQLDriver* drv =  new TQPSQLDriver( con );
    TQSqlDatabase* db = TQSqlDatabase::<a href="#addDatabase">addDatabase</a>( drv ); // becomes the new default connection
    <a href="qsqlquery.html">TQSqlQuery</a> q;
    q.<a href="qsqlquery.html#exec">exec</a>( "SELECT * FROM people" );
    ...
    </pre>
 
<p> The above code sets up a PostgreSQL connection and instantiates a
TQPSQLDriver object. Next, <a href="#addDatabase">addDatabase</a>() is called to add the
connection to the known connections so that it can be used by the
TQt SQL classes. When a driver is instantiated with a connection
handle (or set of handles), TQt assumes that you have already
opened the database connection.
<p> Remember that you must link your application against the database
client library as well. The simplest way to do this is to add
lines like those below to your <tt>.pro</tt> file:
<p> <pre>
    unix:LIBS += -lpq
    win32:LIBS += libpqdll.lib
    </pre>
 
<p> You will need to have the client library in your linker's search
path.
<p> The method described above will work for all the drivers, the only
difference is the arguments the driver constructors take. Below is
an overview of the drivers and their constructor arguments.
<p> <center><table cellpadding="4" cellspacing="2" border="0">
<tr bgcolor="#a2c511"> <th valign="top">Driver <th valign="top">Class name <th valign="top">Constructor arguments <th valign="top">File to include
<tr bgcolor="#f0f0f0">
<td valign="top">TQPSQL7
<td valign="top">TQPSQLDriver
<td valign="top">PGconn* connection
<td valign="top"><tt>qsql_psql.cpp</tt>
<tr bgcolor="#d0d0d0">
<td valign="top"><a href="sql-driver.html#TQMYSQL3">TQMYSQL3</a>
<td valign="top">TQMYSQLDriver
<td valign="top">MYSQL* connection
<td valign="top"><tt>qsql_mysql.cpp</tt>
<tr bgcolor="#f0f0f0">
<td valign="top"><a href="sql-driver.html#TQOCI8">TQOCI8</a>
<td valign="top">TQOCIDriver
<td valign="top">OCIEnv* environment, OCIError* error, OCISvcCtx* serviceContext
<td valign="top"><tt>qsql_oci.cpp</tt>
<tr bgcolor="#d0d0d0">
<td valign="top"><a href="sql-driver.html#TQODBC3">TQODBC3</a>
<td valign="top">TQODBCDriver
<td valign="top">SQLHANDLE environment, SQLHANDLE connection
<td valign="top"><tt>qsql_odbc.cpp</tt>
<tr bgcolor="#f0f0f0">
<td valign="top"><a href="sql-driver.html#TQDB2">TQDB2</a>
<td valign="top">TQDB2
<td valign="top">SQLHANDLE environment, SQLHANDLE connection
<td valign="top"><tt>qsql_db2.cpp</tt>
<tr bgcolor="#d0d0d0">
<td valign="top"><a href="sql-driver.html#TQTDS7">TQTDS7</a>
<td valign="top">TQTDSDriver
<td valign="top">LOGINREC* loginRecord, DBPROCESS* dbProcess, const <a href="qstring.html">TQString</a>& hostName
<td valign="top"><tt>qsql_tds.cpp</tt>
<tr bgcolor="#f0f0f0">
<td valign="top"><a href="sql-driver.html#TQSQLITE">TQSQLITE</a>
<td valign="top">TQSQLiteDriver
<td valign="top">sqlite* connection
<td valign="top"><tt>qsql_sqlite.cpp</tt>
<tr bgcolor="#d0d0d0">
<td valign="top"><a href="sql-driver.html#TQIBASE">TQIBASE</a>
<td valign="top">TQIBaseDriver
<td valign="top">isc_db_handle connection
<td valign="top"><tt>qsql_ibase.cpp</tt>
</table></center>
<p> Note: The host name (or service name) is needed when constructing
the TQTDSDriver for creating new connections for internal
queries. This is to prevent the simultaneous usage of several
<a href="qsqlquery.html">TQSqlQuery</a>/<a href="qsqlcursor.html">TQSqlCursor</a> objects from blocking each other.
<p> <b>Warning:</b> The SQL framework takes ownership of the <em>driver</em> pointer,
and it should not be deleted. The returned TQSqlDatabase object is
owned by the framework and must not be deleted. If you want to
explicitly remove the connection, use <a href="#removeDatabase">removeDatabase</a>()
<p> <p>See also <a href="#drivers">drivers</a>().

<h3 class=fn>void <a name="close"></a>TQSqlDatabase::close ()
</h3>
Closes the database connection, freeing any resources actquired.
<p> <p>See also <a href="#removeDatabase">removeDatabase</a>().

<h3 class=fn>bool <a name="commit"></a>TQSqlDatabase::commit ()
</h3>
Commits a transaction to the database if the driver supports
transactions. Returns TRUE if the operation succeeded; otherwise
returns FALSE.
<p> <p>See also <a href="qsqldriver.html#hasFeature">TQSqlDriver::hasFeature</a>() and <a href="#rollback">rollback</a>().

<h3 class=fn><a href="qstring.html">TQString</a> <a name="connectOptions"></a>TQSqlDatabase::connectOptions () const
</h3><p>Returns the database connect options.
See the <a href="qsqldatabase.html#connectOptions-prop">"connectOptions"</a> property for details.
<h3 class=fn>bool <a name="contains"></a>TQSqlDatabase::contains ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;connectionName = defaultConnection )<tt> [static]</tt>
</h3>
Returns TRUE if the list of database connections contains <em>connectionName</em>; otherwise returns FALSE.

<h3 class=fn><a href="qsqldatabase.html">TQSqlDatabase</a>&nbsp;* <a name="database"></a>TQSqlDatabase::database ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;connectionName = defaultConnection, bool&nbsp;open = TRUE )<tt> [static]</tt>
</h3>
Returns the database connection called <em>connectionName</em>. The
database connection must have been previously added with
<a href="#addDatabase">addDatabase</a>(). If <em>open</em> is TRUE (the default) and the database
connection is not already open it is opened now. If no <em>connectionName</em> is specified the default connection is used. If <em>connectionName</em> does not exist in the list of databases, 0 is
returned. The pointer returned is owned by TQSqlDatabase and should
<em>not</em> be deleted.
<p> <b>Warning:</b> There are restrictions on the use of database connections
in threaded applications. Please see the <a href="threads.html#threads-sql">Thread Support in TQt</a> document for more information about
threading and SQL databases.

<p>Examples: <a href="sql.html#x2156">sql/overview/basicbrowsing/main.cpp</a> and <a href="sql.html#x2155">sql/overview/create_connections/main.cpp</a>.
<h3 class=fn><a href="qstring.html">TQString</a> <a name="databaseName"></a>TQSqlDatabase::databaseName () const
</h3><p>Returns the name of the database.
See the <a href="qsqldatabase.html#databaseName-prop">"databaseName"</a> property for details.
<h3 class=fn><a href="qsqldriver.html">TQSqlDriver</a>&nbsp;* <a name="driver"></a>TQSqlDatabase::driver () const
</h3>
Returns the database driver used to access the database
connection.

<h3 class=fn><a href="qstring.html">TQString</a> <a name="driverName"></a>TQSqlDatabase::driverName () const
</h3>
Returns the name of the driver used by the database connection.

<h3 class=fn><a href="qstringlist.html">TQStringList</a> <a name="drivers"></a>TQSqlDatabase::drivers ()<tt> [static]</tt>
</h3>
Returns a list of all the available database drivers.
<p> Note that if you want to iterate over the list, you should iterate
over a copy, e.g.
<pre>
    <a href="qstringlist.html">TQStringList</a> list = TQSqlDatabase::<a href="#drivers">drivers</a>();
    TQStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();
    while( it != list.<a href="qvaluelist.html#end">end</a>() ) {
        myProcessing( *it );
        ++it;
    }
    </pre>
 

<h3 class=fn><a href="qsqlquery.html">TQSqlQuery</a> <a name="exec"></a>TQSqlDatabase::exec ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;query = TQString::null ) const
</h3>
Executes a SQL statement (e.g. an <tt>INSERT</tt>, <tt>UPDATE</tt> or <tt>DELETE</tt> statement) on the database, and returns a <a href="qsqlquery.html">TQSqlQuery</a> object.
Use <a href="#lastError">lastError</a>() to retrieve error information. If <em>query</em> is
<a href="qstring.html#TQString-null">TQString::null</a>, an empty, invalid query is returned and lastError()
is not affected.
<p> <p>See also <a href="qsqlquery.html">TQSqlQuery</a> and <a href="#lastError">lastError</a>().

<h3 class=fn><a href="qstring.html">TQString</a> <a name="hostName"></a>TQSqlDatabase::hostName () const
</h3><p>Returns the host name where the database resides.
See the <a href="qsqldatabase.html#hostName-prop">"hostName"</a> property for details.
<h3 class=fn>bool <a name="isDriverAvailable"></a>TQSqlDatabase::isDriverAvailable ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;name )<tt> [static]</tt>
</h3>
Returns TRUE if a driver called <em>name</em> is available; otherwise
returns FALSE.
<p> <p>See also <a href="#drivers">drivers</a>().

<h3 class=fn>bool <a name="isOpen"></a>TQSqlDatabase::isOpen () const
</h3>
Returns TRUE if the database connection is currently open;
otherwise returns FALSE.

<h3 class=fn>bool <a name="isOpenError"></a>TQSqlDatabase::isOpenError () const
</h3>
Returns TRUE if there was an error opening the database
connection; otherwise returns FALSE. Error information can be
retrieved using the <a href="#lastError">lastError</a>() function.

<h3 class=fn><a href="qsqlerror.html">TQSqlError</a> <a name="lastError"></a>TQSqlDatabase::lastError () const
</h3>
Returns information about the last error that occurred on the
database. See <a href="qsqlerror.html">TQSqlError</a> for more information.

<p>Examples: <a href="sql.html#x2148">sql/overview/connection.cpp</a> and <a href="sqltable-example.html#x2455">sql/sqltable/main.cpp</a>.
<h3 class=fn>bool <a name="open"></a>TQSqlDatabase::open ()
</h3>
Opens the database connection using the current connection values.
Returns TRUE on success; otherwise returns FALSE. Error
information can be retrieved using the <a href="#lastError">lastError</a>() function.
<p> <p>See also <a href="#lastError">lastError</a>().

<p>Examples: <a href="sql.html#x2142">sql/overview/connect1/main.cpp</a>, <a href="sql.html#x2149">sql/overview/connection.cpp</a>, and <a href="sqltable-example.html#x2456">sql/sqltable/main.cpp</a>.
<h3 class=fn>bool <a name="open-2"></a>TQSqlDatabase::open ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;user, const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;password )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Opens the database connection using the given <em>user</em> name and <em>password</em>. Returns TRUE on success; otherwise returns FALSE. Error
information can be retrieved using the <a href="#lastError">lastError</a>() function.
<p> This function does not store the password it is given. Instead,
the password is passed directly to the driver for opening a
connection and is then discarded.
<p> <p>See also <a href="#lastError">lastError</a>().

<h3 class=fn><a href="qstring.html">TQString</a> <a name="password"></a>TQSqlDatabase::password () const
</h3><p>Returns the password used to connect to the database.
See the <a href="qsqldatabase.html#password-prop">"password"</a> property for details.
<h3 class=fn>int <a name="port"></a>TQSqlDatabase::port () const
</h3><p>Returns the port used to connect to the database.
See the <a href="qsqldatabase.html#port-prop">"port"</a> property for details.
<h3 class=fn><a href="qsqlindex.html">TQSqlIndex</a> <a name="primaryIndex"></a>TQSqlDatabase::primaryIndex ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;tablename ) const
</h3>
Returns the primary index for table <em>tablename</em>. If no primary
index exists an empty <a href="qsqlindex.html">TQSqlIndex</a> will be returned.

<h3 class=fn><a href="qsqlrecord.html">TQSqlRecord</a> <a name="record"></a>TQSqlDatabase::record ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;tablename ) const
</h3>
Returns a <a href="qsqlrecord.html">TQSqlRecord</a> populated with the names of all the fields in
the table (or view) called <em>tablename</em>. The order in which the
fields appear in the record is undefined. If no such table (or
view) exists, an empty record is returned.
<p> <p>See also <a href="#recordInfo">recordInfo</a>().

<h3 class=fn><a href="qsqlrecord.html">TQSqlRecord</a> <a name="record-2"></a>TQSqlDatabase::record ( const&nbsp;<a href="qsqlquery.html">TQSqlQuery</a>&nbsp;&amp;&nbsp;query ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns a <a href="qsqlrecord.html">TQSqlRecord</a> populated with the names of all the fields
used in the SQL <em>query</em>. If the query is a "SELECT *" the order
in which fields appear in the record is undefined.
<p> <p>See also <a href="#recordInfo">recordInfo</a>().

<h3 class=fn><a href="qsqlrecordinfo.html">TQSqlRecordInfo</a> <a name="recordInfo"></a>TQSqlDatabase::recordInfo ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;tablename ) const
</h3>
Returns a <a href="qsqlrecordinfo.html">TQSqlRecordInfo</a> populated with meta data about the table
or view <em>tablename</em>. If no such table (or view) exists, an empty
record is returned.
<p> <p>See also <a href="qsqlrecordinfo.html">TQSqlRecordInfo</a>, <a href="qsqlfieldinfo.html">TQSqlFieldInfo</a>, and <a href="#record">record</a>().

<h3 class=fn><a href="qsqlrecordinfo.html">TQSqlRecordInfo</a> <a name="recordInfo-2"></a>TQSqlDatabase::recordInfo ( const&nbsp;<a href="qsqlquery.html">TQSqlQuery</a>&nbsp;&amp;&nbsp;query ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns a <a href="qsqlrecordinfo.html">TQSqlRecordInfo</a> object with meta data for the <a href="qsqlquery.html">TQSqlQuery</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.
<p> <p>See also <a href="qsqlrecordinfo.html">TQSqlRecordInfo</a>, <a href="qsqlfieldinfo.html">TQSqlFieldInfo</a>, and <a href="#record">record</a>().

<h3 class=fn>void <a name="registerSqlDriver"></a>TQSqlDatabase::registerSqlDriver ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;name, const&nbsp;TQSqlDriverCreatorBase&nbsp;*&nbsp;creator )<tt> [static]</tt>
</h3>
This function registers a new SQL driver called <em>name</em>, within
the SQL framework. This is useful if you have a custom SQL driver
and don't want to compile it as a plugin.
<p> Example usage:
<p> <pre>
    TQSqlDatabase::<a href="#registerSqlDriver">registerSqlDriver</a>( "MYDRIVER", new TQSqlDriverCreator&lt;MyDatabaseDriver&gt; );
    TQSqlDatabase* db = TQSqlDatabase::<a href="#addDatabase">addDatabase</a>( "MYDRIVER" );
    ...
    </pre>
 
<p> <b>Warning:</b> The framework takes ownership of the <em>creator</em> pointer,
so it should not be deleted.

<h3 class=fn>void <a name="removeDatabase"></a>TQSqlDatabase::removeDatabase ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;connectionName )<tt> [static]</tt>
</h3>
Removes the database connection <em>connectionName</em> from the list of
database connections.
<p> <b>Warning:</b> There should be no open queries on the database
connection when this function is called, otherwise a resource leak
will occur.

<h3 class=fn>void <a name="removeDatabase-2"></a>TQSqlDatabase::removeDatabase ( <a href="qsqldatabase.html">TQSqlDatabase</a>&nbsp;*&nbsp;db )<tt> [static]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Removes the database connection <em>db</em> from the list of database
connections. The TQSqlDatabase object is destroyed when it is removed
from the list.
<p> <b>Warning:</b> The <em>db</em> pointer is not valid after this function has
been called. There should be no open queries on the database
connection when this function is called, otherwise a resource leak
will occur.

<h3 class=fn>bool <a name="rollback"></a>TQSqlDatabase::rollback ()
</h3>
Rolls a transaction back on the database if the driver supports
transactions. Returns TRUE if the operation succeeded; otherwise
returns FALSE.
<p> <p>See also <a href="qsqldriver.html#hasFeature">TQSqlDriver::hasFeature</a>(), <a href="#commit">commit</a>(), and <a href="#transaction">transaction</a>().

<h3 class=fn>void <a name="setConnectOptions"></a>TQSqlDatabase::setConnectOptions ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;options = TQString::null )
</h3><p>Sets the database connect options to <em>options</em>.
See the <a href="qsqldatabase.html#connectOptions-prop">"connectOptions"</a> property for details.
<h3 class=fn>void <a name="setDatabaseName"></a>TQSqlDatabase::setDatabaseName ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;name )<tt> [virtual]</tt>
</h3><p>Sets the name of the database to <em>name</em>.
See the <a href="qsqldatabase.html#databaseName-prop">"databaseName"</a> property for details.
<h3 class=fn>void <a name="setHostName"></a>TQSqlDatabase::setHostName ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;host )<tt> [virtual]</tt>
</h3><p>Sets the host name where the database resides to <em>host</em>.
See the <a href="qsqldatabase.html#hostName-prop">"hostName"</a> property for details.
<h3 class=fn>void <a name="setPassword"></a>TQSqlDatabase::setPassword ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;password )<tt> [virtual]</tt>
</h3><p>Sets the password used to connect to the database to <em>password</em>.
See the <a href="qsqldatabase.html#password-prop">"password"</a> property for details.
<h3 class=fn>void <a name="setPort"></a>TQSqlDatabase::setPort ( int&nbsp;p )<tt> [virtual]</tt>
</h3><p>Sets the port used to connect to the database to <em>p</em>.
See the <a href="qsqldatabase.html#port-prop">"port"</a> property for details.
<h3 class=fn>void <a name="setUserName"></a>TQSqlDatabase::setUserName ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;name )<tt> [virtual]</tt>
</h3><p>Sets the user name connected to the database to <em>name</em>.
See the <a href="qsqldatabase.html#userName-prop">"userName"</a> property for details.
<h3 class=fn><a href="qstringlist.html">TQStringList</a> <a name="tables"></a>TQSqlDatabase::tables ( <a href="qsql.html#TableType-enum">TQSql::TableType</a>&nbsp;type ) const
</h3>
Returns a list of the database's tables, system tables and views,
as specified by the parameter <em>type</em>.
<p> Note that if you want to iterate over the list, you should iterate
over a copy, e.g.
<pre>
    <a href="qstringlist.html">TQStringList</a> list = myDatabase.tables( TQSql::Tables | TQSql::Views );
    TQStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();
    while( it != list.<a href="qvaluelist.html#end">end</a>() ) {
        myProcessing( *it );
        ++it;
    }
    </pre>
 

<p>Example: <a href="sqltable-example.html#x2461">sql/sqltable/main.cpp</a>.
<h3 class=fn><a href="qstringlist.html">TQStringList</a> <a name="tables-2"></a>TQSqlDatabase::tables () const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns a list of the database's tables that are visible to the
user. To include views or system tables, use the version of this
function that takes a table <tt>type</tt> parameter.
<p> Note that if you want to iterate over the list, you should iterate
over a copy, e.g.
<pre>
    <a href="qstringlist.html">TQStringList</a> list = myDatabase.tables();
    TQStringList::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();
    while( it != list.<a href="qvaluelist.html#end">end</a>() ) {
        myProcessing( *it );
        ++it;
    }
    </pre>
 

<h3 class=fn>bool <a name="transaction"></a>TQSqlDatabase::transaction ()
</h3>
Begins a transaction on the database if the driver supports
transactions. Returns TRUE if the operation succeeded; otherwise
returns FALSE.
<p> <p>See also <a href="qsqldriver.html#hasFeature">TQSqlDriver::hasFeature</a>(), <a href="#commit">commit</a>(), and <a href="#rollback">rollback</a>().

<h3 class=fn><a href="qstring.html">TQString</a> <a name="userName"></a>TQSqlDatabase::userName () const
</h3><p>Returns the user name connected to the database.
See the <a href="qsqldatabase.html#userName-prop">"userName"</a> property for details.
<hr><h2>Property Documentation</h2>
<h3 class=fn><a href="qstring.html">TQString</a> <a name="connectOptions-prop"></a>connectOptions</h3>
<p>This property holds the database connect options.
<p>The format of the options string is a semi-colon separated list of
option names or option = value pairs. The options depend on the
database client used:
<p> <center><table cellpadding="4" cellspacing="2" border="0">
<tr bgcolor="#a2c511"> <th valign="top">ODBC <th valign="top">MySQL <th valign="top">PostgreSQL
<tr bgcolor="#f0f0f0">
<p> <td valign="top">
<ul>
<li> SQL_ATTR_ACCESS_MODE
<li> SQL_ATTR_LOGIN_TIMEOUT
<li> SQL_ATTR_CONNECTION_TIMEOUT
<li> SQL_ATTR_CURRENT_CATALOG
<li> SQL_ATTR_METADATA_ID
<li> SQL_ATTR_PACKET_SIZE
<li> SQL_ATTR_TRACEFILE
<li> SQL_ATTR_TRACE
</ul>
<p> <td valign="top">
<ul>
<li> CLIENT_COMPRESS
<li> CLIENT_FOUND_ROWS
<li> CLIENT_IGNORE_SPACE
<li> CLIENT_SSL
<li> CLIENT_ODBC
<li> CLIENT_NO_SCHEMA
<li> CLIENT_INTERACTIVE
</ul>
<p> <td valign="top">
<ul>
<li> connect_timeout
<li> options
<li> tty
<li> retquiressl
<li> service
</ul>
<tr bgcolor="#a2c511"> <th valign="top">DB2 <th valign="top">OCI <th valign="top">TDS
<tr bgcolor="#d0d0d0">
<p> <td valign="top">
<ul>
<li> SQL_ATTR_ACCESS_MODE
<li> SQL_ATTR_LOGIN_TIMEOUT
</ul>
<p> <td valign="top">
<em>none</em>
<p> <td valign="top">
<em>none</em>
<p> </table></center>
<p> Example of usage:
<pre>
    ...
    // MySQL connection
    db-&gt;setConnectOptions( "CLIENT_SSL;CLIENT_IGNORE_SPACE" ); // use an SSL connection to the server
    if ( !db-&gt;open() ) {
        db-&gt;setConnectOptions(); // clears the connect option string
        ...
    }
    ...
    // PostgreSQL connection
    db-&gt;setConnectOptions( "retquiressl=1" ); // enable PostgreSQL SSL connections
    if ( !db-&gt;open() ) {
        db-&gt;setConnectOptions(); // clear options
        ...
    }
    ...
    // ODBC connection
    db-&gt;setConnectOptions( "SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY;SQL_ATTR_TRACE=SQL_OPT_TRACE_ON" ); // set ODBC options
    if ( !db-&gt;open() ) {
        db-&gt;setConnectOptions(); // don't try to set this option
        ...
    }
    </pre>
 
<p> Please refer to the client library documentation for more
information about the different options. The options will be set
prior to opening the database connection. Setting new options
without re-opening the connection does nothing.
<p> <p>See also 
<p>Set this property's value with <a href="#setConnectOptions">setConnectOptions</a>() and get this property's value with <a href="#connectOptions">connectOptions</a>().
<h3 class=fn><a href="qstring.html">TQString</a> <a name="databaseName-prop"></a>databaseName</h3>
<p>This property holds the name of the database.
<p>Note that the database name is the TNS Service Name for the <a href="sql-driver.html#TQOCI8">TQOCI8</a>
(Oracle) driver.
<p> For the <a href="sql-driver.html#TQODBC3">TQODBC3</a> driver it can either be a DSN, a DSN filename (the
file must have a <tt>.dsn</tt> extension), or a connection string. MS
Access users can for example use the following connection string
to open a <tt>.mdb</tt> file directly, instead of having to create a DSN
entry in the ODBC manager:
<p> <pre>
    ...
    db = TQSqlDatabase::<a href="#addDatabase">addDatabase</a>( "TQODBC3" );
    db-&gt;setDatabaseName( "DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb" );
    if ( db-&gt;open() ) {
        // success!
    }
    ...
    </pre>
 
("FIL" is the retquired spelling in Microsoft's API.)
<p> There is no default value.

<p>Set this property's value with <a href="#setDatabaseName">setDatabaseName</a>() and get this property's value with <a href="#databaseName">databaseName</a>().
<h3 class=fn><a href="qstring.html">TQString</a> <a name="hostName-prop"></a>hostName</h3>
<p>This property holds the host name where the database resides.
<p>There is no default value.

<p>Set this property's value with <a href="#setHostName">setHostName</a>() and get this property's value with <a href="#hostName">hostName</a>().
<h3 class=fn><a href="qstring.html">TQString</a> <a name="password-prop"></a>password</h3>
<p>This property holds the password used to connect to the database.
<p>There is no default value.
<p> <b>Warning:</b> This function stores the password in plain text within
TQt. Use the <a href="#open">open</a>() call that takes a password as parameter to
avoid this behaviour.
<p> <p>See also <a href="#open">open</a>().

<p>Set this property's value with <a href="#setPassword">setPassword</a>() and get this property's value with <a href="#password">password</a>().
<h3 class=fn>int <a name="port-prop"></a>port</h3>
<p>This property holds the port used to connect to the database.
<p>There is no default value.

<p>Set this property's value with <a href="#setPort">setPort</a>() and get this property's value with <a href="#port">port</a>().
<h3 class=fn><a href="qstring.html">TQString</a> <a name="userName-prop"></a>userName</h3>
<p>This property holds the user name connected to the database.
<p>There is no default value.

<p>Set this property's value with <a href="#setUserName">setUserName</a>() and get this property's value with <a href="#userName">userName</a>().
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">TQt toolkit</a>.
Copyright &copy; 1995-2007
<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 &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>