diff --git a/drivers/common/include_private/orm/drivers/sqlresult_p.hpp b/drivers/common/include_private/orm/drivers/sqlresult_p.hpp index 9a21c0c7f..cc7c5c1a4 100644 --- a/drivers/common/include_private/orm/drivers/sqlresult_p.hpp +++ b/drivers/common/include_private/orm/drivers/sqlresult_p.hpp @@ -64,6 +64,9 @@ namespace Orm::Drivers bool isActive = false; /*! Is this result from the SELECT statement? */ bool isSelect = false; + /*! Determine if the instance needs cleanup before executing the query. It's + always true after the first query is executed. */ + bool needsCleanup = false; }; } // namespace Orm::Drivers diff --git a/drivers/mysql/src/orm/drivers/mysql/mysqlresult.cpp b/drivers/mysql/src/orm/drivers/mysql/mysqlresult.cpp index 72a0ae8b4..937cdd337 100644 --- a/drivers/mysql/src/orm/drivers/mysql/mysqlresult.cpp +++ b/drivers/mysql/src/orm/drivers/mysql/mysqlresult.cpp @@ -527,6 +527,13 @@ void MySqlResult::cleanupForNormal() { Q_D(MySqlResult); + /* Helps to avoid cleanup on the newly created instance, it's only false on the newly + created instance. */ + if (!d->needsCleanup) { + d->needsCleanup = true; + return; + } + d->recordCache.clear(); // Normal queries @@ -540,6 +547,13 @@ void MySqlResult::cleanupForPrepared() { Q_D(MySqlResult); + /* Helps to avoid cleanup on the newly created instance, it's only false on the newly + created instance. */ + if (!d->needsCleanup) { + d->needsCleanup = true; + return; + } + d->recordCache.clear(); // Prepared queries