Skip to content

Commit

Permalink
removed deprecated up to Qt v6.9 (Qt::TimeSpec) πŸŽ‰
Browse files Browse the repository at this point in the history
 - removed using of QDateTime methods using plain Qt::TimeSpec
 - set QT_DISABLE_DEPRECATED_UP_TO to 0x060900 (also 0x061000 works)
 - maintained Qt v5 and <v6.5 code still 😬 (next step will be to drop
   Qt v5 πŸŽ‰)
 - updated auto tests
 - updated docs
 - updated comments

See:
qt/qtbase@8c8d6ff?diff=unified&w=0
  • Loading branch information
silverqx committed Jun 25, 2024
1 parent 318012f commit 1c2f17f
Show file tree
Hide file tree
Showing 35 changed files with 546 additions and 385 deletions.
7 changes: 5 additions & 2 deletions cmake/CommonModules/TinyCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ ${TINY_UNPARSED_ARGUMENTS}")
# Disable deprecated APIs up to the given Qt version
# TODO qt5 remove silverqx
if(QT_VERSION_MAJOR GREATER_EQUAL 6)
# Disable all the APIs deprecated up to Qt v6.7.0 (including)
target_compile_definitions(${target} INTERFACE QT_DISABLE_DEPRECATED_UP_TO=0x060700)
# Disable all the APIs deprecated up to Qt v6.9.0 (including)
target_compile_definitions(${target} INTERFACE QT_DISABLE_DEPRECATED_UP_TO=0x060900)
else()
# Disable all the APIs deprecated up to Qt v6.0.0 (including)
target_compile_definitions(${target} INTERFACE QT_DISABLE_DEPRECATED_BEFORE=0x060000)
endif()

target_compile_definitions(${target}
INTERFACE
#QT_NO_DEPRECATED_WARNINGS
#QT_WARN_DEPRECATED_UP_TO=0x060900

#QT_ASCII_CAST_WARNINGS
#QT_NO_CAST_FROM_ASCII
#QT_RESTRICTED_CAST_FROM_ASCII
Expand Down
6 changes: 3 additions & 3 deletions docs/building/migrations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ std::shared_ptr<DatabaseManager> setupDatabaseManager()
{collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)},
{timezone_, TZ00},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
the system local time. */
{qt_timezone, QVariant::fromValue(Qt::UTC)},
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
{strict_, true},
},
QStringLiteral("tinyorm_tom_mysql")); // shell:connection
Expand Down
52 changes: 28 additions & 24 deletions docs/database/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ auto manager = DB::create({
{"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_0900_ai_ci")},
{"timezone", "+00:00"},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
the system local time. */
{"qt_timezone", QVariant::fromValue(Qt::UTC)},
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{"qt_timezone", QVariant::fromValue(QTimeZone::UTC)},
{"prefix", ""},
{"prefix_indexes", false},
{"strict", true},
Expand Down Expand Up @@ -107,9 +107,9 @@ auto manager = DB::create({
{"charset", qEnvironmentVariable("DB_CHARSET", "utf8")},
{"timezone", "UTC"},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
the system local time. */
{"qt_timezone", QVariant::fromValue(Qt::UTC)},
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{"qt_timezone", QVariant::fromValue(QTimeZone::UTC)},
{"prefix", ""},
{"prefix_indexes", false},
{"options", QVariantHash()},
Expand All @@ -131,9 +131,9 @@ auto manager = DB::create({
{"foreign_key_constraints", qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},
{"check_database_exists", true},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
the system local time. */
{"qt_timezone", QVariant::fromValue(Qt::UTC)},
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{"qt_timezone", QVariant::fromValue(QTimeZone::UTC)},
/* Return a QDateTime/QDate with the correct time zone instead of the QString,
only works when the qt_timezone isn't set to the DontConvert. */
{"return_qdatetime", true},
Expand Down Expand Up @@ -162,9 +162,9 @@ auto manager = DB::create({
{"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_unicode_520_ci")},
{"timezone", "+00:00"},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
the system local time. */
{"qt_timezone", QVariant::fromValue(Qt::UTC)},
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{"qt_timezone", QVariant::fromValue(QTimeZone::UTC)},
{"prefix", ""},
{"prefix_indexes", false},
{"strict", true},
Expand Down Expand Up @@ -208,9 +208,9 @@ auto manager = DB::create({
// {options, ConfigUtils::mysqlSslOptions()},
{timezone_, TZ00},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
the system local time. */
{qt_timezone, QVariant::fromValue(Qt::UTC)},
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
{prefix_, EMPTY},
{prefix_indexes, false},
{strict_, true},
Expand Down Expand Up @@ -258,9 +258,9 @@ auto manager = DB::create({
// {options_, ConfigUtils::postgresSslOptions()},
{timezone_, UTC},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
the system local time. */
{qt_timezone, QVariant::fromValue(Qt::UTC)},
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
{prefix_, EMPTY},
{prefix_indexes, false},
// {isolation_level, QStringLiteral("REPEATABLE READ")}, // Postgres default is READ COMMITTED
Expand Down Expand Up @@ -291,9 +291,9 @@ auto manager = DB::create({
{foreign_key_constraints, qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},
{check_database_exists, true},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
the system local time. */
{qt_timezone, QVariant::fromValue(Qt::UTC)},
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
/* Return a QDateTime/QDate with the correct time zone instead of the QString,
only works when the qt_timezone isn't set to the DontConvert. */
{return_qdatetime, true},
Expand Down Expand Up @@ -333,9 +333,9 @@ auto manager = DB::create({
// {options, ConfigUtils::mariaSslOptions()},
{timezone_, TZ00},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use
the system local time. */
{qt_timezone, QVariant::fromValue(Qt::UTC)},
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{qt_timezone, QVariant::fromValue(QTimeZone::UTC)},
{prefix_, EMPTY},
{prefix_indexes, false},
{strict_, true},
Expand Down Expand Up @@ -372,6 +372,10 @@ A database connection is resolved lazily, which means that the connection config
You can also use predefined string constants to avoid unnecessary `QString` instantiations, as used in the `tom` migrations [example](building/migrations.mdx#string-constants-example).
:::

:::info
See [Date Casting, Serialization & Timezones](tinyorm/casts.mdx#date-casting-serialization-and-timezones) if you have problems with `qt_timezone` configuration option and `QTimeZone` value on older `Qt <6.5` versions.
:::

#### SQLite Configuration

SQLite databases are contained within a single file on your filesystem. You can create a new SQLite database using the `touch` command in your terminal: `touch database.sqlite3`. After the database has been created, you may configure SQLite database connection:
Expand Down
8 changes: 7 additions & 1 deletion docs/tinyorm/casts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,16 @@ inline static QString u_timeFormat {"HH:mm:ss.zzz"};
#### Date Casting, Serialization & Timezones {#date-casting-serialization-and-timezones}
By default, the `CastType::CustomQDate` and `CastType::CustomQDateTime` casts will serialize dates to a UTC ISO-8601 date string (`yyyy-MM-ddTHH:mm:ss.zzzZ`), regardless of the timezone specified in your database connection's `qt_timezone` configuration option. You are strongly encouraged to always use this serialization format, as well as to store your application's dates in the UTC timezone by not changing your database connection's `qt_timezone` configuration option from its default `Qt::UTC` value. Consistently using the UTC timezone throughout your application will provide the maximum level of interoperability with other date manipulation libraries or services written in any programming language.
By default, the `CastType::CustomQDate` and `CastType::CustomQDateTime` casts will serialize dates to a UTC ISO-8601 date string (`yyyy-MM-ddTHH:mm:ss.zzzZ`), regardless of the timezone specified in your database connection's `qt_timezone` configuration option. You are strongly encouraged to always use this serialization format, as well as to store your application's dates in the UTC timezone by not changing your database connection's `qt_timezone` configuration option from its default `QTimeZone::UTC` value. Consistently using the UTC timezone throughout your application will provide the maximum level of interoperability with other date manipulation libraries or services written in any programming language.
If a custom format is applied to the `CastType::CustomQDate` or `CastType::CustomQDateTime` cast types, such as `{CastType::CustomQDateTime, "yyyy-MM-dd HH:mm:ss"}`, the inner timezone of the QDateTime instance will be used during date serialization. Typically, this will be the timezone specified in your database connection's `qt_timezone` configuration option.
:::info
Passing the `Qt::TimeSpec` (eg. `Qt::UTC` or `Qt::LocalTime`) to `QDateTime` methods was deprecated in [`Qt >=6.5`](https://github.com/qt/qtbase/commit/8c8d6ff7b6e2e6b1b673051685f1499ae4d65e05?diff=unified&w=0), it was replaced by the `enum QTimeZone::Initialization` (`QTimeZone::UTC` and `QTimeZone::LocalTime`).
If you need to support older and newer versions of Qt at the same time, you can use the `Orm::QtTimeZoneConfig::utc()` or `QtTimeZoneConfig::localTime()` factory methods to create the `QtTimeZoneConfig` instance.
:::
### Query Time Casting
Sometimes you may need to apply casts while executing a query, such as when selecting a raw value from a table. For example, consider the following query:
Expand Down
2 changes: 1 addition & 1 deletion docs/tinyorm/collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Alternatively, you can use the `Orm::collect<Model>` helper function to create a
```cpp
ModelsCollection<User> users = Orm::collect<User>({
{{"name", "Kate"}, {"added_on", QDateTime::currentDateTimeUtc()}},
{{"name", "John"}, {"added_on", QDateTime({2023, 6, 1}, {13, 46, 15}, Qt::UTC)}},
{{"name", "John"}, {"added_on", QDateTime({2023, 6, 1}, {13, 46, 15}, QTimeZone::UTC)}},
});
```

Expand Down
31 changes: 16 additions & 15 deletions examples/tom/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

using Orm::DatabaseManager;
using Orm::DB;
using Orm::QtTimeZoneConfig;

using ConfigUtils = Orm::Utils::Configuration;

Expand Down Expand Up @@ -83,10 +84,10 @@ std::shared_ptr<DatabaseManager> setupDatabaseManager()
{collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)},
// SYSTEM - set the time zone to your local MySQL server time zone
{timezone_, TZ00},
/* Specifies what time zone all QDateTime-s will have, the overridden default
is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to
use the system local time. */
{qt_timezone, QVariant::fromValue(Qt::UTC)},
/* Specifies what time zone all QDateTime-s will have, the overridden default is
the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())},
{prefix_, EMPTY},
{prefix_indexes, false},
{strict_, true},
Expand All @@ -110,9 +111,9 @@ std::shared_ptr<DatabaseManager> setupDatabaseManager()
// SYSTEM - set the time zone to your local MySQL server time zone
{timezone_, TZ00},
/* Specifies what time zone all QDateTime-s will have, the overridden default
is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to
use the system local time. */
{qt_timezone, QVariant::fromValue(Qt::UTC)},
is the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())},
{prefix_, EMPTY},
{prefix_indexes, false},
{strict_, true},
Expand All @@ -137,17 +138,17 @@ std::shared_ptr<DatabaseManager> setupDatabaseManager()
// LOCAL/DEFAULT - set the time zone to your local PostgreSQL server time zone
{timezone_, UTC},
/* Specifies what time zone all QDateTime-s will have, the overridden default
is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to
use the system local time. */
{qt_timezone, QVariant::fromValue(Qt::UTC)},
is the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())},
// Examples of qt_timezone
// {qt_timezone, QVariant::fromValue(QTimeZone("Europe/Bratislava"))},
// {qt_timezone, "Europe/Prague"}, // Will be converted to QTimeZone("Europe/Prague")
// {qt_timezone, QVariant::fromValue(QTimeZone("UTC+04"))},
// {qt_timezone, "-03:00"},
// {qt_timezone, 3600}, // Offset from UTC
// {qt_timezone, QVariant::fromValue(Qt::LocalTime)},
// {qt_timezone, {}}, // The same as Qt::LocalTime
// {qt_timezone, QVariant::fromValue(QTimeZone::LocalTime)}, // To support Qt <v6.5 use Orm::QtTimeZoneConfig::utc/localTime()
// {qt_timezone, {}}, // The same as QTimeZone::UTC
{prefix_, EMPTY},
{prefix_indexes, false},
// {isolation_level, QStringLiteral("REPEATABLE READ")}, // Postgres default is READ COMMITTED
Expand All @@ -165,9 +166,9 @@ std::shared_ptr<DatabaseManager> setupDatabaseManager()
{foreign_key_constraints, true},
{check_database_exists, true},
/* Specifies what time zone all QDateTime-s will have, the overridden default
is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to
use the system local time. */
{qt_timezone, QVariant::fromValue(Qt::UTC)},
is the QTimeZone::UTC, set to the QTimeZone::LocalTime or
QtTimeZoneType::DontConvert to use the system local time. */
{qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())},
/* Return a QDateTime/QDate with the correct time zone instead of the QString,
only works when the qt_timezone isn't set to the DontConvert. */
{return_qdatetime, true},
Expand Down
2 changes: 1 addition & 1 deletion include/orm/connectors/connectionfactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace Connectors
createConnection(
const QString &driver, std::function<ConnectionName()> &&connection,
QString &&database, QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(),
QVariantHash &&config = {},
std::optional<bool> returnQDateTime = std::nullopt);

Expand Down
4 changes: 2 additions & 2 deletions include/orm/databaseconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ namespace Orm
explicit DatabaseConnection(
std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(),
QVariantHash &&config = {});
/*! Protected constructor for SQLite connection. */
explicit DatabaseConnection(
std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(),
std::optional<bool> returnQDateTime = true,
QVariantHash &&config = {});

Expand Down
4 changes: 2 additions & 2 deletions include/orm/mysqlconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Orm
explicit MySqlConnection(
std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(),
QVariantHash &&config = {});

public:
Expand All @@ -33,7 +33,7 @@ namespace Orm
std::shared_ptr<MySqlConnection>
create(std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(),
QVariantHash &&config = {});

/* Getters / Setters */
Expand Down
Loading

0 comments on commit 1c2f17f

Please sign in to comment.