summaryrefslogtreecommitdiffstats
path: root/src/sql/kernel/qsqldatabase.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2025-01-26 10:04:21 -0800
committerThiago Macieira <thiago.macieira@intel.com>2025-02-07 18:46:38 -0800
commit16aae5a4b83517e302e5c14ce07c8f210b308ad8 (patch)
treedb0c2b2e923110e85e64ba3cc5fc0184eb4bcc28 /src/sql/kernel/qsqldatabase.h
parent03f6f176b1ef789ae8320da13a37d3590918694f (diff)
QSqlDatabase: fix historical mistake of defaultConnection being non-const
This was likely never intended, and was a mistake in the API design, missing the second const after the pointer. It should have been: static const char *const defaultConnection; This commit fixes that mistake by replacing the variable with a constexpr one that can't be modified. We can actually do better by moving the name to the header, so it will get emitted in each library, application, or plugin instead of trying to load from QtSql. [ChangeLog][Potentially Source-Incompatible Changes] The static QSqlDatabase::connectionName member variable has changed from a non-const pointer to a constexpr array. Modifying the pointer was most likely a mistake in code and would produce a misbehaving application. Change-Id: Icf2eddc865c2d6dde0c7fffda06e55e215e5f26d Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Diffstat (limited to 'src/sql/kernel/qsqldatabase.h')
-rw-r--r--src/sql/kernel/qsqldatabase.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/sql/kernel/qsqldatabase.h b/src/sql/kernel/qsqldatabase.h
index e1e5b631472..c2595ce658d 100644
--- a/src/sql/kernel/qsqldatabase.h
+++ b/src/sql/kernel/qsqldatabase.h
@@ -34,7 +34,13 @@ public:
QSqlDriver *createObject() const override { return new T; }
};
-class Q_SQL_EXPORT QSqlDatabase
+struct QSqlDatabaseDefaultConnectionName
+{
+ // separate class because of the static inline constexpr variable
+ static constexpr const char defaultConnection[] = "qt_sql_default_connection";
+};
+
+class Q_SQL_EXPORT QSqlDatabase : public QSqlDatabaseDefaultConnectionName
{
Q_GADGET
Q_PROPERTY(QSql::NumericalPrecisionPolicy numericalPrecisionPolicy READ numericalPrecisionPolicy WRITE setNumericalPrecisionPolicy)
@@ -87,7 +93,9 @@ public:
QSqlDriver* driver() const;
+#if QT_SQL_REMOVED_SINCE(6, 10)
static const char *defaultConnection;
+#endif
static QSqlDatabase addDatabase(const QString& type,
const QString& connectionName = QLatin1StringView(defaultConnection));