Skip to content

Commit

Permalink
Update write method to accept result argument
Browse files Browse the repository at this point in the history
  • Loading branch information
MonilBhavsar committed Dec 9, 2024
1 parent b496479 commit 72bb681
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions sqlitecluster/SQLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,16 @@ bool SQLite::write(const string& query) {
return _writeIdempotent(query, ignore);
}

bool SQLite::write(const string& query, SQResult& result) {
if (_noopUpdateMode) {
SALERT("Non-idempotent write in _noopUpdateMode. Query: " << query);
return true;
}

// This is literally identical to the idempotent version except for the check for _noopUpdateMode.
return _writeIdempotent(query, result);
}

bool SQLite::writeIdempotent(const string& query) {
SQResult ignore;
return _writeIdempotent(query, ignore);
Expand Down
6 changes: 5 additions & 1 deletion sqlitecluster/SQLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ class SQLite {
bool addColumn(const string& tableName, const string& column, const string& columnType);

// Performs a read/write query (eg, INSERT, UPDATE, DELETE). This is added to the current transaction's query list.
// Returns true on success.
// Returns true on success.
// If we're in noop-update mode, this call alerts and performs no write, but returns as if it had completed.
bool write(const string& query);

// Performs a read/write query
// Designed for use with queries that include a RETURNING clause
bool write(const string& query, SQResult& result);

// This is the same as `write` except it runs successfully without any warnings or errors in noop-update mode.
// It's intended to be used for `mockRequest` enabled commands, such that we only run a version of them that's
// known to be repeatable. What counts as repeatable is up to the individual command.
Expand Down

0 comments on commit 72bb681

Please sign in to comment.