Skip to content

Commit

Permalink
Merge pull request #1693 from Expensify/tyler-fix-sqresult-row-bug
Browse files Browse the repository at this point in the history
Fix bug where rows would reference wrong SQResult after copy
  • Loading branch information
tylerkaraszewski authored Apr 9, 2024
2 parents 0677e01 + 90d36cd commit 0138770
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libstuff/SQResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions libstuff/SQResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using namespace std;
class SQResult;

class SQResultRow : public vector<string> {
friend class SQResult;
public:
SQResultRow();
SQResultRow(SQResult& result, size_t count = 0);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0138770

Please sign in to comment.