From 90d36cd3c06c14113fade5fc3d4268679c5a8b65 Mon Sep 17 00:00:00 2001 From: Tyler Karaszewski Date: Tue, 9 Apr 2024 13:13:40 -0700 Subject: [PATCH] Fix bug where rows would reference wrong SQResult after copy --- libstuff/SQResult.cpp | 9 +++++++++ libstuff/SQResult.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/libstuff/SQResult.cpp b/libstuff/SQResult.cpp index 7a9d3e9f3..2eb447296 100644 --- a/libstuff/SQResult.cpp +++ b/libstuff/SQResult.cpp @@ -162,3 +162,12 @@ const SQResultRow& SQResult::operator[](size_t rowNum) const { STHROW("Out of range"); } } + +SQResult& SQResult::operator=(const SQResult& other) { + headers = other.headers; + rows = other.rows; + for (auto& row : rows) { + row.result = this; + } + return *this; +} diff --git a/libstuff/SQResult.h b/libstuff/SQResult.h index 001907fa9..1ecd3560f 100644 --- a/libstuff/SQResult.h +++ b/libstuff/SQResult.h @@ -6,6 +6,7 @@ using namespace std; class SQResult; class SQResultRow : public vector { + friend class SQResult; public: SQResultRow(); SQResultRow(SQResult& result, size_t count = 0); @@ -36,6 +37,7 @@ class SQResult { // Operators SQResultRow& operator[](size_t rowNum); const SQResultRow& operator[](size_t rowNum) const; + SQResult& operator=(const SQResult& other); // Serializers string serializeToJSON() const;