summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/qsqldatabase.3qt
blob: 2d640d26dd27b5a1c81f1050296665c531de6dbd (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
'\" t
.TH QSqlDatabase 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QSqlDatabase \- Used to create SQL database connections and to provide transaction handling
.SH SYNOPSIS
\fC#include <qsqldatabase.h>\fR
.PP
Inherits QObject.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fB~QSqlDatabase\fR ()"
.br
.ti -1c
.BI "bool \fBopen\fR ()"
.br
.ti -1c
.BI "bool \fBopen\fR ( const QString & user, const QString & password )"
.br
.ti -1c
.BI "void \fBclose\fR ()"
.br
.ti -1c
.BI "bool \fBisOpen\fR () const"
.br
.ti -1c
.BI "bool \fBisOpenError\fR () const"
.br
.ti -1c
.BI "QStringList \fBtables\fR () const"
.br
.ti -1c
.BI "QStringList \fBtables\fR ( QSql::TableType type ) const"
.br
.ti -1c
.BI "QSqlIndex \fBprimaryIndex\fR ( const QString & tablename ) const"
.br
.ti -1c
.BI "QSqlRecord \fBrecord\fR ( const QString & tablename ) const"
.br
.ti -1c
.BI "QSqlRecord \fBrecord\fR ( const QSqlQuery & query ) const"
.br
.ti -1c
.BI "QSqlRecordInfo \fBrecordInfo\fR ( const QString & tablename ) const"
.br
.ti -1c
.BI "QSqlRecordInfo \fBrecordInfo\fR ( const QSqlQuery & query ) const"
.br
.ti -1c
.BI "QSqlQuery \fBexec\fR ( const QString & query = QString::null ) const"
.br
.ti -1c
.BI "QSqlError \fBlastError\fR () const"
.br
.ti -1c
.BI "bool \fBtransaction\fR ()"
.br
.ti -1c
.BI "bool \fBcommit\fR ()"
.br
.ti -1c
.BI "bool \fBrollback\fR ()"
.br
.ti -1c
.BI "virtual void \fBsetDatabaseName\fR ( const QString & name )"
.br
.ti -1c
.BI "virtual void \fBsetUserName\fR ( const QString & name )"
.br
.ti -1c
.BI "virtual void \fBsetPassword\fR ( const QString & password )"
.br
.ti -1c
.BI "virtual void \fBsetHostName\fR ( const QString & host )"
.br
.ti -1c
.BI "virtual void \fBsetPort\fR ( int p )"
.br
.ti -1c
.BI "void \fBsetConnectOptions\fR ( const QString & options = QString::null )"
.br
.ti -1c
.BI "QString \fBdatabaseName\fR () const"
.br
.ti -1c
.BI "QString \fBuserName\fR () const"
.br
.ti -1c
.BI "QString \fBpassword\fR () const"
.br
.ti -1c
.BI "QString \fBhostName\fR () const"
.br
.ti -1c
.BI "QString \fBdriverName\fR () const"
.br
.ti -1c
.BI "int \fBport\fR () const"
.br
.ti -1c
.BI "QString \fBconnectOptions\fR () const"
.br
.ti -1c
.BI "QSqlDriver * \fBdriver\fR () const"
.br
.in -1c
.SS "Static Public Members"
.in +1c
.ti -1c
.BI "QSqlDatabase * \fBaddDatabase\fR ( const QString & type, const QString & connectionName = defaultConnection )"
.br
.ti -1c
.BI "QSqlDatabase * \fBaddDatabase\fR ( QSqlDriver * driver, const QString & connectionName = defaultConnection )"
.br
.ti -1c
.BI "QSqlDatabase * \fBdatabase\fR ( const QString & connectionName = defaultConnection, bool open = TRUE )"
.br
.ti -1c
.BI "void \fBremoveDatabase\fR ( const QString & connectionName )"
.br
.ti -1c
.BI "void \fBremoveDatabase\fR ( QSqlDatabase * db )"
.br
.ti -1c
.BI "bool \fBcontains\fR ( const QString & connectionName = defaultConnection )"
.br
.ti -1c
.BI "QStringList \fBdrivers\fR ()"
.br
.ti -1c
.BI "void \fBregisterSqlDriver\fR ( const QString & name, const QSqlDriverCreatorBase * creator )"
.br
.ti -1c
.BI "bool \fBisDriverAvailable\fR ( const QString & name )"
.br
.in -1c
.SS "Properties"
.in +1c
.ti -1c
.BI "QString \fBconnectOptions\fR - the database connect options"
.br
.ti -1c
.BI "QString \fBdatabaseName\fR - the name of the database"
.br
.ti -1c
.BI "QString \fBhostName\fR - the host name where the database resides"
.br
.ti -1c
.BI "QString \fBpassword\fR - the password used to connect to the database"
.br
.ti -1c
.BI "int \fBport\fR - the port used to connect to the database"
.br
.ti -1c
.BI "QString \fBuserName\fR - the user name connected to the database"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "\fBQSqlDatabase\fR ( const QString & type, const QString & name, QObject * parent = 0, const char * objname = 0 )"
.br
.ti -1c
.BI "\fBQSqlDatabase\fR ( QSqlDriver * driver, QObject * parent = 0, const char * objname = 0 )"
.br
.in -1c
.SH DESCRIPTION
The QSqlDatabase class is used to create SQL database connections and to provide transaction handling.
.PP
Note that transaction handling is not supported by every SQL database. You can find out whether transactions are supported using QSqlDriver::hasFeature().
.PP
The QSqlDatabase 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 QSqlDriver). Result set objects provide the interface for executing and manipulating SQL queries (see QSqlQuery).
.PP
See also Database Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QSqlDatabase::QSqlDatabase ( const QString & type, const QString & name, QObject * parent = 0, const char * objname = 0 )\fC [protected]\fR"
Creates a QSqlDatabase connection called \fIname\fR that uses the driver referred to by \fItype\fR, with the parent \fIparent\fR and the object name \fIobjname\fR. If the \fItype\fR is not recognized, the database connection will have no functionality.
.PP
The currently available drivers are:
.PP
<center>.nf
.TS
l - l. Driver Type Description QODBC3 ODBC Driver (includes Microsoft SQL Server) QOCI8 Oracle Call Interface Driver QPSQL7 PostgreSQL v6.x and v7.x Driver QTDS7 Sybase Adaptive Server QMYSQL3 MySQL Driver QDB2 IBM DB2, v7.1 and higher QSQLITE SQLite Driver QIBASE
.TE
.fi
</center>
.PP
Additional third party drivers, including your own custom drivers, can be loaded dynamically.
.PP
See also registerSqlDriver().
.SH "QSqlDatabase::QSqlDatabase ( QSqlDriver * driver, QObject * parent = 0, const char * objname = 0 )\fC [protected]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Creates a database connection using the driver \fIdriver\fR, with the parent \fIparent\fR and the object name \fIobjname\fR.
.PP
\fBWarning:\fR The framework takes ownership of the \fIdriver\fR pointer, so it should not be deleted.
.SH "QSqlDatabase::~QSqlDatabase ()"
Destroys the object and frees any allocated resources.
.SH "QSqlDatabase * QSqlDatabase::addDatabase ( const QString & type, const QString & connectionName = defaultConnection )\fC [static]\fR"
Adds a database to the list of database connections using the driver \fItype\fR and the connection name \fIconnectionName\fR.
.PP
The database connection is referred to by \fIconnectionName\fR. The newly added database connection is returned. This pointer is owned by QSqlDatabase and will be deleted on program exit or when removeDatabase() is called.
.PP
If \fIconnectionName\fR is not specified, the newly added database connection becomes the default database connection for the application, and subsequent calls to database() (without a database name parameter) will return a pointer to it. If \fIconnectionName\fR is given, use database(connectionName) to retrieve a pointer to the database connection.
.PP
\fBWarning:\fR 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 \fIconnectionName\fR.
.PP
See also database() and removeDatabase().
.PP
Examples:
.)l sql/overview/connect1/main.cpp, sql/overview/connection.cpp, and sql/sqltable/main.cpp.
.SH "QSqlDatabase * QSqlDatabase::addDatabase ( QSqlDriver * driver, const QString & connectionName = defaultConnection )\fC [static]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
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 QPSQL7 driver can be done the following way:
.PP
.nf
.br
    #include "qtdir/src/sql/drivers/psql/qsql_psql.cpp"
.br
.fi
(We assume that \fCqtdir\fR is the directory where Qt is installed.) This will pull in the code that is needed to use the PostgreSQL client library and to instantiate a QPSQLDriver object, assuming that you have the PostgreSQL headers somewhere in your include search path.
.PP
.nf
.br
    PGconn* con = PQconnectdb( "host=server user=bart password=simpson dbname=springfield" );
.br
    QPSQLDriver* drv =  new QPSQLDriver( con );
.br
    QSqlDatabase* db = QSqlDatabase::addDatabase( drv ); // becomes the new default connection
.br
    QSqlQuery q;
.br
    q.exec( "SELECT * FROM people" );
.br
    ...
.br
.fi
.PP
The above code sets up a PostgreSQL connection and instantiates a QPSQLDriver object. Next, addDatabase() is called to add the connection to the known connections so that it can be used by the Qt SQL classes. When a driver is instantiated with a connection handle (or set of handles), Qt assumes that you have already opened the database connection.
.PP
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 \fC.pro\fR file:
.PP
.nf
.br
    unix:LIBS += -lpq
.br
    win32:LIBS += libpqdll.lib
.br
.fi
.PP
You will need to have the client library in your linker's search path.
.PP
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.
.PP
<center>.nf
.TS
l - l. Driver Class name Constructor arguments File to include QPSQL7 QPSQLDriver PGconn* connection QMYSQL3 QMYSQLDriver MYSQL* connection QOCI8 QOCIDriver OCIEnv* environment, OCIError* error, OCISvcCtx* serviceContext QODBC3 QODBCDriver SQLHANDLE environment, SQLHANDLE connection QDB2 QDB2 SQLHANDLE environment, SQLHANDLE connection QTDS7 QTDSDriver LOGINREC* loginRecord, DBPROCESS* dbProcess, const QString& hostName QSQLITE QSQLiteDriver sqlite* connection QIBASE QIBaseDriver isc_db_handle connection 
.TE
.fi
</center>
.PP
Note: The host name (or service name) is needed when constructing the QTDSDriver for creating new connections for internal queries. This is to prevent the simultaneous usage of several QSqlQuery/QSqlCursor objects from blocking each other.
.PP
\fBWarning:\fR The SQL framework takes ownership of the \fIdriver\fR pointer, and it should not be deleted. The returned QSqlDatabase object is owned by the framework and must not be deleted. If you want to explicitly remove the connection, use removeDatabase()
.PP
See also drivers().
.SH "void QSqlDatabase::close ()"
Closes the database connection, freeing any resources acquired.
.PP
See also removeDatabase().
.SH "bool QSqlDatabase::commit ()"
Commits a transaction to the database if the driver supports transactions. Returns TRUE if the operation succeeded; otherwise returns FALSE.
.PP
See also QSqlDriver::hasFeature() and rollback().
.SH "QString QSqlDatabase::connectOptions () const"
Returns the database connect options. See the "connectOptions" property for details.
.SH "bool QSqlDatabase::contains ( const QString & connectionName = defaultConnection )\fC [static]\fR"
Returns TRUE if the list of database connections contains \fIconnectionName\fR; otherwise returns FALSE.
.SH "QSqlDatabase * QSqlDatabase::database ( const QString & connectionName = defaultConnection, bool open = TRUE )\fC [static]\fR"
Returns the database connection called \fIconnectionName\fR. The database connection must have been previously added with addDatabase(). If \fIopen\fR is TRUE (the default) and the database connection is not already open it is opened now. If no \fIconnectionName\fR is specified the default connection is used. If \fIconnectionName\fR does not exist in the list of databases, 0 is returned. The pointer returned is owned by QSqlDatabase and should \fInot\fR be deleted.
.PP
\fBWarning:\fR There are restrictions on the use of database connections in threaded applications. Please see the Thread Support in Qt document for more information about threading and SQL databases.
.PP
Examples:
.)l sql/overview/basicbrowsing/main.cpp and sql/overview/create_connections/main.cpp.
.SH "QString QSqlDatabase::databaseName () const"
Returns the name of the database. See the "databaseName" property for details.
.SH "QSqlDriver * QSqlDatabase::driver () const"
Returns the database driver used to access the database connection.
.SH "QString QSqlDatabase::driverName () const"
Returns the name of the driver used by the database connection.
.SH "QStringList QSqlDatabase::drivers ()\fC [static]\fR"
Returns a list of all the available database drivers.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
    QStringList list = QSqlDatabase::drivers();
.br
    QStringList::Iterator it = list.begin();
.br
    while( it != list.end() ) {
.br
        myProcessing( *it );
.br
        ++it;
.br
    }
.br
.fi
.SH "QSqlQuery QSqlDatabase::exec ( const QString & query = QString::null ) const"
Executes a SQL statement (e.g. an \fCINSERT\fR, \fCUPDATE\fR or \fCDELETE\fR statement) on the database, and returns a QSqlQuery object. Use lastError() to retrieve error information. If \fIquery\fR is QString::null, an empty, invalid query is returned and lastError() is not affected.
.PP
See also QSqlQuery and lastError().
.SH "QString QSqlDatabase::hostName () const"
Returns the host name where the database resides. See the "hostName" property for details.
.SH "bool QSqlDatabase::isDriverAvailable ( const QString & name )\fC [static]\fR"
Returns TRUE if a driver called \fIname\fR is available; otherwise returns FALSE.
.PP
See also drivers().
.SH "bool QSqlDatabase::isOpen () const"
Returns TRUE if the database connection is currently open; otherwise returns FALSE.
.SH "bool QSqlDatabase::isOpenError () const"
Returns TRUE if there was an error opening the database connection; otherwise returns FALSE. Error information can be retrieved using the lastError() function.
.SH "QSqlError QSqlDatabase::lastError () const"
Returns information about the last error that occurred on the database. See QSqlError for more information.
.PP
Examples:
.)l sql/overview/connection.cpp and sql/sqltable/main.cpp.
.SH "bool QSqlDatabase::open ()"
Opens the database connection using the current connection values. Returns TRUE on success; otherwise returns FALSE. Error information can be retrieved using the lastError() function.
.PP
See also lastError().
.PP
Examples:
.)l sql/overview/connect1/main.cpp, sql/overview/connection.cpp, and sql/sqltable/main.cpp.
.SH "bool QSqlDatabase::open ( const QString & user, const QString & password )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Opens the database connection using the given \fIuser\fR name and \fIpassword\fR. Returns TRUE on success; otherwise returns FALSE. Error information can be retrieved using the lastError() function.
.PP
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.
.PP
See also lastError().
.SH "QString QSqlDatabase::password () const"
Returns the password used to connect to the database. See the "password" property for details.
.SH "int QSqlDatabase::port () const"
Returns the port used to connect to the database. See the "port" property for details.
.SH "QSqlIndex QSqlDatabase::primaryIndex ( const QString & tablename ) const"
Returns the primary index for table \fItablename\fR. If no primary index exists an empty QSqlIndex will be returned.
.SH "QSqlRecord QSqlDatabase::record ( const QString & tablename ) const"
Returns a QSqlRecord populated with the names of all the fields in the table (or view) called \fItablename\fR. The order in which the fields appear in the record is undefined. If no such table (or view) exists, an empty record is returned.
.PP
See also recordInfo().
.SH "QSqlRecord QSqlDatabase::record ( const QSqlQuery & query ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns a QSqlRecord populated with the names of all the fields used in the SQL \fIquery\fR. If the query is a "SELECT *" the order in which fields appear in the record is undefined.
.PP
See also recordInfo().
.SH "QSqlRecordInfo QSqlDatabase::recordInfo ( const QString & tablename ) const"
Returns a QSqlRecordInfo populated with meta data about the table or view \fItablename\fR. If no such table (or view) exists, an empty record is returned.
.PP
See also QSqlRecordInfo, QSqlFieldInfo, and record().
.SH "QSqlRecordInfo QSqlDatabase::recordInfo ( const QSqlQuery & query ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns a QSqlRecordInfo object with meta data for the QSqlQuery \fIquery\fR. Note that this overloaded function may return less information than the recordInfo() function which takes the name of a table as parameter.
.PP
See also QSqlRecordInfo, QSqlFieldInfo, and record().
.SH "void QSqlDatabase::registerSqlDriver ( const QString & name, const QSqlDriverCreatorBase * creator )\fC [static]\fR"
This function registers a new SQL driver called \fIname\fR, within the SQL framework. This is useful if you have a custom SQL driver and don't want to compile it as a plugin.
.PP
Example usage:
.PP
.nf
.br
    QSqlDatabase::registerSqlDriver( "MYDRIVER", new QSqlDriverCreator<MyDatabaseDriver> );
.br
    QSqlDatabase* db = QSqlDatabase::addDatabase( "MYDRIVER" );
.br
    ...
.br
.fi
.PP
\fBWarning:\fR The framework takes ownership of the \fIcreator\fR pointer, so it should not be deleted.
.SH "void QSqlDatabase::removeDatabase ( const QString & connectionName )\fC [static]\fR"
Removes the database connection \fIconnectionName\fR from the list of database connections.
.PP
\fBWarning:\fR There should be no open queries on the database connection when this function is called, otherwise a resource leak will occur.
.SH "void QSqlDatabase::removeDatabase ( QSqlDatabase * db )\fC [static]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Removes the database connection \fIdb\fR from the list of database connections. The QSqlDatabase object is destroyed when it is removed from the list.
.PP
\fBWarning:\fR The \fIdb\fR 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.
.SH "bool QSqlDatabase::rollback ()"
Rolls a transaction back on the database if the driver supports transactions. Returns TRUE if the operation succeeded; otherwise returns FALSE.
.PP
See also QSqlDriver::hasFeature(), commit(), and transaction().
.SH "void QSqlDatabase::setConnectOptions ( const QString & options = QString::null )"
Sets the database connect options to \fIoptions\fR. See the "connectOptions" property for details.
.SH "void QSqlDatabase::setDatabaseName ( const QString & name )\fC [virtual]\fR"
Sets the name of the database to \fIname\fR. See the "databaseName" property for details.
.SH "void QSqlDatabase::setHostName ( const QString & host )\fC [virtual]\fR"
Sets the host name where the database resides to \fIhost\fR. See the "hostName" property for details.
.SH "void QSqlDatabase::setPassword ( const QString & password )\fC [virtual]\fR"
Sets the password used to connect to the database to \fIpassword\fR. See the "password" property for details.
.SH "void QSqlDatabase::setPort ( int p )\fC [virtual]\fR"
Sets the port used to connect to the database to \fIp\fR. See the "port" property for details.
.SH "void QSqlDatabase::setUserName ( const QString & name )\fC [virtual]\fR"
Sets the user name connected to the database to \fIname\fR. See the "userName" property for details.
.SH "QStringList QSqlDatabase::tables ( QSql::TableType type ) const"
Returns a list of the database's tables, system tables and views, as specified by the parameter \fItype\fR.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
    QStringList list = myDatabase.tables( QSql::Tables | QSql::Views );
.br
    QStringList::Iterator it = list.begin();
.br
    while( it != list.end() ) {
.br
        myProcessing( *it );
.br
        ++it;
.br
    }
.br
.fi
.PP
Example: sql/sqltable/main.cpp.
.SH "QStringList QSqlDatabase::tables () const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
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 \fCtype\fR parameter.
.PP
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
.PP
.nf
.br
    QStringList list = myDatabase.tables();
.br
    QStringList::Iterator it = list.begin();
.br
    while( it != list.end() ) {
.br
        myProcessing( *it );
.br
        ++it;
.br
    }
.br
.fi
.SH "bool QSqlDatabase::transaction ()"
Begins a transaction on the database if the driver supports transactions. Returns TRUE if the operation succeeded; otherwise returns FALSE.
.PP
See also QSqlDriver::hasFeature(), commit(), and rollback().
.SH "QString QSqlDatabase::userName () const"
Returns the user name connected to the database. See the "userName" property for details.
.SS "Property Documentation"
.SH "QString connectOptions"
This property holds the database connect options.
.PP
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:
.PP
<center>.nf
.TS
l - l. ODBC MySQL PostgreSQL
.TP
SQL_ATTR_ACCESS_MODE
.TP
SQL_ATTR_LOGIN_TIMEOUT
.TP
SQL_ATTR_CONNECTION_TIMEOUT
.TP
SQL_ATTR_CURRENT_CATALOG
.TP
SQL_ATTR_METADATA_ID
.TP
SQL_ATTR_PACKET_SIZE
.TP
SQL_ATTR_TRACEFILE
.TP
SQL_ATTR_TRACE
.PP	.TP
CLIENT_COMPRESS
.TP
CLIENT_FOUND_ROWS
.TP
CLIENT_IGNORE_SPACE
.TP
CLIENT_SSL
.TP
CLIENT_ODBC
.TP
CLIENT_NO_SCHEMA
.TP
CLIENT_INTERACTIVE
.PP	.TP
connect_timeout
.TP
options
.TP
tty
.TP
requiressl
.TP
service DB2 OCI TDS
.TP
SQL_ATTR_ACCESS_MODE
.TP
SQL_ATTR_LOGIN_TIMEOUT
.PP	\fInone\fR
.PP
.TE
.fi
</center>
.PP
Example of usage:
.PP
.nf
.br
    ...
.br
    // MySQL connection
.br
    db->setConnectOptions( "CLIENT_SSL;CLIENT_IGNORE_SPACE" ); // use an SSL connection to the server
.br
    if ( !db->open() ) {
.br
        db->setConnectOptions(); // clears the connect option string
.br
        ...
.br
    }
.br
    ...
.br
    // PostgreSQL connection
.br
    db->setConnectOptions( "requiressl=1" ); // enable PostgreSQL SSL connections
.br
    if ( !db->open() ) {
.br
        db->setConnectOptions(); // clear options
.br
        ...
.br
    }
.br
    ...
.br
    // ODBC connection
.br
    db->setConnectOptions( "SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY;SQL_ATTR_TRACE=SQL_OPT_TRACE_ON" ); // set ODBC options
.br
    if ( !db->open() ) {
.br
        db->setConnectOptions(); // don't try to set this option
.br
        ...
.br
    }
.br
.fi
.PP
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.
.PP
See also
.PP
Set this property's value with setConnectOptions() and get this property's value with connectOptions().
.SH "QString databaseName"
This property holds the name of the database.
.PP
Note that the database name is the TNS Service Name for the QOCI8 (Oracle) driver.
.PP
For the QODBC3 driver it can either be a DSN, a DSN filename (the file must have a \fC.dsn\fR extension), or a connection string. MS Access users can for example use the following connection string to open a \fC.mdb\fR file directly, instead of having to create a DSN entry in the ODBC manager:
.PP
.nf
.br
    ...
.br
    db = QSqlDatabase::addDatabase( "QODBC3" );
.br
    db->setDatabaseName( "DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb" );
.br
    if ( db->open() ) {
.br
        // success!
.br
    }
.br
    ...
.br
.fi
("FIL" is the required spelling in Microsoft's API.)
.PP
There is no default value.
.PP
Set this property's value with setDatabaseName() and get this property's value with databaseName().
.SH "QString hostName"
This property holds the host name where the database resides.
.PP
There is no default value.
.PP
Set this property's value with setHostName() and get this property's value with hostName().
.SH "QString password"
This property holds the password used to connect to the database.
.PP
There is no default value.
.PP
\fBWarning:\fR This function stores the password in plain text within Qt. Use the open() call that takes a password as parameter to avoid this behaviour.
.PP
See also open().
.PP
Set this property's value with setPassword() and get this property's value with password().
.SH "int port"
This property holds the port used to connect to the database.
.PP
There is no default value.
.PP
Set this property's value with setPort() and get this property's value with port().
.SH "QString userName"
This property holds the user name connected to the database.
.PP
There is no default value.
.PP
Set this property's value with setUserName() and get this property's value with userName().

.SH "SEE ALSO"
.BR http://doc.trolltech.com/qsqldatabase.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qsqldatabase.3qt) and the Qt
version (3.3.8).