![]() |
Qt 6.x
The Qt SDK
|
The QSqlDatabase class handles a connection to a database. More...
#include <qsqldatabase.h>
Public Member Functions | |
QSqlDatabase () | |
Creates an empty, invalid QSqlDatabase object. | |
QSqlDatabase (const QSqlDatabase &other) | |
Creates a copy of other. | |
~QSqlDatabase () | |
Destroys the object and frees any allocated resources. | |
QSqlDatabase & | operator= (const QSqlDatabase &other) |
Assigns other to this object. | |
bool | open () |
Executes a SQL statement on the database and returns a QSqlQuery object. | |
bool | open (const QString &user, const QString &password) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Opens the database connection using the given user name and password. | |
void | close () |
Closes the database connection, freeing any resources acquired, and invalidating any existing QSqlQuery objects that are used with the database. | |
bool | isOpen () const |
Returns true if the database connection is currently open; otherwise returns false . | |
bool | isOpenError () const |
Returns true if there was an error opening the database connection; otherwise returns false . | |
QStringList | tables (QSql::TableType type=QSql::Tables) const |
Returns a list of the database's tables, system tables and views, as specified by the parameter type. | |
QSqlIndex | primaryIndex (const QString &tablename) const |
Returns the primary index for table tablename. | |
QSqlRecord | record (const QString &tablename) const |
Returns a QSqlRecord populated with the names of all the fields in the table (or view) called tablename. | |
QSqlError | lastError () const |
Returns information about the last error that occurred on the database. | |
bool | isValid () const |
Returns true if the QSqlDatabase has a valid driver. | |
bool | transaction () |
Begins a transaction on the database if the driver supports transactions. | |
bool | commit () |
Commits a transaction to the database if the driver supports transactions and a transaction() has been started. | |
bool | rollback () |
Rolls back a transaction on the database, if the driver supports transactions and a transaction() has been started. | |
void | setDatabaseName (const QString &name) |
Sets the connection's database name to name. | |
void | setUserName (const QString &name) |
Sets the connection's user name to name. | |
void | setPassword (const QString &password) |
Sets the connection's password to password. | |
void | setHostName (const QString &host) |
Sets the connection's host name to host. | |
void | setPort (int p) |
Sets the connection's port number to port. | |
void | setConnectOptions (const QString &options=QString()) |
Sets database-specific options. | |
QString | databaseName () const |
Returns the connection's database name, which may be empty. | |
QString | userName () const |
Returns the connection's user name; it may be empty. | |
QString | password () const |
Returns the connection's password. | |
QString | hostName () const |
Returns the connection's host name; it may be empty. | |
QString | driverName () const |
Returns the connection's driver name. | |
int | port () const |
Returns the connection's port number. | |
QString | connectOptions () const |
Returns the connection options string used for this connection. | |
QString | connectionName () const |
void | setNumericalPrecisionPolicy (QSql::NumericalPrecisionPolicy precisionPolicy) |
QSql::NumericalPrecisionPolicy | numericalPrecisionPolicy () const |
QSqlDriver * | driver () const |
Returns the database driver used to access the database connection. | |
Static Public Member Functions | |
static QSqlDatabase | addDatabase (const QString &type, const QString &connectionName=QLatin1StringView(defaultConnection)) |
\threadsafe | |
static QSqlDatabase | addDatabase (QSqlDriver *driver, const QString &connectionName=QLatin1StringView(defaultConnection)) |
This overload is useful when you want to create a database connection with a \l{QSqlDriver} {driver} you instantiated yourself. | |
static QSqlDatabase | cloneDatabase (const QSqlDatabase &other, const QString &connectionName) |
Clones the database connection other and stores it as connectionName. | |
static QSqlDatabase | cloneDatabase (const QString &other, const QString &connectionName) |
static QSqlDatabase | database (const QString &connectionName=QLatin1StringView(defaultConnection), bool open=true) |
\threadsafe | |
static void | removeDatabase (const QString &connectionName) |
\threadsafe | |
static bool | contains (const QString &connectionName=QLatin1StringView(defaultConnection)) |
\threadsafe | |
static QStringList | drivers () |
Returns a list of all the available database drivers. | |
static QStringList | connectionNames () |
\threadsafe | |
static void | registerSqlDriver (const QString &name, QSqlDriverCreatorBase *creator) |
[2] | |
static bool | isDriverAvailable (const QString &name) |
Returns true if a driver called name is available; otherwise returns false . | |
Static Public Attributes | |
static const char * | defaultConnection |
Protected Member Functions | |
QSqlDatabase (const QString &type) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QSqlDatabase connection that uses the driver referred to by type. | |
QSqlDatabase (QSqlDriver *driver) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a database connection using the given driver. | |
Friends | |
class | QSqlDatabasePrivate |
The QSqlDatabase class handles a connection to a database.
\inmodule QtSql
The QSqlDatabase class provides an interface for accessing a database through a connection. An instance of QSqlDatabase represents the connection. The connection provides access to the database via one of the \l{SQL Database Drivers::Supported Databases} {supported database drivers}, which are derived from QSqlDriver. Alternatively, you can subclass your own database driver from QSqlDriver. See \l{How to Write Your Own Database Driver} for more information.
Create a connection (i.e., an instance of QSqlDatabase) by calling one of the static addDatabase() functions, where you specify \l{SQL Database Drivers::Supported Databases} {the driver or type of driver} to use (depending on the type of database) and a connection name. A connection is known by its own name, {not} by the name of the database it connects to. You can have multiple connections to one database. QSqlDatabase also supports the concept of a {default} connection, which is the unnamed connection. To create the default connection, don't pass the connection name argument when you call addDatabase(). Subsequently, the default connection will be assumed if you call any static member function without specifying the connection name. The following snippet shows how to create and open a default connection to a PostgreSQL database:
Once the QSqlDatabase object has been created, set the connection parameters with setDatabaseName(), setUserName(), setPassword(), setHostName(), setPort(), and setConnectOptions(). Then call open() to activate the physical connection to the database. The connection is not usable until you open it.
The connection defined above will be the {default} connection, because we didn't give a connection name to \l{QSqlDatabase::} {addDatabase()}. Subsequently, you can get the default connection by calling database() without the connection name argument:
QSqlDatabase is a value class. Changes made to a database connection via one instance of QSqlDatabase will affect other instances of QSqlDatabase that represent the same connection. Use cloneDatabase() to create an independent database connection based on an existing one.
If you create multiple database connections, specify a unique connection name for each one, when you call addDatabase(). Use database() with a connection name to get that connection. Use removeDatabase() with a connection name to remove a connection. QSqlDatabase outputs a warning if you try to remove a connection referenced by other QSqlDatabase objects. Use contains() to see if a given connection name is in the list of connections.
\table \header
Definition at line 34 of file qsqldatabase.h.
QSqlDatabase::QSqlDatabase | ( | ) |
Creates an empty, invalid QSqlDatabase object.
Use addDatabase(), removeDatabase(), and database() to get valid QSqlDatabase objects.
Definition at line 611 of file qsqldatabase.cpp.
References QBasicAtomicInteger< T >::ref(), and QSqlDatabasePrivate::ref.
Referenced by cloneDatabase().
QSqlDatabase::QSqlDatabase | ( | const QSqlDatabase & | other | ) |
Creates a copy of other.
Definition at line 620 of file qsqldatabase.cpp.
References other(), QBasicAtomicInteger< T >::ref(), and QSqlDatabasePrivate::ref.
QSqlDatabase::~QSqlDatabase | ( | ) |
Destroys the object and frees any allocated resources.
Definition at line 678 of file qsqldatabase.cpp.
References close(), QBasicAtomicInteger< T >::deref(), and QSqlDatabasePrivate::ref.
|
explicitprotected |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QSqlDatabase connection that uses the driver referred to by type.
If the type is not recognized, the database connection will have no functionality.
The currently available driver types are:
\table \header
Additional third party drivers, including your own custom drivers, can be loaded dynamically.
Definition at line 589 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::init().
|
explicitprotected |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a database connection using the given driver.
Definition at line 601 of file qsqldatabase.cpp.
|
static |
\threadsafe
Adds a database to the list of database connections using the driver type and the connection name connectionName. If there already exists a database connection called connectionName, that connection is removed.
The database connection is referred to by connectionName. The newly added database connection is returned.
If type is not available or could not be loaded, isValid() returns false
.
If connectionName is not specified, the new connection becomes the default connection for the application, and subsequent calls to database() without the connection name argument will return the default connection. If a connectionName is provided here, use database(connectionName) to retrieve the connection.
Before using the connection, it must be initialized. e.g., call some or all of setDatabaseName(), setUserName(), setPassword(), setHostName(), setPort(), and setConnectOptions(), and, finally, open().
Definition at line 427 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::addDatabase(), connectionName(), and db.
Referenced by QQmlLocalStorage::openDatabaseSync(), QSqlDatabase_snippets(), setmyDatabase(), and sql_intro_snippets().
|
static |
This overload is useful when you want to create a database connection with a \l{QSqlDriver} {driver} you instantiated yourself.
It might be your own database driver, or you might just need to instantiate one of the Qt drivers yourself. If you do this, it is recommended that you include the driver code in your application. For example, you can create a PostgreSQL connection with your own QPSQL driver like this:
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.
qtdir
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.Remember that you must link your application against the database client library. Make sure the client library is in your linker's search path, and add lines like these to your {.pro} file:
The method described works for all the supplied drivers. The only difference will be in the driver constructor arguments. Here is a table of the drivers included with Qt, their source code files, and their constructor arguments:
\table \header
qsql_psql.cpp
\row qsql_mysql.cpp
\row qsql_oci.cpp
\row qsql_odbc.cpp
\row qsql_db2.cpp
\row qsql_sqlite.cpp
\row qsql_mimer.cpp
\row qsql_ibase.cpp
\endtableDefinition at line 1230 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::addDatabase(), connectionName(), db, and driver().
|
static |
Clones the database connection other and stores it as connectionName.
All the settings from the original database, e.g. databaseName(), hostName(), etc., are copied across. Does nothing if other is an invalid database. Returns the newly created database connection.
\reentrant
Definition at line 1260 of file qsqldatabase.cpp.
References QSqlDatabase(), QSqlDatabasePrivate::addDatabase(), connectionName(), db, and other().
Referenced by cloneDatabase().
|
static |
Clones the database connection other and stores it as connectionName. All the settings from the original database, e.g. databaseName(), hostName(), etc., are copied across. Does nothing if other is an invalid database. Returns the newly created database connection.
This overload is useful when cloning the database in another thread to the one that is used by the database represented by other.
Definition at line 1288 of file qsqldatabase.cpp.
References cloneDatabase(), connectionName(), other(), Q_ASSERT, and QConnectionDict::value_ts().
void QSqlDatabase::close | ( | ) |
Closes the database connection, freeing any resources acquired, and invalidating any existing QSqlQuery objects that are used with the database.
This will also affect copies of this QSqlDatabase object.
Definition at line 753 of file qsqldatabase.cpp.
References QSqlDriver::close(), and QSqlDatabasePrivate::driver.
Referenced by ~QSqlDatabase().
bool QSqlDatabase::commit | ( | ) |
Commits a transaction to the database if the driver supports transactions and a transaction() has been started.
Returns {true} if the operation succeeded. Otherwise it returns
{false}.
{false} if there is an \l{QSqlQuery::isActive()} {active query} using the database for a
{SELECT}. Make the query \l{QSqlQuery::isActive()} {inactive} before doing the commit.Call lastError() to get information about errors.
Definition at line 807 of file qsqldatabase.cpp.
References QSqlDriver::commitTransaction(), QSqlDatabasePrivate::driver, QSqlDriver::hasFeature(), and QSqlDriver::Transactions.
Referenced by sql_intro_snippets().
QString QSqlDatabase::connectionName | ( | ) | const |
Returns the connection name, which may be empty.
Definition at line 1304 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::connName.
Referenced by addDatabase(), addDatabase(), cloneDatabase(), cloneDatabase(), contains(), database(), and removeDatabase().
|
static |
\threadsafe
Returns a list containing the names of all connections.
Definition at line 557 of file qsqldatabase.cpp.
Referenced by QQmlLocalStorage::openDatabaseSync().
QString QSqlDatabase::connectOptions | ( | ) | const |
Returns the connection options string used for this connection.
The string may be empty.
Definition at line 1123 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::connOptions.
|
static |
\threadsafe
Returns true
if the list of database connections contains connectionName; otherwise returns false
.
Definition at line 545 of file qsqldatabase.cpp.
References connectionName().
|
static |
\threadsafe
Returns the database connection called connectionName. The database connection must have been previously added with addDatabase(). If open is true (the default) and the database connection is not already open it is opened now. If no connectionName is specified the default connection is used. If connectionName does not exist in the list of databases, an invalid connection is returned.
Definition at line 448 of file qsqldatabase.cpp.
References connectionName(), QSqlDatabasePrivate::database(), and open().
Referenced by QSqlTableModel::QSqlTableModel(), QSqlTableModel::QSqlTableModel(), checkHandle(), dbQdebug(), openDatabase(), QQmlLocalStorage::openDatabaseSync(), qInit(), QSqlDatabase_snippets(), querySqlite(), removeDatabase(), and sql_intro_snippets().
QString QSqlDatabase::databaseName | ( | ) | const |
Returns the connection's database name, which may be empty.
Definition at line 959 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::dbname.
QSqlDriver * QSqlDatabase::driver | ( | ) | const |
Returns the database driver used to access the database connection.
Definition at line 1022 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::driver.
Referenced by addDatabase(), QSqlTableModelPrivate::exec(), numericalPrecisionPolicy(), QRelation::populateDictionary(), qInit(), setNumericalPrecisionPolicy(), sql_intro_snippets(), and QSqlTableModelPrivate::strippedFieldName().
QString QSqlDatabase::driverName | ( | ) | const |
Returns the connection's driver name.
Definition at line 999 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::drvName.
|
static |
Returns a list of all the available database drivers.
Definition at line 491 of file qsqldatabase.cpp.
References QListSpecialMethodsBase< T >::contains(), QSqlDatabasePrivate::driverDict(), keyMap, list, loader, and lock.
Referenced by QSqlDatabasePrivate::init(), isDriverAvailable(), and testInt().
QString QSqlDatabase::hostName | ( | ) | const |
Returns the connection's host name; it may be empty.
Definition at line 989 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::hname.
|
static |
Returns true
if a driver called name is available; otherwise returns false
.
Definition at line 1135 of file qsqldatabase.cpp.
References drivers().
bool QSqlDatabase::isOpen | ( | ) | const |
Returns true
if the database connection is currently open; otherwise returns false
.
Definition at line 763 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::driver, and QSqlDriver::isOpen().
Referenced by QQmlLocalStorage::openDatabaseSync().
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.
Definition at line 774 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::driver, and QSqlDriver::isOpenError().
bool QSqlDatabase::isValid | ( | ) | const |
Returns true
if the QSqlDatabase has a valid driver.
Example:
Definition at line 1243 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::driver, and QSqlDatabasePrivate::shared_null().
Referenced by qInit(), setConnectOptions(), setDatabaseName(), setHostName(), setPassword(), setPort(), and setUserName().
QSqlError QSqlDatabase::lastError | ( | ) | const |
Returns information about the last error that occurred on the database.
Failures that occur in conjunction with an individual query are reported by QSqlQuery::lastError().
Definition at line 1037 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::driver, and QSqlDriver::lastError().
QSql::NumericalPrecisionPolicy QSqlDatabase::numericalPrecisionPolicy | ( | ) | const |
Returns the current default precision policy for the database connection.
Definition at line 1341 of file qsqldatabase.cpp.
References driver(), QSqlDriver::numericalPrecisionPolicy(), and QSqlDatabasePrivate::precisionPolicy.
bool QSqlDatabase::open | ( | ) |
Executes a SQL statement on the database and returns a QSqlQuery object.
Use lastError() to retrieve error information. If query is empty, an empty, invalid query is returned and lastError() is not affected.
Opens the database connection using the current connection values. Returns true
on success; otherwise returns false
. Error information can be retrieved using lastError().
Definition at line 716 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::connOptions, QSqlDatabasePrivate::dbname, QSqlDatabasePrivate::driver, QSqlDatabasePrivate::hname, QSqlDriver::open(), QSqlDatabasePrivate::port, QSqlDatabasePrivate::pword, and QSqlDatabasePrivate::uname.
Referenced by database(), and QQmlLocalStorage::openDatabaseSync().
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Opens the database connection using the given user name and password.
Returns true
on success; otherwise returns false
. Error information can be retrieved using the lastError() function.
This function does not store the password it is given. Instead, the password is passed directly to the driver for opening the connection and it is then discarded.
Definition at line 736 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::connOptions, QSqlDatabasePrivate::dbname, QSqlDatabasePrivate::driver, QSqlDatabasePrivate::hname, QSqlDriver::open(), password(), QSqlDatabasePrivate::port, and setUserName().
QSqlDatabase & QSqlDatabase::operator= | ( | const QSqlDatabase & | other | ) |
Assigns other to this object.
Definition at line 629 of file qsqldatabase.cpp.
References other(), and qAtomicAssign().
QString QSqlDatabase::password | ( | ) | const |
Returns the connection's password.
An empty string will be returned if the password was not set with setPassword(), and if the password was given in the open() call, or if no password was used.
Definition at line 979 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::pword.
Referenced by open(), and setPassword().
int QSqlDatabase::port | ( | ) | const |
Returns the connection's port number.
The value is undefined if the port number has not been set.
Definition at line 1010 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::port.
Referenced by setPort().
Returns the primary index for table tablename.
If no primary index exists, an empty QSqlIndex is returned.
Definition at line 1067 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::driver, and QSqlDriver::primaryIndex().
Referenced by QSqlTableModelPrivate::initRecordAndPrimaryIndex().
QSqlRecord QSqlDatabase::record | ( | const QString & | tablename | ) | const |
Returns a QSqlRecord populated with the names of all the fields in the table (or view) called tablename.
The order in which the fields appear in the record is undefined. If no such table (or view) exists, an empty record is returned.
Definition at line 1085 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::driver, and QSqlDriver::record().
Referenced by QSqlTableModelPrivate::initRecordAndPrimaryIndex(), and QSqlRelationalTableModel::selectStatement().
|
static |
[2]
This function registers a new SQL driver called name, within the SQL framework.
This is useful if you have a custom SQL driver and don't want to compile it as a plugin.
Example:
QSqlDatabase takes ownership of the creator pointer, so you mustn't delete it yourself.
Definition at line 528 of file qsqldatabase.cpp.
References creator, QSqlDatabasePrivate::driverDict(), and lock.
\threadsafe
Removes the database connection connectionName from the list of database connections.
Example:
The correct way to do it:
To remove the default connection, which may have been created with a call to addDatabase() not specifying a connection name, you can retrieve the default connection name by calling connectionName() on the database returned by database(). Note that if a default database hasn't been created an invalid database will be returned.
Definition at line 480 of file qsqldatabase.cpp.
References connectionName(), and QSqlDatabasePrivate::removeDatabase().
Referenced by dbQdebug(), openDatabase(), and removeDatabase().
bool QSqlDatabase::rollback | ( | ) |
Rolls back a transaction on the database, if the driver supports transactions and a transaction() has been started.
Returns {true} if the operation succeeded. Otherwise it returns
{false}.
{false} if there is an \l{QSqlQuery::isActive()} {active query} using the database for a
{SELECT}. Make the query \l{QSqlQuery::isActive()} {inactive} before doing the rollback.Call lastError() to get information about errors.
Definition at line 828 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::driver, QSqlDriver::hasFeature(), QSqlDriver::rollbackTransaction(), and QSqlDriver::Transactions.
Sets database-specific options.
This must be done before the connection is opened, otherwise it has no effect. Another possibility is to close the connection, call QSqlDatabase::setConnectOptions(), and open() the connection again.
The format of the options string is a semicolon separated list of option names or option=value pairs. The options depend on the database client used and are described for each plugin in the \l{sql-driver.html}{SQL Database Drivers} page.
Examples:
Refer to the client library documentation for more information about the different options.
Definition at line 1111 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::connOptions, and isValid().
Sets the connection's database name to name.
To have effect, the database name must be set {before} the connection is \l{open()} {opened}. Alternatively, you can close() the connection, set the database name, and call open() again.
For the QSQLITE driver, if the database name specified does not exist, then it will create the file for you unless the QSQLITE_OPEN_READONLY option is set.
Additionally, name can be set to ":memory:"
which will create a temporary database which is only available for the lifetime of the application.
For the QOCI (Oracle) driver, the database name is the TNS Service Name.
For the QODBC driver, the name can either be a DSN, a DSN filename (in which case the file must have a .dsn extension), or a connection string.
For example, Microsoft Access users can use the following connection string to open an .mdb file directly, instead of having to create a DSN entry in the ODBC manager:
There is no default value.
Definition at line 871 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::dbname, and isValid().
Referenced by QQmlLocalStorage::openDatabaseSync().
Sets the connection's host name to host.
To have effect, the host name must be set {before} the connection is \l{open()} {opened}. Alternatively, you can close() the connection, set the host name, and call open() again.
There is no default value.
Definition at line 929 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::hname, and isValid().
void QSqlDatabase::setNumericalPrecisionPolicy | ( | QSql::NumericalPrecisionPolicy | precisionPolicy | ) |
Sets the default numerical precision policy used by queries created on this database connection to precisionPolicy.
Note: Drivers that don't support fetching numerical values with low precision will ignore the precision policy. You can use QSqlDriver::hasFeature() to find out whether a driver supports this feature.
Note: Setting the default precision policy to precisionPolicy doesn't affect any currently active queries.
Definition at line 1326 of file qsqldatabase.cpp.
References driver(), QSqlDatabasePrivate::precisionPolicy, and QSqlDriver::setNumericalPrecisionPolicy().
Sets the connection's password to password.
To have effect, the password must be set {before} the connection is \l{open()} {opened}. Alternatively, you can close() the connection, set the password, and call open() again.
There is no default value.
Definition at line 911 of file qsqldatabase.cpp.
References isValid(), password(), and QSqlDatabasePrivate::pword.
void QSqlDatabase::setPort | ( | int | port | ) |
Sets the connection's port number to port.
To have effect, the port number must be set {before} the connection is \l{open()} {opened}. Alternatively, you can close() the connection, set the port number, and call open() again..
There is no default value.
Definition at line 947 of file qsqldatabase.cpp.
References isValid(), QSqlDatabasePrivate::port, and port().
Sets the connection's user name to name.
To have effect, the user name must be set {before} the connection is \l{open()} {opened}. Alternatively, you can close() the connection, set the user name, and call open() again.
There is no default value.
Definition at line 889 of file qsqldatabase.cpp.
References isValid(), and QSqlDatabasePrivate::uname.
Referenced by open().
QStringList QSqlDatabase::tables | ( | QSql::TableType | type = QSql::Tables | ) | const |
Returns a list of the database's tables, system tables and views, as specified by the parameter type.
Definition at line 1050 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::driver, and QSqlDriver::tables().
bool QSqlDatabase::transaction | ( | ) |
Begins a transaction on the database if the driver supports transactions.
Returns {true} if the operation succeeded. Otherwise it returns
{false}.
Definition at line 786 of file qsqldatabase.cpp.
References QSqlDriver::beginTransaction(), QSqlDatabasePrivate::driver, QSqlDriver::hasFeature(), and QSqlDriver::Transactions.
Referenced by sql_intro_snippets().
QString QSqlDatabase::userName | ( | ) | const |
Returns the connection's user name; it may be empty.
Definition at line 969 of file qsqldatabase.cpp.
References QSqlDatabasePrivate::uname.
|
friend |
Definition at line 103 of file qsqldatabase.h.
|
static |
Definition at line 81 of file qsqldatabase.h.
Referenced by qInit().