Skip to content

Commit

Permalink
Merge pull request #1029 from Expensify/master
Browse files Browse the repository at this point in the history
  • Loading branch information
iwiznia authored May 25, 2021
2 parents 3c58b52 + cd266b8 commit 163cfba
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions plugins/DB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,23 @@ bool BedrockDBCommand::peek(SQLite& db) {
STHROW("502 Query aborted");
}

if (SStartsWith(upperQuery, "SELECT ")) {
// Seems to be read-only
SINFO("Query appears to be read-only, peeking.");
} else {
// Attempt the read-only query
SQResult result;
int preChangeCount = db.getChangeCount();
if (!db.read(query, result)) {
if (shouldRequireWhere &&
(SStartsWith(upperQuery, "UPDATE") || SStartsWith(upperQuery, "DELETE")) &&
!SContains(upperQuery, " WHERE ")) {
(SContains(upperQuery, "UPDATE ") || SContains(upperQuery, "DELETE ")) &&
!SContains(upperQuery, " WHERE ")) {
SALERT("Query aborted, it has no 'where' clause: '" << query << "'");
STHROW("502 Query aborted");
}

// Assume it's read/write
// Assume it's write or bad query, escalating it to process
// If it's a bad query, it will fail in the process too
SINFO("Query appears to be read/write, queuing for processing.");
return false;
}

// Attempt the read-only query
SQResult result;
int preChangeCount = db.getChangeCount();
if (!db.read(query, result)) {
// Query failed
SALERT("Query failed: '" << query << "'");
response["error"] = db.getLastError();
STHROW("502 Query failed");
}

// Verify it didn't change anything -- assert because if we did, we did so
// outside of a replicated transaction and that's REALLY bad.
if (preChangeCount != db.getChangeCount()) {
Expand Down

0 comments on commit 163cfba

Please sign in to comment.