diff --git a/include/orm/query/concerns/buildsqueries.hpp b/include/orm/query/concerns/buildsqueries.hpp index 52b49318b..0deec4bb5 100644 --- a/include/orm/query/concerns/buildsqueries.hpp +++ b/include/orm/query/concerns/buildsqueries.hpp @@ -34,23 +34,24 @@ namespace Orm::Query::Concerns BuildsQueries &operator=(BuildsQueries &&) = delete; /*! Chunk the results of the query. */ - bool chunk(int count, - const std::function &callback); + bool chunk(qint64 count, + const std::function &callback); /*! Execute a callback over each item while chunking. */ - bool each(const std::function &callback, - int count = 1000); + bool each(const std::function &callback, + qint64 count = 1000); /*! Run a map over each item while chunking. */ // QVector -// chunkMap(const std::function &callback, int count = 1000); +// chunkMap(const std::function &callback, qint64 count = 1000); /*! Chunk the results of a query by comparing IDs. */ - bool chunkById(int count, - const std::function &callback, + bool chunkById(qint64 count, + const std::function< + bool(SqlQuery &results, qint64 page)> &callback, const QString &column = "", const QString &alias = ""); /*! Execute a callback over each item while chunking by ID. */ - bool eachById(const std::function &callback, - int count = 1000, const QString &column = "", + bool eachById(const std::function &callback, + qint64 count = 1000, const QString &column = "", const QString &alias = ""); diff --git a/include/orm/query/querybuilder.hpp b/include/orm/query/querybuilder.hpp index 495d18443..545f2ebfa 100644 --- a/include/orm/query/querybuilder.hpp +++ b/include/orm/query/querybuilder.hpp @@ -670,22 +670,22 @@ namespace Orm::Query Builder &reorder(const Column &column, const QString &direction = ASC); /*! Set the "limit" value of the query. */ - Builder &limit(int value); + Builder &limit(qint64 value); /*! Alias to set the "limit" value of the query. */ - Builder &take(int value); + Builder &take(qint64 value); /*! Set the "offset" value of the query. */ - Builder &offset(int value); + Builder &offset(qint64 value); /*! Alias to set the "offset" value of the query. */ - Builder &skip(int value); + Builder &skip(qint64 value); /*! Set the limit and offset for a given page. */ - Builder &forPage(int page, int perPage = 30); + Builder &forPage(qint64 page, qint64 perPage = 30); /*! Constrain the query to the previous "page" of results before a given ID. */ - Builder &forPageBeforeId(int perPage = 30, const QVariant &lastId = {}, + Builder &forPageBeforeId(qint64 perPage = 30, const QVariant &lastId = {}, const QString &column = Orm::Constants::ID, bool prependOrder = false); /*! Constrain the query to the next "page" of results after a given ID. */ - Builder &forPageAfterId(int perPage = 30, const QVariant &lastId = {}, + Builder &forPageAfterId(qint64 perPage = 30, const QVariant &lastId = {}, const QString &column = Orm::Constants::ID, bool prependOrder = false); @@ -784,9 +784,9 @@ namespace Orm::Query /*! Get the orderings for the query. */ inline const QVector &getOrders() const noexcept; /*! Get the maximum number of records to return. */ - inline int getLimit() const noexcept; + inline qint64 getLimit() const noexcept; /*! Get the number of records to skip. */ - inline int getOffset() const noexcept; + inline qint64 getOffset() const noexcept; /*! Get the row locking. */ inline const std::variant & getLock() const noexcept; @@ -984,9 +984,9 @@ namespace Orm::Query /*! The orderings for the query. */ QVector m_orders {}; /*! The maximum number of records to return. */ - int m_limit = -1; + qint64 m_limit = -1; /*! The number of records to skip. */ - int m_offset = -1; + qint64 m_offset = -1; /*! Indicates whether row locking is being used. */ std::variant m_lock {}; }; @@ -1756,12 +1756,12 @@ namespace Orm::Query return m_orders; } - int Builder::getLimit() const noexcept + qint64 Builder::getLimit() const noexcept { return m_limit; } - int Builder::getOffset() const noexcept + qint64 Builder::getOffset() const noexcept { return m_offset; } diff --git a/include/orm/tiny/concerns/buildsqueries.hpp b/include/orm/tiny/concerns/buildsqueries.hpp index 0b4064240..3bf6dbde9 100644 --- a/include/orm/tiny/concerns/buildsqueries.hpp +++ b/include/orm/tiny/concerns/buildsqueries.hpp @@ -44,29 +44,30 @@ namespace Concerns BuildsQueries &operator=(BuildsQueries &&) = delete; /*! Chunk the results of the query. */ - bool chunk(int count, + bool chunk(qint64 count, const std::function< - bool(ModelsCollection &&models, int page)> &callback); + bool(ModelsCollection &&models, qint64 page)> &callback); /*! Execute a callback over each item while chunking. */ - bool each(const std::function &callback, - int count = 1000); + bool each(const std::function &callback, + qint64 count = 1000); /*! Run a map over each item while chunking. */ ModelsCollection - chunkMap(const std::function &callback, int count = 1000); + chunkMap(const std::function &callback, + qint64 count = 1000); /*! Run a map over each item while chunking. */ template QVector - chunkMap(const std::function &callback, int count = 1000); + chunkMap(const std::function &callback, qint64 count = 1000); /*! Chunk the results of a query by comparing IDs. */ - bool chunkById(int count, + bool chunkById(qint64 count, const std::function< - bool(ModelsCollection &&models, int page)> &callback, + bool(ModelsCollection &&models, qint64 page)> &callback, const QString &column = "", const QString &alias = ""); /*! Execute a callback over each item while chunking by ID. */ - bool eachById(const std::function &callback, - int count = 1000, const QString &column = "", + bool eachById(const std::function &callback, + qint64 count = 1000, const QString &column = "", const QString &alias = ""); /*! Execute the query and get the first result if it's the sole matching @@ -103,13 +104,13 @@ namespace Concerns template bool BuildsQueries::chunk( - const int count, - const std::function &&, int)> &callback) + const qint64 count, + const std::function &&, qint64)> &callback) { builder().enforceOrderBy(); - int page = 1; - int countModels = 0; + qint64 page = 1; + qint64 countModels = 0; do { // NOLINT(cppcoreguidelines-avoid-do-while) /* We'll execute the query for the given page and get the results. If there @@ -117,7 +118,7 @@ namespace Concerns we will call the callback with the current chunk of these results. */ auto models = builder().forPage(page, count).get(); - countModels = models.size(); + countModels = static_cast(models.size()); if (countModels == 0) break; @@ -139,13 +140,13 @@ namespace Concerns } template - bool BuildsQueries::each(const std::function &callback, - const int count) + bool BuildsQueries::each(const std::function &callback, + const qint64 count) { return chunk(count, [&callback] - (ModelsCollection &&models, const int /*unused*/) + (ModelsCollection &&models, const qint64 /*unused*/) { - int index = 0; + qint64 index = 0; for (auto &&model : models) if (const auto result = std::invoke(callback, std::move(model), index++); @@ -160,14 +161,14 @@ namespace Concerns template ModelsCollection BuildsQueries::chunkMap(const std::function &callback, - const int count) + const qint64 count) { ModelsCollection result; // Reserve the first page, it can help reallocations at the beginning result.reserve(static_cast::size_type>(count)); chunk(count, [&result, &callback] - (ModelsCollection &&models, const int /*unused*/) + (ModelsCollection &&models, const qint64 /*unused*/) { for (auto &&model : models) result << std::invoke(callback, std::move(model)); @@ -182,14 +183,14 @@ namespace Concerns template QVector BuildsQueries::chunkMap(const std::function &callback, - const int count) + const qint64 count) { QVector result; // Reserve the first page, it can help reallocations at the beginning result.reserve(static_cast::size_type>(count)); chunk(count, [&result, &callback] - (ModelsCollection &&models, const int /*unused*/) + (ModelsCollection &&models, const qint64 /*unused*/) { for (auto &&model : models) result << std::invoke(callback, std::move(model)); @@ -202,15 +203,15 @@ namespace Concerns template bool BuildsQueries::chunkById( - const int count, - const std::function &&, int)> &callback, + const qint64 count, + const std::function &&, qint64)> &callback, const QString &column, const QString &alias) { const auto columnName = column.isEmpty() ? builder().defaultKeyName() : column; const auto aliasName = alias.isEmpty() ? columnName : alias; - int page = 1; - int countModels = 0; + qint64 page = 1; + qint64 countModels = 0; QVariant lastId; @@ -222,7 +223,7 @@ namespace Concerns we will call the callback with the current chunk of these results. */ auto models = clone.forPageAfterId(count, lastId, columnName, true).get(); - countModels = models.size(); + countModels = static_cast(models.size()); if (countModels == 0) break; @@ -259,13 +260,13 @@ namespace Concerns template bool BuildsQueries::eachById( - const std::function &callback, - const int count, const QString &column, const QString &alias) + const std::function &callback, + const qint64 count, const QString &column, const QString &alias) { return chunkById(count, [&callback, count] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { - int index = 0; + qint64 index = 0; for (auto &&model : models) if (const auto result = std::invoke(callback, std::move(model), diff --git a/include/orm/tiny/modelproxies.hpp b/include/orm/tiny/modelproxies.hpp index f3d4fa8ee..4a3b0875b 100644 --- a/include/orm/tiny/modelproxies.hpp +++ b/include/orm/tiny/modelproxies.hpp @@ -810,28 +810,28 @@ namespace Tiny /*! Set the "limit" value of the query. */ static std::unique_ptr> - limit(int value); + limit(qint64 value); /*! Alias to set the "limit" value of the query. */ static std::unique_ptr> - take(int value); + take(qint64 value); /*! Set the "offset" value of the query. */ static std::unique_ptr> - offset(int value); + offset(qint64 value); /*! Alias to set the "offset" value of the query. */ static std::unique_ptr> - skip(int value); + skip(qint64 value); /*! Set the limit and offset for a given page. */ static std::unique_ptr> - forPage(int page, int perPage = 30); + forPage(qint64 page, qint64 perPage = 30); /*! Constrain the query to the previous "page" of results before a given ID. */ static std::unique_ptr> - forPageBeforeId(int perPage = 30, const QVariant &lastId = {}, + forPageBeforeId(qint64 perPage = 30, const QVariant &lastId = {}, const QString &column = Orm::Constants::ID, bool prependOrder = false); /*! Constrain the query to the next "page" of results after a given ID. */ static std::unique_ptr> - forPageAfterId(int perPage = 30, const QVariant &lastId = {}, + forPageAfterId(qint64 perPage = 30, const QVariant &lastId = {}, const QString &column = Orm::Constants::ID, bool prependOrder = false); @@ -858,33 +858,33 @@ namespace Tiny /* Builds Queries */ /*! Chunk the results of the query. */ static bool - chunk(int count, + chunk(qint64 count, const std::function< - bool(ModelsCollection &&models, int page)> &callback); + bool(ModelsCollection &&models, qint64 page)> &callback); /*! Execute a callback over each item while chunking. */ static bool - each(const std::function &callback, - int count = 1000); + each(const std::function &callback, + qint64 count = 1000); /*! Run a map over each item while chunking. */ static ModelsCollection chunkMap(const std::function &callback, - int count = 1000); + qint64 count = 1000); /*! Run a map over each item while chunking. */ template static QVector - chunkMap(const std::function &callback, int count = 1000); + chunkMap(const std::function &callback, qint64 count = 1000); /*! Chunk the results of a query by comparing IDs. */ static bool - chunkById(int count, + chunkById(qint64 count, const std::function< - bool(ModelsCollection &&models, int page)> &callback, + bool(ModelsCollection &&models, qint64 page)> &callback, const QString &column = "", const QString &alias = ""); /*! Execute a callback over each item while chunking by ID. */ static bool - eachById(const std::function &callback, - int count = 1000, const QString &column = "", + eachById(const std::function &callback, + qint64 count = 1000, const QString &column = "", const QString &alias = ""); /*! Execute the query and get the first result if it's the sole matching @@ -3177,7 +3177,7 @@ namespace Tiny template std::unique_ptr> - ModelProxies::limit(const int value) + ModelProxies::limit(const qint64 value) { auto builder = query(); @@ -3188,7 +3188,7 @@ namespace Tiny template std::unique_ptr> - ModelProxies::take(const int value) + ModelProxies::take(const qint64 value) { auto builder = query(); @@ -3199,7 +3199,7 @@ namespace Tiny template std::unique_ptr> - ModelProxies::offset(const int value) + ModelProxies::offset(const qint64 value) { auto builder = query(); @@ -3210,7 +3210,7 @@ namespace Tiny template std::unique_ptr> - ModelProxies::skip(const int value) + ModelProxies::skip(const qint64 value) { auto builder = query(); @@ -3221,7 +3221,8 @@ namespace Tiny template std::unique_ptr> - ModelProxies::forPage(const int page, const int perPage) + ModelProxies::forPage(const qint64 page, + const qint64 perPage) { auto builder = query(); @@ -3233,7 +3234,7 @@ namespace Tiny template std::unique_ptr> ModelProxies::forPageBeforeId( - const int perPage, const QVariant &lastId, const QString &column, + const qint64 perPage, const QVariant &lastId, const QString &column, const bool prependOrder) { auto builder = query(); @@ -3246,7 +3247,7 @@ namespace Tiny template std::unique_ptr> ModelProxies::forPageAfterId( - const int perPage, const QVariant &lastId, const QString &column, + const qint64 perPage, const QVariant &lastId, const QString &column, const bool prependOrder) { auto builder = query(); @@ -3328,15 +3329,15 @@ namespace Tiny template bool ModelProxies::chunk( - const int count, - const std::function &&, int)> &callback) + const qint64 count, + const std::function &&, qint64)> &callback) { return query()->chunk(count, callback); } template bool ModelProxies::each( - const std::function &callback, const int count) + const std::function &callback, const qint64 count) { return query()->each(callback, count); } @@ -3344,7 +3345,7 @@ namespace Tiny template ModelsCollection ModelProxies::chunkMap( - const std::function &callback, const int count) + const std::function &callback, const qint64 count) { return query()->chunkMap(callback, count); } @@ -3353,15 +3354,15 @@ namespace Tiny template QVector ModelProxies::chunkMap( - const std::function &callback, const int count) + const std::function &callback, const qint64 count) { return query()->template chunkMap(callback, count); } template bool ModelProxies::chunkById( - const int count, - const std::function &&, int)> &callback, + const qint64 count, + const std::function &&, qint64)> &callback, const QString &column, const QString &alias) { return query()->chunkById(count, callback, column, alias); @@ -3369,8 +3370,8 @@ namespace Tiny template bool ModelProxies::eachById( - const std::function &callback, - const int count, const QString &column, const QString &alias) + const std::function &callback, + const qint64 count, const QString &column, const QString &alias) { return query()->eachById(callback, count, column, alias); } diff --git a/include/orm/tiny/relations/belongstomany.hpp b/include/orm/tiny/relations/belongstomany.hpp index 40cd086c4..d166ad798 100644 --- a/include/orm/tiny/relations/belongstomany.hpp +++ b/include/orm/tiny/relations/belongstomany.hpp @@ -219,33 +219,34 @@ namespace Orm::Tiny::Relations /* Builds Queries */ /*! Chunk the results of the query. */ - bool chunk(int count, + bool chunk(qint64 count, const std::function< - bool(ModelsCollection &&models, int page)> &callback + bool(ModelsCollection &&models, qint64 page)> &callback ) const override; /*! Execute a callback over each item while chunking. */ - bool each(const std::function &callback, - int count = 1000) const override; + bool each(const std::function &callback, + qint64 count = 1000) const override; /*! Run a map over each item while chunking. */ ModelsCollection chunkMap(const std::function &callback, - int count = 1000) const override; + qint64 count = 1000) const override; /*! Run a map over each item while chunking. */ template QVector chunkMap(const std::function &callback, - int count = 1000) const; + qint64 count = 1000) const; /*! Chunk the results of a query by comparing IDs. */ - bool chunkById(int count, - const std::function< - bool(ModelsCollection &&models, int page)> &callback, - const QString &column = "", - const QString &alias = "") const override; + bool + chunkById(qint64 count, + const std::function< + bool(ModelsCollection &&models, qint64 page)> &callback, + const QString &column = "", + const QString &alias = "") const override; /*! Execute a callback over each item while chunking by ID. */ - bool eachById(const std::function &callback, - int count = 1000, const QString &column = "", + bool eachById(const std::function &callback, + qint64 count = 1000, const QString &column = "", const QString &alias = "") const override; /* Inserting/Updating operations on the relationship */ @@ -953,12 +954,13 @@ namespace Orm::Tiny::Relations template bool BelongsToMany::chunk( - const int count, - const std::function &&, int)> &callback) const + const qint64 count, + const std::function< + bool(ModelsCollection &&, qint64)> &callback) const { return prepareQueryBuilder() .chunk(count, [this, &callback] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { hydratePivotRelation(models); @@ -968,12 +970,13 @@ namespace Orm::Tiny::Relations template bool BelongsToMany::each( - const std::function &callback, const int count) const + const std::function &callback, + const qint64 count) const { return chunk(count, [&callback] - (ModelsCollection &&models, const int /*unused*/) + (ModelsCollection &&models, const qint64 /*unused*/) { - int index = 0; + qint64 index = 0; for (auto &&model : models) if (const auto result = std::invoke(callback, std::move(model), index++); @@ -988,14 +991,14 @@ namespace Orm::Tiny::Relations template ModelsCollection BelongsToMany::chunkMap( - const std::function &callback, const int count) const + const std::function &callback, const qint64 count) const { ModelsCollection result; // Reserve the first page, it can help reallocations at the beginning result.reserve(static_cast::size_type>(count)); chunk(count, [&result, &callback] - (ModelsCollection &&models, const int /*unused*/) + (ModelsCollection &&models, const qint64 /*unused*/) { for (auto &&model : models) result << std::invoke(callback, std::move(model)); @@ -1010,14 +1013,14 @@ namespace Orm::Tiny::Relations template QVector BelongsToMany::chunkMap( - const std::function &callback, const int count) const + const std::function &callback, const qint64 count) const { QVector result; // Reserve the first page, it can help reallocations at the beginning result.reserve(static_cast::size_type>(count)); chunk(count, [&result, &callback] - (ModelsCollection &&models, const int /*unused*/) + (ModelsCollection &&models, const qint64 /*unused*/) { for (auto &&model : models) result << std::invoke(callback, std::move(model)); @@ -1030,8 +1033,8 @@ namespace Orm::Tiny::Relations template bool BelongsToMany::chunkById( - const int count, - const std::function &&, int)> &callback, + const qint64 count, + const std::function &&, qint64)> &callback, const QString &column, const QString &alias) const { const auto &relatedKeyName = this->getRelatedKeyName(); @@ -1043,7 +1046,7 @@ namespace Orm::Tiny::Relations return prepareQueryBuilder() .chunkById(count, [this, &callback] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { hydratePivotRelation(models); @@ -1054,13 +1057,13 @@ namespace Orm::Tiny::Relations template bool BelongsToMany::eachById( - const std::function &callback, - const int count, const QString &column, const QString &alias) const + const std::function &callback, + const qint64 count, const QString &column, const QString &alias) const { return chunkById(count, [&callback, count] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { - int index = 0; + qint64 index = 0; for (auto &&model : models) if (const auto result = std::invoke(callback, std::move(model), diff --git a/include/orm/tiny/relations/relationproxies.hpp b/include/orm/tiny/relations/relationproxies.hpp index 768c245bb..151ac2a47 100644 --- a/include/orm/tiny/relations/relationproxies.hpp +++ b/include/orm/tiny/relations/relationproxies.hpp @@ -795,24 +795,24 @@ namespace Tiny::Relations const Column &column, const QString &direction = ASC) const; /*! Set the "limit" value of the query. */ - const Relation &limit(int value) const; + const Relation &limit(qint64 value) const; /*! Alias to set the "limit" value of the query. */ - const Relation &take(int value) const; + const Relation &take(qint64 value) const; /*! Set the "offset" value of the query. */ - const Relation &offset(int value) const; + const Relation &offset(qint64 value) const; /*! Alias to set the "offset" value of the query. */ - const Relation &skip(int value) const; + const Relation &skip(qint64 value) const; /*! Set the limit and offset for a given page. */ - const Relation &forPage(int page, int perPage = 30) const; + const Relation &forPage(qint64 page, qint64 perPage = 30) const; /*! Constrain the query to the previous "page" of results before a given ID. */ const Relation & - forPageBeforeId(int perPage = 30, const QVariant &lastId = {}, + forPageBeforeId(qint64 perPage = 30, const QVariant &lastId = {}, const QString &column = Orm::Constants::ID, bool prependOrder = false) const; /*! Constrain the query to the next "page" of results after a given ID. */ const Relation & - forPageAfterId(int perPage = 30, const QVariant &lastId = {}, + forPageAfterId(qint64 perPage = 30, const QVariant &lastId = {}, const QString &column = Orm::Constants::ID, bool prependOrder = false) const; @@ -851,34 +851,34 @@ namespace Tiny::Relations /* Builds Queries */ /*! Chunk the results of the query. */ virtual bool - chunk(int count, + chunk(qint64 count, const std::function< - bool(ModelsCollection &&models, int page)> &callback) const; + bool(ModelsCollection &&models, qint64 page)> &callback) const; /*! Execute a callback over each item while chunking. */ virtual bool - each(const std::function &callback, - int count = 1000) const; + each(const std::function &callback, + qint64 count = 1000) const; /*! Run a map over each item while chunking. */ virtual ModelsCollection chunkMap(const std::function &callback, - int count = 1000) const; + qint64 count = 1000) const; /*! Run a map over each item while chunking. */ template QVector chunkMap(const std::function &callback, - int count = 1000) const; + qint64 count = 1000) const; /*! Chunk the results of a query by comparing IDs. */ virtual bool - chunkById(int count, + chunkById(qint64 count, const std::function< - bool(ModelsCollection &&models, int page)> &callback, + bool(ModelsCollection &&models, qint64 page)> &callback, const QString &column = "", const QString &alias = "") const; /*! Execute a callback over each item while chunking by ID. */ virtual bool - eachById(const std::function &callback, - int count = 1000, const QString &column = "", + eachById(const std::function &callback, + qint64 count = 1000, const QString &column = "", const QString &alias = "") const; /*! Execute the query and get the first result if it's the sole matching @@ -2932,7 +2932,7 @@ namespace Tiny::Relations template const Relation & - RelationProxies::limit(const int value) const + RelationProxies::limit(const qint64 value) const { getQuery().limit(value); @@ -2941,7 +2941,7 @@ namespace Tiny::Relations template const Relation & - RelationProxies::take(const int value) const + RelationProxies::take(const qint64 value) const { getQuery().take(value); @@ -2950,7 +2950,7 @@ namespace Tiny::Relations template const Relation & - RelationProxies::offset(const int value) const + RelationProxies::offset(const qint64 value) const { getQuery().offset(value); @@ -2959,7 +2959,7 @@ namespace Tiny::Relations template const Relation & - RelationProxies::skip(const int value) const + RelationProxies::skip(const qint64 value) const { getQuery().skip(value); @@ -2968,7 +2968,8 @@ namespace Tiny::Relations template const Relation & - RelationProxies::forPage(const int page, const int perPage) const + RelationProxies::forPage(const qint64 page, + const qint64 perPage) const { getQuery().forPage(page, perPage); @@ -2978,7 +2979,7 @@ namespace Tiny::Relations template const Relation & RelationProxies::forPageBeforeId( - const int perPage, const QVariant &lastId, const QString &column, + const qint64 perPage, const QVariant &lastId, const QString &column, const bool prependOrder) const { getQuery().forPageBeforeId(perPage, lastId, column, prependOrder); @@ -2989,7 +2990,7 @@ namespace Tiny::Relations template const Relation & RelationProxies::forPageAfterId( - const int perPage, const QVariant &lastId, const QString &column, + const qint64 perPage, const QVariant &lastId, const QString &column, const bool prependOrder) const { getQuery().forPageAfterId(perPage, lastId, column, prependOrder); @@ -3092,15 +3093,17 @@ namespace Tiny::Relations /* Builds Queries */ template bool RelationProxies::chunk( - const int count, - const std::function &&, int)> &callback) const + const qint64 count, + const std::function< + bool(ModelsCollection &&, qint64)> &callback) const { return getQuery().chunk(count, callback); } template bool RelationProxies::each( - const std::function &callback, const int count) const + const std::function &callback, + const qint64 count) const { return getQuery().each(callback, count); } @@ -3108,7 +3111,7 @@ namespace Tiny::Relations template ModelsCollection RelationProxies::chunkMap( - const std::function &callback, const int count) const + const std::function &callback, const qint64 count) const { return getQuery().chunkMap(callback, count); } @@ -3117,15 +3120,15 @@ namespace Tiny::Relations template QVector RelationProxies::chunkMap( - const std::function &callback, const int count) const + const std::function &callback, const qint64 count) const { return getQuery().template chunkMap(callback, count); } template bool RelationProxies::chunkById( - const int count, - const std::function &&, int)> &callback, + const qint64 count, + const std::function &&, qint64)> &callback, const QString &column, const QString &alias) const { return getQuery().chunkById(count, callback, column, alias); @@ -3133,8 +3136,8 @@ namespace Tiny::Relations template bool RelationProxies::eachById( - const std::function &callback, - const int count, const QString &column, const QString &alias) const + const std::function &callback, + const qint64 count, const QString &column, const QString &alias) const { return getQuery().eachById(callback, count, column, alias); } diff --git a/include/orm/tiny/tinybuilderproxies.hpp b/include/orm/tiny/tinybuilderproxies.hpp index 6746b8321..e74c9634e 100644 --- a/include/orm/tiny/tinybuilderproxies.hpp +++ b/include/orm/tiny/tinybuilderproxies.hpp @@ -637,24 +637,24 @@ namespace Tiny const QString &direction = ASC); /*! Set the "limit" value of the query. */ - TinyBuilder &limit(int value); + TinyBuilder &limit(qint64 value); /*! Alias to set the "limit" value of the query. */ - TinyBuilder &take(int value); + TinyBuilder &take(qint64 value); /*! Set the "offset" value of the query. */ - TinyBuilder &offset(int value); + TinyBuilder &offset(qint64 value); /*! Alias to set the "offset" value of the query. */ - TinyBuilder &skip(int value); + TinyBuilder &skip(qint64 value); /*! Set the limit and offset for a given page. */ - TinyBuilder &forPage(int page, int perPage = 30); + TinyBuilder &forPage(qint64 page, qint64 perPage = 30); /*! Constrain the query to the previous "page" of results before a given ID. */ TinyBuilder & - forPageBeforeId(int perPage = 30, const QVariant &lastId = {}, + forPageBeforeId(qint64 perPage = 30, const QVariant &lastId = {}, const QString &column = Orm::Constants::ID, bool prependOrder = false); /*! Constrain the query to the next "page" of results after a given ID. */ TinyBuilder & - forPageAfterId(int perPage = 30, const QVariant &lastId = {}, + forPageAfterId(qint64 perPage = 30, const QVariant &lastId = {}, const QString &column = Orm::Constants::ID, bool prependOrder = false); @@ -2147,7 +2147,7 @@ namespace Tiny template TinyBuilder & - BuilderProxies::limit(const int value) + BuilderProxies::limit(const qint64 value) { getQuery().limit(value); return builder(); @@ -2155,14 +2155,14 @@ namespace Tiny template TinyBuilder & - BuilderProxies::take(const int value) + BuilderProxies::take(const qint64 value) { return limit(value); } template TinyBuilder & - BuilderProxies::offset(const int value) + BuilderProxies::offset(const qint64 value) { getQuery().offset(value); return builder(); @@ -2170,14 +2170,14 @@ namespace Tiny template TinyBuilder & - BuilderProxies::skip(const int value) + BuilderProxies::skip(const qint64 value) { return offset(value); } template TinyBuilder & - BuilderProxies::forPage(const int page, const int perPage) + BuilderProxies::forPage(const qint64 page, const qint64 perPage) { getQuery().forPage(page, perPage); return builder(); @@ -2185,7 +2185,7 @@ namespace Tiny template TinyBuilder & - BuilderProxies::forPageBeforeId(const int perPage, const QVariant &lastId, + BuilderProxies::forPageBeforeId(const qint64 perPage, const QVariant &lastId, const QString &column, const bool prependOrder) { getQuery().forPageBeforeId(perPage, lastId, column, prependOrder); @@ -2194,7 +2194,7 @@ namespace Tiny template TinyBuilder & - BuilderProxies::forPageAfterId(const int perPage, const QVariant &lastId, + BuilderProxies::forPageAfterId(const qint64 perPage, const QVariant &lastId, const QString &column, const bool prependOrder) { getQuery().forPageAfterId(perPage, lastId, column, prependOrder); diff --git a/src/orm/query/concerns/buildsqueries.cpp b/src/orm/query/concerns/buildsqueries.cpp index 5858bbe60..01a061907 100644 --- a/src/orm/query/concerns/buildsqueries.cpp +++ b/src/orm/query/concerns/buildsqueries.cpp @@ -15,13 +15,13 @@ namespace Orm::Query::Concerns /* public */ -bool BuildsQueries::chunk(const int count, - const std::function &callback) +bool BuildsQueries::chunk(const qint64 count, + const std::function &callback) { builder().enforceOrderBy(); - int page = 1; - int countResults = 0; + qint64 page = 1; + qint64 countResults = 0; do { // NOLINT(cppcoreguidelines-avoid-do-while) /* We'll execute the query for the given page and get the results. If there are @@ -29,7 +29,7 @@ bool BuildsQueries::chunk(const int count, we will call the callback with the current chunk of these results here. */ auto results = builder().forPage(page, count).get(); - countResults = QueryUtils::queryResultSize(results); + countResults = static_cast(QueryUtils::queryResultSize(results)); if (countResults == 0) break; @@ -49,12 +49,12 @@ bool BuildsQueries::chunk(const int count, return true; } -bool BuildsQueries::each(const std::function &callback, - const int count) +bool BuildsQueries::each(const std::function &callback, + const qint64 count) { - return chunk(count, [&callback](SqlQuery &results, const int /*unused*/) + return chunk(count, [&callback](SqlQuery &results, const qint64 /*unused*/) { - int index = 0; + qint64 index = 0; while (results.next()) if (const auto result = std::invoke(callback, results, index++); @@ -69,7 +69,7 @@ bool BuildsQueries::each(const std::function &callback, /* This is trash as the QSqlQuery is passed to the callback, I need to pass something like std::map, QVariant> so an user can modify it and return */ //QVector -//BuildsQueries::chunkMap(const std::function &callback, const int count) +//BuildsQueries::chunkMap(const std::function &callback, const qint64 count) //{ // /* This method is weird, it should return one merged collection with all rows, but // it's impossible to merge more QSqlQuery-ies into the one QSqlQuery, so I have @@ -83,7 +83,7 @@ bool BuildsQueries::each(const std::function &callback, // processed/looped then move a whole QSqlQuery into the result vector. */ // QVector result; -// chunk(count, [&result, &callback](QSqlQuery &results, const int /*unused*/) +// chunk(count, [&result, &callback](QSqlQuery &results, const qint64 /*unused*/) // { // while (results.next()) // std::invoke(callback, results); @@ -97,14 +97,14 @@ bool BuildsQueries::each(const std::function &callback, //} bool BuildsQueries::chunkById( - const int count, const std::function &callback, + const qint64 count, const std::function &callback, const QString &column, const QString &alias) { const auto columnName = column.isEmpty() ? builder().defaultKeyName() : column; const auto aliasName = alias.isEmpty() ? columnName : alias; - int page = 1; - int countResults = 0; + qint64 page = 1; + qint64 countResults = 0; QVariant lastId; @@ -116,7 +116,7 @@ bool BuildsQueries::chunkById( we will call the callback with the current chunk of these results here. */ auto results = clone.forPageAfterId(count, lastId, columnName, true).get(); - countResults = QueryUtils::queryResultSize(results); + countResults = static_cast(QueryUtils::queryResultSize(results)); if (countResults == 0) break; @@ -153,12 +153,12 @@ bool BuildsQueries::chunkById( } bool BuildsQueries::eachById( - const std::function &callback, - const int count, const QString &column, const QString &alias) + const std::function &callback, + const qint64 count, const QString &column, const QString &alias) { - return chunkById(count, [&callback, count](SqlQuery &results, const int page) + return chunkById(count, [&callback, count](SqlQuery &results, const qint64 page) { - int index = 0; + qint64 index = 0; while (results.next()) if (const auto result = std::invoke(callback, results, diff --git a/src/orm/query/querybuilder.cpp b/src/orm/query/querybuilder.cpp index 8858e9039..5db307c3d 100644 --- a/src/orm/query/querybuilder.cpp +++ b/src/orm/query/querybuilder.cpp @@ -1067,7 +1067,7 @@ Builder &Builder::reorder(const Column &column, const QString &direction) return orderBy(column, direction); } -Builder &Builder::limit(const int value) +Builder &Builder::limit(const qint64 value) { /* I checked negative limit/offset, MySQL and PostgreSQL throws an error, SQLite accepts a negative value, but it has no effect and Microsoft SQL Server @@ -1081,12 +1081,12 @@ Builder &Builder::limit(const int value) return *this; } -Builder &Builder::take(const int value) +Builder &Builder::take(const qint64 value) { return limit(value); } -Builder &Builder::offset(const int value) +Builder &Builder::offset(const qint64 value) { Q_ASSERT(value >= 0); @@ -1095,18 +1095,18 @@ Builder &Builder::offset(const int value) return *this; } -Builder &Builder::skip(const int value) +Builder &Builder::skip(const qint64 value) { return offset(value); } -Builder &Builder::forPage(const int page, const int perPage) +Builder &Builder::forPage(const qint64 page, const qint64 perPage) { return offset((page - 1) * perPage).limit(perPage); } // NOTE api little different, added bool prependOrder parameter silverqx -Builder &Builder::forPageBeforeId(const int perPage, const QVariant &lastId, +Builder &Builder::forPageBeforeId(const qint64 perPage, const QVariant &lastId, const QString &column, const bool prependOrder) { m_orders = removeExistingOrdersFor(column); @@ -1123,7 +1123,7 @@ Builder &Builder::forPageBeforeId(const int perPage, const QVariant &lastId, } // NOTE api little different, added bool prependOrder parameter silverqx -Builder &Builder::forPageAfterId(const int perPage, const QVariant &lastId, +Builder &Builder::forPageAfterId(const qint64 perPage, const QVariant &lastId, const QString &column, const bool prependOrder) { m_orders = removeExistingOrdersFor(column); diff --git a/tests/auto/functional/orm/query/querybuilder/tst_querybuilder.cpp b/tests/auto/functional/orm/query/querybuilder/tst_querybuilder.cpp index 63e24fdd3..00fc5c946 100644 --- a/tests/auto/functional/orm/query/querybuilder/tst_querybuilder.cpp +++ b/tests/auto/functional/orm/query/querybuilder/tst_querybuilder.cpp @@ -1635,13 +1635,14 @@ void tst_QueryBuilder::chunk() const QFETCH_GLOBAL(QString, connection); // - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page) + const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page) { - QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page)); + QCOMPARE(static_cast(QueryUtils::queryResultSize(query)), + expectedRows.at(page)); }; std::vector ids; @@ -1649,7 +1650,8 @@ void tst_QueryBuilder::chunk() const auto result = createQuery(connection)->from("file_property_properties") .orderBy(ID) - .chunk(3, [&compareResultSize, &ids](SqlQuery &query, const int page) + .chunk(3, [&compareResultSize, &ids] + (SqlQuery &query, const qint64 page) { compareResultSize(query, page); @@ -1672,13 +1674,14 @@ void tst_QueryBuilder::chunk_ReturnFalse() const QFETCH_GLOBAL(QString, connection); // (I leave it here also in this test, doesn't matter much - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page) + const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page) { - QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page)); + QCOMPARE(static_cast(QueryUtils::queryResultSize(query)), + expectedRows.at(page)); }; std::vector ids; @@ -1686,7 +1689,8 @@ void tst_QueryBuilder::chunk_ReturnFalse() const auto result = createQuery(connection)->from("file_property_properties") .orderBy(ID) - .chunk(3, [&compareResultSize, &ids](SqlQuery &query, const int page) + .chunk(3, [&compareResultSize, &ids] + (SqlQuery &query, const qint64 page) { compareResultSize(query, page); @@ -1715,11 +1719,11 @@ void tst_QueryBuilder::chunk_EnforceOrderBy() const QFETCH_GLOBAL(QString, connection); QVERIFY_EXCEPTION_THROWN(createQuery(connection)->from("file_property_properties") - .chunk(3, [](SqlQuery &/*unused*/, const int /*unused*/) + .chunk(3, [](SqlQuery &/*unused*/, const qint64 /*unused*/) { return true; }), - RuntimeError); + RuntimeError); } void tst_QueryBuilder::chunk_EmptyResult() const @@ -1732,7 +1736,7 @@ void tst_QueryBuilder::chunk_EmptyResult() const .whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .chunk(3, [&callbackInvoked] - (SqlQuery &/*unused*/, const int /*unused*/) + (SqlQuery &/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; @@ -1747,14 +1751,14 @@ void tst_QueryBuilder::each() const { QFETCH_GLOBAL(QString, connection); - std::vector indexes; + std::vector indexes; indexes.reserve(8); std::vector ids; ids.reserve(8); auto result = createQuery(connection)->from("file_property_properties") .orderBy(ID) - .each([&indexes, &ids](SqlQuery &query, const int index) + .each([&indexes, &ids](SqlQuery &query, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(query.value(ID).value()); @@ -1764,7 +1768,7 @@ void tst_QueryBuilder::each() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; + std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; std::vector expectedIds {1, 2, 3, 4, 5, 6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -1777,14 +1781,14 @@ void tst_QueryBuilder::each_ReturnFalse() const { QFETCH_GLOBAL(QString, connection); - std::vector indexes; + std::vector indexes; indexes.reserve(5); std::vector ids; ids.reserve(5); auto result = createQuery(connection)->from("file_property_properties") .orderBy(ID) - .each([&indexes, &ids](SqlQuery &query, const int index) + .each([&indexes, &ids](SqlQuery &query, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(query.value(ID).value()); @@ -1794,7 +1798,7 @@ void tst_QueryBuilder::each_ReturnFalse() const QVERIFY(!result); - std::vector expectedIndexes {0, 1, 2, 3, 4}; + std::vector expectedIndexes {0, 1, 2, 3, 4}; std::vector expectedIds {1, 2, 3, 4, 5}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -1808,11 +1812,11 @@ void tst_QueryBuilder::each_EnforceOrderBy() const QFETCH_GLOBAL(QString, connection); QVERIFY_EXCEPTION_THROWN(createQuery(connection)->from("file_property_properties") - .each([](SqlQuery &/*unused*/, const int /*unused*/) + .each([](SqlQuery &/*unused*/, const qint64 /*unused*/) { return true; }), - RuntimeError); + RuntimeError); } void tst_QueryBuilder::each_EmptyResult() const @@ -1825,7 +1829,7 @@ void tst_QueryBuilder::each_EmptyResult() const .whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .each([&callbackInvoked] - (SqlQuery &/*unused*/, const int /*unused*/) + (SqlQuery &/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; @@ -1841,13 +1845,14 @@ void tst_QueryBuilder::chunkById() const QFETCH_GLOBAL(QString, connection); // - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page) + const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page) { - QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page)); + QCOMPARE(static_cast(QueryUtils::queryResultSize(query)), + expectedRows.at(page)); }; std::vector ids; @@ -1856,7 +1861,7 @@ void tst_QueryBuilder::chunkById() const auto result = createQuery(connection)->from("file_property_properties") .orderBy(ID) .chunkById(3, [&compareResultSize, &ids] - (SqlQuery &query, const int page) + (SqlQuery &query, const qint64 page) { compareResultSize(query, page); @@ -1879,13 +1884,14 @@ void tst_QueryBuilder::chunkById_ReturnFalse() const QFETCH_GLOBAL(QString, connection); // (I leave it here also in this test, doesn't matter much - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page) + const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page) { - QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page)); + QCOMPARE(static_cast(QueryUtils::queryResultSize(query)), + expectedRows.at(page)); }; std::vector ids; @@ -1894,7 +1900,7 @@ void tst_QueryBuilder::chunkById_ReturnFalse() const auto result = createQuery(connection)->from("file_property_properties") .orderBy(ID) .chunkById(3, [&compareResultSize, &ids] - (SqlQuery &query, const int page) + (SqlQuery &query, const qint64 page) { compareResultSize(query, page); @@ -1928,7 +1934,7 @@ void tst_QueryBuilder::chunkById_EmptyResult() const .whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .chunkById(3, [&callbackInvoked] - (SqlQuery &/*unused*/, const int /*unused*/) + (SqlQuery &/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; @@ -1944,13 +1950,14 @@ void tst_QueryBuilder::chunkById_WithAlias() const QFETCH_GLOBAL(QString, connection); // - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page) + const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page) { - QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page)); + QCOMPARE(static_cast(QueryUtils::queryResultSize(query)), + expectedRows.at(page)); }; std::vector ids; @@ -1960,7 +1967,7 @@ void tst_QueryBuilder::chunkById_WithAlias() const .select({ASTERISK, "id as id_as"}) .orderBy(ID) .chunkById(3, [&compareResultSize, &ids] - (SqlQuery &query, const int page) + (SqlQuery &query, const qint64 page) { compareResultSize(query, page); @@ -1969,7 +1976,7 @@ void tst_QueryBuilder::chunkById_WithAlias() const return true; }, - ID, "id_as"); + ID, "id_as"); QVERIFY(result); @@ -1984,13 +1991,14 @@ void tst_QueryBuilder::chunkById_ReturnFalse_WithAlias() const QFETCH_GLOBAL(QString, connection); // (I leave it here also in this test, doesn't matter much - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](SqlQuery &query, const int page) + const auto compareResultSize = [&expectedRows](SqlQuery &query, const qint64 page) { - QCOMPARE(QueryUtils::queryResultSize(query), expectedRows.at(page)); + QCOMPARE(static_cast(QueryUtils::queryResultSize(query)), + expectedRows.at(page)); }; std::vector ids; @@ -2000,7 +2008,7 @@ void tst_QueryBuilder::chunkById_ReturnFalse_WithAlias() const .select({ASTERISK, "id as id_as"}) .orderBy(ID) .chunkById(3, [&compareResultSize, &ids] - (SqlQuery &query, const int page) + (SqlQuery &query, const qint64 page) { compareResultSize(query, page); @@ -2015,7 +2023,7 @@ void tst_QueryBuilder::chunkById_ReturnFalse_WithAlias() const return true; }, - ID, "id_as"); + ID, "id_as"); QVERIFY(!result); @@ -2036,13 +2044,13 @@ void tst_QueryBuilder::chunkById_EmptyResult_WithAlias() const .whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .chunkById(3, [&callbackInvoked] - (SqlQuery &/*unused*/, const int /*unused*/) + (SqlQuery &/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; return true; }, - ID, "id_as"); + ID, "id_as"); QVERIFY(!callbackInvoked); QVERIFY(result); @@ -2052,14 +2060,14 @@ void tst_QueryBuilder::eachById() const { QFETCH_GLOBAL(QString, connection); - std::vector indexes; + std::vector indexes; indexes.reserve(8); std::vector ids; ids.reserve(8); auto result = createQuery(connection)->from("file_property_properties") .orderBy(ID) - .eachById([&indexes, &ids](SqlQuery &query, const int index) + .eachById([&indexes, &ids](SqlQuery &query, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(query.value(ID).value()); @@ -2069,7 +2077,7 @@ void tst_QueryBuilder::eachById() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; + std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; std::vector expectedIds {1, 2, 3, 4, 5, 6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2082,14 +2090,14 @@ void tst_QueryBuilder::eachById_ReturnFalse() const { QFETCH_GLOBAL(QString, connection); - std::vector indexes; + std::vector indexes; indexes.reserve(5); std::vector ids; ids.reserve(5); auto result = createQuery(connection)->from("file_property_properties") .orderBy(ID) - .eachById([&indexes, &ids](SqlQuery &query, const int index) + .eachById([&indexes, &ids](SqlQuery &query, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(query.value(ID).value()); @@ -2099,7 +2107,7 @@ void tst_QueryBuilder::eachById_ReturnFalse() const QVERIFY(!result); - std::vector expectedIndexes {0, 1, 2, 3, 4}; + std::vector expectedIndexes {0, 1, 2, 3, 4}; std::vector expectedIds {1, 2, 3, 4, 5}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2118,7 +2126,7 @@ void tst_QueryBuilder::eachById_EmptyResult() const .whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .eachById([&callbackInvoked] - (SqlQuery &/*unused*/, const int /*unused*/) + (SqlQuery &/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; @@ -2133,7 +2141,7 @@ void tst_QueryBuilder::eachById_WithAlias() const { QFETCH_GLOBAL(QString, connection); - std::vector indexes; + std::vector indexes; indexes.reserve(8); std::vector ids; ids.reserve(8); @@ -2141,18 +2149,18 @@ void tst_QueryBuilder::eachById_WithAlias() const auto result = createQuery(connection)->from("file_property_properties") .select({ASTERISK, "id as id_as"}) .orderBy(ID) - .eachById([&indexes, &ids](SqlQuery &query, const int index) + .eachById([&indexes, &ids](SqlQuery &query, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(query.value(ID).value()); return true; }, - 1000, ID, "id_as"); + 1000, ID, "id_as"); QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; + std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; std::vector expectedIds {1, 2, 3, 4, 5, 6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2165,7 +2173,7 @@ void tst_QueryBuilder::eachById_ReturnFalse_WithAlias() const { QFETCH_GLOBAL(QString, connection); - std::vector indexes; + std::vector indexes; indexes.reserve(5); std::vector ids; ids.reserve(5); @@ -2173,18 +2181,18 @@ void tst_QueryBuilder::eachById_ReturnFalse_WithAlias() const auto result = createQuery(connection)->from("file_property_properties") .select({ASTERISK, "id as id_as"}) .orderBy(ID) - .eachById([&indexes, &ids](SqlQuery &query, const int index) + .eachById([&indexes, &ids](SqlQuery &query, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(query.value(ID).value()); return index != 4; // false/interrupt on 4 }, - 1000, ID, "id_as"); + 1000, ID, "id_as"); QVERIFY(!result); - std::vector expectedIndexes {0, 1, 2, 3, 4}; + std::vector expectedIndexes {0, 1, 2, 3, 4}; std::vector expectedIds {1, 2, 3, 4, 5}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2204,13 +2212,13 @@ void tst_QueryBuilder::eachById_EmptyResult_WithAlias() const .whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .eachById([&callbackInvoked] - (SqlQuery &/*unused*/, const int /*unused*/) + (SqlQuery &/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; return true; }, - 1000, ID, "id_as"); + 1000, ID, "id_as"); QVERIFY(!callbackInvoked); QVERIFY(result); diff --git a/tests/auto/functional/orm/tiny/model_conn_indep/tst_model_connection_independent.cpp b/tests/auto/functional/orm/tiny/model_conn_indep/tst_model_connection_independent.cpp index 2aaf2f623..d4a33cddf 100644 --- a/tests/auto/functional/orm/tiny/model_conn_indep/tst_model_connection_independent.cpp +++ b/tests/auto/functional/orm/tiny/model_conn_indep/tst_model_connection_independent.cpp @@ -1304,13 +1304,14 @@ void tst_Model_Connection_Independent::chunk() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -1319,7 +1320,7 @@ void tst_Model_Connection_Independent::chunk() const auto result = FilePropertyProperty::orderBy(ID) ->chunk(3, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -1342,13 +1343,14 @@ void tst_Model_Connection_Independent::chunk_ReturnFalse() const using SizeType = ModelsCollection::size_type; // (I leave it here also in this test, doesn't matter much) - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -1357,7 +1359,7 @@ void tst_Model_Connection_Independent::chunk_ReturnFalse() const auto result = FilePropertyProperty::orderBy(ID) ->chunk(3, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -1389,13 +1391,14 @@ void tst_Model_Connection_Independent::chunk_EnforceOrderBy() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -1404,7 +1407,7 @@ void tst_Model_Connection_Independent::chunk_EnforceOrderBy() const auto result = FilePropertyProperty::chunk( 3, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -1431,7 +1434,7 @@ void tst_Model_Connection_Independent::chunk_EmptyResult() const ->orderBy(ID) .chunk(3, [&callbackInvoked] (ModelsCollection &&/*unused*/, - const int /*unused*/) + const qint64 /*unused*/) { callbackInvoked = true; @@ -1444,14 +1447,14 @@ void tst_Model_Connection_Independent::chunk_EmptyResult() const void tst_Model_Connection_Independent::each() const { - std::vector indexes; + std::vector indexes; indexes.reserve(8); std::vector ids; ids.reserve(8); auto result = FilePropertyProperty::orderBy(ID) ->each([&indexes, &ids] - (FilePropertyProperty &&model, const int index) + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).template value()); @@ -1461,7 +1464,7 @@ void tst_Model_Connection_Independent::each() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; + std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; std::vector expectedIds {1, 2, 3, 4, 5, 6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -1472,13 +1475,14 @@ void tst_Model_Connection_Independent::each() const void tst_Model_Connection_Independent::each_ReturnFalse() const { - std::vector indexes; + std::vector indexes; indexes.reserve(5); std::vector ids; ids.reserve(5); auto result = FilePropertyProperty::orderBy(ID) - ->each([&indexes, &ids](FilePropertyProperty &&model, const int index) + ->each([&indexes, &ids] + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).template value()); @@ -1488,7 +1492,7 @@ void tst_Model_Connection_Independent::each_ReturnFalse() const QVERIFY(!result); - std::vector expectedIndexes {0, 1, 2, 3, 4}; + std::vector expectedIndexes {0, 1, 2, 3, 4}; std::vector expectedIds {1, 2, 3, 4, 5}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -1502,13 +1506,14 @@ void tst_Model_Connection_Independent::each_EnforceOrderBy() const /* The TinBuilder version doesn't throws exception if the 'order by' clause is not specified, instead it adds a generic 'order by' clause on the Model::getQualifiedKeyName() (it sorts by the primary key by default). */ - std::vector indexes; + std::vector indexes; indexes.reserve(8); std::vector ids; ids.reserve(8); auto result = FilePropertyProperty::each( - [&indexes, &ids](FilePropertyProperty &&model, const int index) + [&indexes, &ids] + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).template value()); @@ -1518,7 +1523,7 @@ void tst_Model_Connection_Independent::each_EnforceOrderBy() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; + std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; std::vector expectedIds {1, 2, 3, 4, 5, 6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -1535,7 +1540,7 @@ void tst_Model_Connection_Independent::each_EmptyResult() const QStringLiteral("dummy-NON_EXISTENT")) ->orderBy(ID) .each([&callbackInvoked] - (FilePropertyProperty &&/*unused*/, const int /*unused*/) + (FilePropertyProperty &&/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; @@ -1739,13 +1744,14 @@ void tst_Model_Connection_Independent::chunkById() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -1754,7 +1760,7 @@ void tst_Model_Connection_Independent::chunkById() const auto result = FilePropertyProperty::orderBy(ID) ->chunkById(3, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -1777,13 +1783,14 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse() const using SizeType = ModelsCollection::size_type; // (I leave it here also in this test, doesn't matter much - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -1792,7 +1799,7 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse() const auto result = FilePropertyProperty::orderBy(ID) ->chunkById(3, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -1825,7 +1832,7 @@ void tst_Model_Connection_Independent::chunkById_EmptyResult() const ->orderBy(ID) .chunkById(3, [&callbackInvoked] (ModelsCollection &&/*unused*/, - const int /*unused*/) + const qint64 /*unused*/) { callbackInvoked = true; @@ -1841,13 +1848,14 @@ void tst_Model_Connection_Independent::chunkById_WithAlias() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -1857,7 +1865,7 @@ void tst_Model_Connection_Independent::chunkById_WithAlias() const ->orderBy(ID) .chunkById(3, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -1866,7 +1874,7 @@ void tst_Model_Connection_Independent::chunkById_WithAlias() const return true; }, - ID, "id_as"); + ID, "id_as"); QVERIFY(result); @@ -1881,13 +1889,14 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse_WithAlias() const using SizeType = ModelsCollection::size_type; // (I leave it here also in this test, doesn't matter much - const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; + const std::unordered_map expectedRows {{1, 3}, {2, 3}, {3, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -1897,7 +1906,7 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse_WithAlias() const ->orderBy(ID) .chunkById(3, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -1912,7 +1921,7 @@ void tst_Model_Connection_Independent::chunkById_ReturnFalse_WithAlias() const return true; }, - ID, "id_as"); + ID, "id_as"); QVERIFY(!result); @@ -1931,13 +1940,13 @@ void tst_Model_Connection_Independent::chunkById_EmptyResult_WithAlias() const .orderBy(ID) .chunkById(3, [&callbackInvoked] (ModelsCollection &&/*unused*/, - const int /*unused*/) + const qint64 /*unused*/) { callbackInvoked = true; return true; }, - ID, "id_as"); + ID, "id_as"); QVERIFY(!callbackInvoked); QVERIFY(result); @@ -1945,14 +1954,14 @@ void tst_Model_Connection_Independent::chunkById_EmptyResult_WithAlias() const void tst_Model_Connection_Independent::eachById() const { - std::vector indexes; + std::vector indexes; indexes.reserve(8); std::vector ids; ids.reserve(8); auto result = FilePropertyProperty::orderBy(ID) ->eachById([&indexes, &ids] - (FilePropertyProperty &&model, const int index) + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); @@ -1962,7 +1971,7 @@ void tst_Model_Connection_Independent::eachById() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; + std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; std::vector expectedIds {1, 2, 3, 4, 5, 6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -1973,14 +1982,14 @@ void tst_Model_Connection_Independent::eachById() const void tst_Model_Connection_Independent::eachById_ReturnFalse() const { - std::vector indexes; + std::vector indexes; indexes.reserve(5); std::vector ids; ids.reserve(5); auto result = FilePropertyProperty::orderBy(ID) ->eachById([&indexes, &ids] - (FilePropertyProperty &&model, const int index) + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); @@ -1990,7 +1999,7 @@ void tst_Model_Connection_Independent::eachById_ReturnFalse() const QVERIFY(!result); - std::vector expectedIndexes {0, 1, 2, 3, 4}; + std::vector expectedIndexes {0, 1, 2, 3, 4}; std::vector expectedIds {1, 2, 3, 4, 5}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2007,7 +2016,7 @@ void tst_Model_Connection_Independent::eachById_EmptyResult() const QStringLiteral("dummy-NON_EXISTENT")) ->orderBy(ID) .eachById([&callbackInvoked] - (FilePropertyProperty &&/*unused*/, const int /*unused*/) + (FilePropertyProperty &&/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; @@ -2020,7 +2029,7 @@ void tst_Model_Connection_Independent::eachById_EmptyResult() const void tst_Model_Connection_Independent::eachById_WithAlias() const { - std::vector indexes; + std::vector indexes; indexes.reserve(8); std::vector ids; ids.reserve(8); @@ -2028,18 +2037,18 @@ void tst_Model_Connection_Independent::eachById_WithAlias() const auto result = FilePropertyProperty::select({ASTERISK, "id as id_as"}) ->orderBy(ID) .eachById([&indexes, &ids] - (FilePropertyProperty &&model, const int index) + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); return true; }, - 1000, ID, "id_as"); + 1000, ID, "id_as"); QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; + std::vector expectedIndexes {0, 1, 2, 3, 4, 5, 6, 7}; std::vector expectedIds {1, 2, 3, 4, 5, 6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2050,7 +2059,7 @@ void tst_Model_Connection_Independent::eachById_WithAlias() const void tst_Model_Connection_Independent::eachById_ReturnFalse_WithAlias() const { - std::vector indexes; + std::vector indexes; indexes.reserve(5); std::vector ids; ids.reserve(5); @@ -2058,18 +2067,18 @@ void tst_Model_Connection_Independent::eachById_ReturnFalse_WithAlias() const auto result = FilePropertyProperty::select({ASTERISK, "id as id_as"}) ->orderBy(ID) .eachById([&indexes, &ids] - (FilePropertyProperty &&model, const int index) + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); return index != 4; // false/interrupt on 4 }, - 1000, ID, "id_as"); + 1000, ID, "id_as"); QVERIFY(!result); - std::vector expectedIndexes {0, 1, 2, 3, 4}; + std::vector expectedIndexes {0, 1, 2, 3, 4}; std::vector expectedIds {1, 2, 3, 4, 5}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2086,13 +2095,13 @@ void tst_Model_Connection_Independent::eachById_EmptyResult_WithAlias() const ->whereEq(NAME, QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .eachById([&callbackInvoked] - (FilePropertyProperty &&/*unused*/, const int /*unused*/) + (FilePropertyProperty &&/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; return true; }, - 1000, ID, "id_as"); + 1000, ID, "id_as"); QVERIFY(!callbackInvoked); QVERIFY(result); diff --git a/tests/auto/functional/orm/tiny/model_relations/tst_model_relations.cpp b/tests/auto/functional/orm/tiny/model_relations/tst_model_relations.cpp index 3fc7a2b48..fe942aceb 100644 --- a/tests/auto/functional/orm/tiny/model_relations/tst_model_relations.cpp +++ b/tests/auto/functional/orm/tiny/model_relations/tst_model_relations.cpp @@ -2317,13 +2317,14 @@ void tst_Model_Relations::chunk_Relation() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 2}, {2, 1}}; + const std::unordered_map expectedRows {{1, 2}, {2, 1}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -2333,7 +2334,7 @@ void tst_Model_Relations::chunk_Relation() const ->orderBy(ID) .chunk(2, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -2357,7 +2358,7 @@ void tst_Model_Relations::each_Relation() const ConnectionOverride::connection = connection; - std::vector indexes; + std::vector indexes; indexes.reserve(3); std::vector ids; ids.reserve(3); @@ -2365,7 +2366,7 @@ void tst_Model_Relations::each_Relation() const auto result = TorrentPreviewableFileProperty::find(5)->filePropertyProperty() ->orderBy(ID) .each([&indexes, &ids] - (FilePropertyProperty &&model, const int index) + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).template value()); @@ -2375,7 +2376,7 @@ void tst_Model_Relations::each_Relation() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2}; + std::vector expectedIndexes {0, 1, 2}; std::vector expectedIds {6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2473,13 +2474,14 @@ void tst_Model_Relations::chunkById_Relation() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 2}, {2, 1}}; + const std::unordered_map expectedRows {{1, 2}, {2, 1}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -2489,7 +2491,7 @@ void tst_Model_Relations::chunkById_Relation() const ->orderBy(ID) .chunkById(2, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -2516,13 +2518,14 @@ void tst_Model_Relations::chunkById_WithAlias_Relation() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 2}, {2, 1}}; + const std::unordered_map expectedRows {{1, 2}, {2, 1}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -2533,7 +2536,7 @@ void tst_Model_Relations::chunkById_WithAlias_Relation() const .orderBy(ID) .chunkById(2, [&compareResultSize, &ids] (ModelsCollection &&models, - const int page) + const qint64 page) { compareResultSize(models.size(), page); @@ -2558,7 +2561,7 @@ void tst_Model_Relations::eachById_Relation() const ConnectionOverride::connection = connection; - std::vector indexes; + std::vector indexes; indexes.reserve(3); std::vector ids; ids.reserve(3); @@ -2566,7 +2569,7 @@ void tst_Model_Relations::eachById_Relation() const auto result = TorrentPreviewableFileProperty::find(5)->filePropertyProperty() ->orderBy(ID) .eachById([&indexes, &ids] - (FilePropertyProperty &&model, const int index) + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); @@ -2576,7 +2579,7 @@ void tst_Model_Relations::eachById_Relation() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2}; + std::vector expectedIndexes {0, 1, 2}; std::vector expectedIds {6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2591,7 +2594,7 @@ void tst_Model_Relations::eachById_WithAlias_Relation() const ConnectionOverride::connection = connection; - std::vector indexes; + std::vector indexes; indexes.reserve(3); std::vector ids; ids.reserve(3); @@ -2600,7 +2603,7 @@ void tst_Model_Relations::eachById_WithAlias_Relation() const ->select({ASTERISK, "id as id_as"}) .orderBy(ID) .eachById([&indexes, &ids] - (FilePropertyProperty &&model, const int index) + (FilePropertyProperty &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); @@ -2611,7 +2614,7 @@ void tst_Model_Relations::eachById_WithAlias_Relation() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2}; + std::vector expectedIndexes {0, 1, 2}; std::vector expectedIds {6, 7, 8}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -2867,13 +2870,14 @@ void tst_Model_Relations::chunk() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 2}, {2, 2}}; + const std::unordered_map expectedRows {{1, 2}, {2, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -2881,7 +2885,7 @@ void tst_Model_Relations::chunk() const auto result = Torrent::find(2)->tags()->orderBy(ID) .chunk(2, [&compareResultSize, &ids] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { compareResultSize(models.size(), page); @@ -2911,13 +2915,14 @@ void tst_Model_Relations::chunk_ReturnFalse() const using SizeType = ModelsCollection::size_type; // (I leave it here also in this test, doesn't matter much) - const std::unordered_map expectedRows {{1, 2}, {2, 2}}; + const std::unordered_map expectedRows {{1, 2}, {2, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -2925,7 +2930,7 @@ void tst_Model_Relations::chunk_ReturnFalse() const auto result = Torrent::find(2)->tags()->orderBy(ID) .chunk(2, [&compareResultSize, &ids] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { compareResultSize(models.size(), page); @@ -2963,13 +2968,14 @@ void tst_Model_Relations::chunk_EnforceOrderBy() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 2}, {2, 2}}; + const std::unordered_map expectedRows {{1, 2}, {2, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -2977,7 +2983,7 @@ void tst_Model_Relations::chunk_EnforceOrderBy() const auto result = Torrent::find(2)->tags() ->chunk(2, [&compareResultSize, &ids] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { compareResultSize(models.size(), page); @@ -3010,7 +3016,7 @@ void tst_Model_Relations::chunk_EmptyResult() const QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .chunk(2, [&callbackInvoked] - (ModelsCollection &&/*unused*/, const int /*unused*/) + (ModelsCollection &&/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; @@ -3027,14 +3033,14 @@ void tst_Model_Relations::each() const ConnectionOverride::connection = connection; - std::vector indexes; + std::vector indexes; indexes.reserve(4); std::vector ids; ids.reserve(4); auto result = Torrent::find(2)->tags()->orderBy(ID) .each([&indexes, &ids] - (Tag &&model, const int index) + (Tag &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).template value()); @@ -3046,7 +3052,7 @@ void tst_Model_Relations::each() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3}; + std::vector expectedIndexes {0, 1, 2, 3}; std::vector expectedIds {1, 2, 3, 4}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -3061,14 +3067,14 @@ void tst_Model_Relations::each_ReturnFalse() const ConnectionOverride::connection = connection; - std::vector indexes; + std::vector indexes; indexes.reserve(2); std::vector ids; ids.reserve(2); auto result = Torrent::find(2)->tags()->orderBy(ID) .each([&indexes, &ids] - (Tag &&model, const int index) + (Tag &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).template value()); @@ -3080,7 +3086,7 @@ void tst_Model_Relations::each_ReturnFalse() const QVERIFY(!result); - std::vector expectedIndexes {0, 1}; + std::vector expectedIndexes {0, 1}; std::vector expectedIds {1, 2}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -3098,14 +3104,14 @@ void tst_Model_Relations::each_EnforceOrderBy() const /* The TinBuilder version doesn't throws exception if the 'order by' clause is not specified, instead it adds a generic 'order by' clause on the Model::getQualifiedKeyName() (it sorts by the primary key by default). */ - std::vector indexes; + std::vector indexes; indexes.reserve(4); std::vector ids; ids.reserve(4); auto result = Torrent::find(2)->tags() ->each([&indexes, &ids] - (Tag &&model, const int index) + (Tag &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).template value()); @@ -3117,7 +3123,7 @@ void tst_Model_Relations::each_EnforceOrderBy() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3}; + std::vector expectedIndexes {0, 1, 2, 3}; std::vector expectedIds {1, 2, 3, 4}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -3138,7 +3144,7 @@ void tst_Model_Relations::each_EmptyResult() const QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .each([&callbackInvoked] - (Tag &&/*unused*/, const int /*unused*/) + (Tag &&/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; @@ -3378,13 +3384,14 @@ void tst_Model_Relations::chunkById() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 2}, {2, 2}}; + const std::unordered_map expectedRows {{1, 2}, {2, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -3392,7 +3399,7 @@ void tst_Model_Relations::chunkById() const auto result = Torrent::find(2)->tags()->orderBy(ID) .chunkById(2, [&compareResultSize, &ids] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { compareResultSize(models.size(), page); @@ -3422,13 +3429,14 @@ void tst_Model_Relations::chunkById_ReturnFalse() const using SizeType = ModelsCollection::size_type; // (I leave it here also in this test, doesn't matter much - const std::unordered_map expectedRows {{1, 2}, {2, 2}}; + const std::unordered_map expectedRows {{1, 2}, {2, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -3436,7 +3444,7 @@ void tst_Model_Relations::chunkById_ReturnFalse() const auto result = Torrent::find(2)->tags()->orderBy(ID) .chunkById(2, [&compareResultSize, &ids] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { compareResultSize(models.size(), page); @@ -3475,7 +3483,7 @@ void tst_Model_Relations::chunkById_EmptyResult() const .orderBy(ID) .chunkById(2, [&callbackInvoked] (ModelsCollection &&/*unused*/, - const int /*unused*/) + const qint64 /*unused*/) { callbackInvoked = true; @@ -3495,13 +3503,14 @@ void tst_Model_Relations::chunkById_WithAlias() const using SizeType = ModelsCollection::size_type; // - const std::unordered_map expectedRows {{1, 2}, {2, 2}}; + const std::unordered_map expectedRows {{1, 2}, {2, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -3511,7 +3520,7 @@ void tst_Model_Relations::chunkById_WithAlias() const ->select({ASTERISK, "torrent_tags.id as id_as"}) .orderBy(ID) .chunkById(2, [&compareResultSize, &ids] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { compareResultSize(models.size(), page); @@ -3523,7 +3532,7 @@ void tst_Model_Relations::chunkById_WithAlias() const return true; }, - ID, "id_as"); + ID, "id_as"); QVERIFY(result); @@ -3542,13 +3551,14 @@ void tst_Model_Relations::chunkById_ReturnFalse_WithAlias() const using SizeType = ModelsCollection::size_type; // (I leave it here also in this test, doesn't matter much - const std::unordered_map expectedRows {{1, 2}, {2, 2}}; + const std::unordered_map expectedRows {{1, 2}, {2, 2}}; /* Can't be inside the chunk's callback because QCOMPARE internally calls 'return;' and it causes compile error. */ - const auto compareResultSize = [&expectedRows](const SizeType size, const int page) + const auto compareResultSize = [&expectedRows] + (const SizeType size, const qint64 page) { - QCOMPARE(size, expectedRows.at(page)); + QCOMPARE(static_cast(size), expectedRows.at(page)); }; std::vector ids; @@ -3558,7 +3568,7 @@ void tst_Model_Relations::chunkById_ReturnFalse_WithAlias() const ->select({ASTERISK, "torrent_tags.id as id_as"}) .orderBy(ID) .chunkById(2, [&compareResultSize, &ids] - (ModelsCollection &&models, const int page) + (ModelsCollection &&models, const qint64 page) { compareResultSize(models.size(), page); @@ -3575,7 +3585,7 @@ void tst_Model_Relations::chunkById_ReturnFalse_WithAlias() const return true; }, - ID, "id_as"); + ID, "id_as"); QVERIFY(!result); @@ -3599,13 +3609,13 @@ void tst_Model_Relations::chunkById_EmptyResult_WithAlias() const .orderBy(ID) .chunkById(2, [&callbackInvoked] (ModelsCollection &&/*unused*/, - const int /*unused*/) + const qint64 /*unused*/) { callbackInvoked = true; return true; }, - ID, "id_as"); + ID, "id_as"); QVERIFY(!callbackInvoked); QVERIFY(result); @@ -3617,7 +3627,7 @@ void tst_Model_Relations::eachById() const ConnectionOverride::connection = connection; - std::vector indexes; + std::vector indexes; indexes.reserve(4); std::vector ids; ids.reserve(4); @@ -3625,7 +3635,7 @@ void tst_Model_Relations::eachById() const auto result = Torrent::find(2)->tags() ->orderBy(ID) .eachById([&indexes, &ids] - (Tag &&model, const int index) + (Tag &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); @@ -3637,7 +3647,7 @@ void tst_Model_Relations::eachById() const QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3}; + std::vector expectedIndexes {0, 1, 2, 3}; std::vector expectedIds {1, 2, 3, 4}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -3652,7 +3662,7 @@ void tst_Model_Relations::eachById_ReturnFalse() const ConnectionOverride::connection = connection; - std::vector indexes; + std::vector indexes; indexes.reserve(2); std::vector ids; ids.reserve(2); @@ -3660,7 +3670,7 @@ void tst_Model_Relations::eachById_ReturnFalse() const auto result = Torrent::find(2)->tags() ->orderBy(ID) .eachById([&indexes, &ids] - (Tag &&model, const int index) + (Tag &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); @@ -3672,7 +3682,7 @@ void tst_Model_Relations::eachById_ReturnFalse() const QVERIFY(!result); - std::vector expectedIndexes {0, 1}; + std::vector expectedIndexes {0, 1}; std::vector expectedIds {1, 2}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -3693,7 +3703,7 @@ void tst_Model_Relations::eachById_EmptyResult() const QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .eachById([&callbackInvoked] - (Tag &&/*unused*/, const int /*unused*/) + (Tag &&/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; @@ -3710,7 +3720,7 @@ void tst_Model_Relations::eachById_WithAlias() const ConnectionOverride::connection = connection; - std::vector indexes; + std::vector indexes; indexes.reserve(4); std::vector ids; ids.reserve(4); @@ -3719,7 +3729,7 @@ void tst_Model_Relations::eachById_WithAlias() const ->select({ASTERISK, "torrent_tags.id as id_as"}) .orderBy(ID) .eachById([&indexes, &ids] - (Tag &&model, const int index) + (Tag &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); @@ -3728,11 +3738,11 @@ void tst_Model_Relations::eachById_WithAlias() const return true; }, - 1000, ID, "id_as"); + 1000, ID, "id_as"); QVERIFY(result); - std::vector expectedIndexes {0, 1, 2, 3}; + std::vector expectedIndexes {0, 1, 2, 3}; std::vector expectedIds {1, 2, 3, 4}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -3747,7 +3757,7 @@ void tst_Model_Relations::eachById_ReturnFalse_WithAlias() const ConnectionOverride::connection = connection; - std::vector indexes; + std::vector indexes; indexes.reserve(2); std::vector ids; ids.reserve(2); @@ -3756,7 +3766,7 @@ void tst_Model_Relations::eachById_ReturnFalse_WithAlias() const ->select({ASTERISK, "torrent_tags.id as id_as"}) .orderBy(ID) .eachById([&indexes, &ids] - (Tag &&model, const int index) + (Tag &&model, const qint64 index) { indexes.emplace_back(index); ids.emplace_back(model.getAttribute(ID).value()); @@ -3765,11 +3775,11 @@ void tst_Model_Relations::eachById_ReturnFalse_WithAlias() const return index != 1; // false/interrupt on 1 }, - 1000, ID, "id_as"); + 1000, ID, "id_as"); QVERIFY(!result); - std::vector expectedIndexes {0, 1}; + std::vector expectedIndexes {0, 1}; std::vector expectedIds {1, 2}; QVERIFY(indexes.size() == expectedIndexes.size()); @@ -3791,13 +3801,13 @@ void tst_Model_Relations::eachById_EmptyResult_WithAlias() const .whereEq("torrent_tags.name", QStringLiteral("dummy-NON_EXISTENT")) .orderBy(ID) .eachById([&callbackInvoked] - (Tag &&/*unused*/, const int /*unused*/) + (Tag &&/*unused*/, const qint64 /*unused*/) { callbackInvoked = true; return true; }, - 1000, ID, "id_as"); + 1000, ID, "id_as"); QVERIFY(!callbackInvoked); QVERIFY(result); diff --git a/tom/src/tom/migrationrepository.cpp b/tom/src/tom/migrationrepository.cpp index 3a44d5622..87a23ecd6 100644 --- a/tom/src/tom/migrationrepository.cpp +++ b/tom/src/tom/migrationrepository.cpp @@ -58,7 +58,7 @@ std::vector MigrationRepository::getMigrations(const int steps) c auto query = table()->where(batch_, GE, 1) .orderBy(batch_, DESC) .orderBy(migration_, DESC) - .take(steps) + .take(static_cast(steps)) .get(); return hydrateMigrations(query);