Skip to content

Commit

Permalink
Fix get_affected_rows() for partial updates in SQLite3 backend
Browse files Browse the repository at this point in the history
This function always returned 0 even if some rows were updated because
rowsAffectedBulkTemp was never copied into rowsAffectedBulk_ in this
case, i.e. when load_one() threw an exception.

Fix this by just getting rid of this temporary variable and updating
rowsAffectedBulk_ directly, this seems to be much simpler than this
code, added back in c97a666 (SQLite3 support for get_affected_rows() in
bulk operations., 2013-03-11), and is more correct.
  • Loading branch information
vadz committed Jan 28, 2025
1 parent 3ba7d78 commit 42d5a2e
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/backends/sqlite3/statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ sqlite3_statement_backend::bind_and_execute(int number)
{
statement_backend::exec_fetch_result retVal = ef_no_data;

long long rowsAffectedBulkTemp = 0;

rowsAffectedBulk_ = -1;
rowsAffectedBulk_ = 0;

int const rows = static_cast<int>(useData_.size());
for (int row = 0; row < rows; ++row)
Expand Down Expand Up @@ -341,8 +339,6 @@ sqlite3_statement_backend::bind_and_execute(int number)

if (SQLITE_OK != bindRes)
{
// preserve the number of rows affected so far.
rowsAffectedBulk_ = rowsAffectedBulkTemp;
throw sqlite3_soci_error("Failure to bind on bulk operations", bindRes);
}
}
Expand All @@ -356,10 +352,9 @@ sqlite3_statement_backend::bind_and_execute(int number)

databaseReady_=true; // Mark sqlite engine is ready to perform sqlite3_step
retVal = load_one(); // execute each bound line
rowsAffectedBulkTemp += get_affected_rows();
rowsAffectedBulk_ += sqlite3_changes(session_.conn_);
}

rowsAffectedBulk_ = rowsAffectedBulkTemp;
return retVal;
}

Expand Down

0 comments on commit 42d5a2e

Please sign in to comment.