12#include "QtCore/qapplicationstatic.h"
13#include "private/qfactoryloader_p.h"
14#include "private/qsqlnulldriver_p.h"
51 struct DriverDict :
public QHash<QString, QSqlDriverCreatorBase*>
91 static DriverDict &driverDict();
92 static void cleanConnections();
123 while (
it != dict->
end()) {
130DriverDict::~DriverDict()
138 return *qtDriverDict();
150 if (
db.d->ref.loadRelaxed() != 1 && doWarn) {
151 qWarning(
"QSqlDatabasePrivate::removeDatabase: connection '%s' is still in use, "
152 "all queries will cease to work.",
name.toLocal8Bit().constData());
154 db.d->connName.clear();
178 qWarning(
"QSqlDatabasePrivate::addDatabase: duplicate connection name '%s', old "
179 "connection removed.",
name.toLocal8Bit().data());
196 qWarning(
"QSqlDatabasePrivate::database: requested database does not belong to the calling thread.");
200 if (
open && !
db.isOpen()) {
202 qWarning() <<
"QSqlDatabasePrivate::database: unable to open database:" <<
db.lastError().text();
498 const PluginKeyMap
keyMap = fl->keyMap();
507 for (
const auto &[k, _] : dict.asKeyValueRange()) {
559 return dbDict()->keys_ts();
648 for (DriverDict::const_iterator
it = dict.constBegin();
660 qWarning(
"QSqlDatabase: %s driver not loaded",
type.toLatin1().data());
661 qWarning(
"QSqlDatabase: available drivers: %s",
664 qWarning(
"QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins");
695#if QT_DEPRECATED_SINCE(6, 6)
699 if (!
query.isEmpty()) {
1262 if (!
other.isValid())
1350#ifndef QT_NO_DEBUG_STREAM
1357 dbg <<
"QSqlDatabase(invalid)";
1361 dbg <<
"QSqlDatabase(driver=\"" <<
d.driverName() <<
"\", database=\""
1362 <<
d.databaseName() <<
"\", host=\"" <<
d.hostName() <<
"\", port=" <<
d.port()
1363 <<
", user=\"" <<
d.userName() <<
"\", open=" <<
d.isOpen() <<
')';
QStringList keys_ts() const
bool contains_ts(const QString &key) const
QSqlDatabase value_ts(const QString &key) const
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it.
QList< QString > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
bool contains(const QString &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
static QSqlDatabasePrivate * shared_null()
void init(const QString &type)
static DriverDict & driverDict()
QSqlDatabasePrivate(QSqlDriver *dr)
static QSqlDatabase database(const QString &name, bool open)
static void cleanConnections()
static void removeDatabase(const QString &name)
static void invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn=true)
QSql::NumericalPrecisionPolicy precisionPolicy
static void addDatabase(const QSqlDatabase &db, const QString &name)
void copy(const QSqlDatabasePrivate *other)
The QSqlDatabase class handles a connection to a database.
bool isValid() const
Returns true if the QSqlDatabase has a valid driver.
void close()
Closes the database connection, freeing any resources acquired, and invalidating any existing QSqlQue...
static bool contains(const QString &connectionName=QLatin1StringView(defaultConnection))
\threadsafe
QString driverName() const
Returns the connection's driver name.
int port() const
Returns the connection's port number.
bool open()
Executes a SQL statement on the database and returns a QSqlQuery object.
QSqlIndex primaryIndex(const QString &tablename) const
Returns the primary index for table tablename.
void setDatabaseName(const QString &name)
Sets the connection's database name to name.
QString connectionName() const
static QStringList connectionNames()
\threadsafe
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const
QSqlDriver * driver() const
Returns the database driver used to access the database connection.
QString hostName() const
Returns the connection's host name; it may be empty.
bool isOpen() const
Returns true if the database connection is currently open; otherwise returns false.
QString connectOptions() const
Returns the connection options string used for this connection.
bool transaction()
Begins a transaction on the database if the driver supports transactions.
static const char * defaultConnection
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy)
QString password() const
Returns the connection's password.
QSqlRecord record(const QString &tablename) const
Returns a QSqlRecord populated with the names of all the fields in the table (or view) called tablena...
static void removeDatabase(const QString &connectionName)
\threadsafe
QSqlDatabase & operator=(const QSqlDatabase &other)
Assigns other to this object.
static QSqlDatabase addDatabase(const QString &type, const QString &connectionName=QLatin1StringView(defaultConnection))
\threadsafe
void setPassword(const QString &password)
Sets the connection's password to password.
bool rollback()
Rolls back a transaction on the database, if the driver supports transactions and a transaction() has...
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.
bool isOpenError() const
Returns true if there was an error opening the database connection; otherwise returns false.
QSqlDatabase()
Creates an empty, invalid QSqlDatabase object.
static QSqlDatabase database(const QString &connectionName=QLatin1StringView(defaultConnection), bool open=true)
\threadsafe
bool commit()
Commits a transaction to the database if the driver supports transactions and a transaction() has bee...
static QSqlDatabase cloneDatabase(const QSqlDatabase &other, const QString &connectionName)
Clones the database connection other and stores it as connectionName.
void setUserName(const QString &name)
Sets the connection's user name to name.
QString userName() const
Returns the connection's user name; it may be empty.
static bool isDriverAvailable(const QString &name)
Returns true if a driver called name is available; otherwise returns false.
static void registerSqlDriver(const QString &name, QSqlDriverCreatorBase *creator)
[2]
void setConnectOptions(const QString &options=QString())
Sets database-specific options.
QString databaseName() const
Returns the connection's database name, which may be empty.
QSqlError lastError() const
Returns information about the last error that occurred on the database.
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.
static QStringList drivers()
Returns a list of all the available database drivers.
~QSqlDatabase()
Destroys the object and frees any allocated resources.
The QSqlDriverCreatorBase class is the base class for SQL driver factories.
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
virtual bool commitTransaction()
This function is called to commit a transaction.
virtual QSqlResult * createResult() const =0
Creates an empty SQL result on the database.
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy)
virtual QSqlIndex primaryIndex(const QString &tableName) const
Returns the primary index for table tableName.
virtual bool beginTransaction()
This function is called to begin a transaction.
QSqlError lastError() const
Returns a QSqlError object which contains information about the last error that occurred on the datab...
virtual QSqlRecord record(const QString &tableName) const
Returns a QSqlRecord populated with the names of the fields in table tableName.
virtual bool rollbackTransaction()
This function is called to rollback a transaction.
virtual void close()=0
Derived classes must reimplement this pure virtual function in order to close the database connection...
bool isOpenError() const
Returns true if the there was an error opening the database connection; otherwise returns false.
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const
virtual void setLastError(const QSqlError &e)
This function is used to set the value of the last error, error, that occurred on the database.
virtual bool open(const QString &db, const QString &user=QString(), const QString &password=QString(), const QString &host=QString(), int port=-1, const QString &connOpts=QString())=0
Derived classes must reimplement this pure virtual function to open a database connection on database...
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
virtual bool hasFeature(DriverFeature f) const =0
Returns true if the driver supports feature feature; otherwise returns false.
virtual QStringList tables(QSql::TableType tableType) const
Returns a list of the names of the tables in the database.
The QSqlError class provides SQL database error information.
The QSqlIndex class provides functions to manipulate and describe database indexes.
The QSqlQuery class provides a means of executing and manipulating SQL statements.
The QSqlRecord class encapsulates a database record.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QThread * currentThread()
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
#define Q_APPLICATION_STATIC(TYPE, NAME,...)
QT_WARNING_POP void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
QDebug operator<<(QDebug dbg, const QSqlDatabase &d)
#define QSqlDriverFactoryInterface_iid
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
static const struct @437 keyMap[]
file open(QIODevice::ReadOnly)
QItemEditorCreatorBase * creator
bool contains(const AT &t) const noexcept