Skip to content

Commit

Permalink
Show row values in errors in Firebird backend
Browse files Browse the repository at this point in the history
This is similar to the other backends without special support for bulk
operations: just remember the current row during bulk operations, so
that we could refer to its values if an error happens.
  • Loading branch information
vadz committed Jan 30, 2025
1 parent 7ed67e8 commit 0ea3281
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions include/soci/firebird/soci-firebird.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ struct SOCI_FIREBIRD_DECL firebird_statement_backend : details::statement_backen
long long get_affected_rows() override;
int get_number_of_rows() override;
std::string get_parameter_name(int index) const override;
int get_row_to_dump() const override { return current_row_; }

std::string rewrite_for_procedure_call(std::string const &query) override;

Expand Down Expand Up @@ -252,6 +253,11 @@ struct SOCI_FIREBIRD_DECL firebird_statement_backend : details::statement_backen
std::map <std::string, int> names_;

bool procedure_;

private:
// Used during bulk operations to keep track of the row which potentially
// resulted in an error.
int current_row_ = -1;
};

struct SOCI_FIREBIRD_DECL firebird_blob_backend : details::blob_backend
Expand Down
8 changes: 5 additions & 3 deletions src/backends/firebird/statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,13 @@ firebird_statement_backend::execute(int number)

// Here we have to explicitly loop to achieve the
// effect of inserting or updating with vector use elements.
std::size_t rows = static_cast<firebird_vector_use_type_backend*>(uses_[0])->size();
for (std::size_t row=0; row < rows; ++row)
const int rows = static_cast<firebird_vector_use_type_backend*>(uses_[0])->size();
for (current_row_ = 0; current_row_ < rows; ++current_row_)
{
// first we have to prepare input parameters
for (std::size_t col=0; col<usize; ++col)
{
static_cast<firebird_vector_use_type_backend*>(uses_[col])->exchangeData(row);
static_cast<firebird_vector_use_type_backend*>(uses_[col])->exchangeData(current_row_);
}

// then execute query
Expand All @@ -437,6 +437,8 @@ firebird_statement_backend::execute(int number)
// in same query. So here, we know that into elements are not
// vectors. So, there is no need to fetch data here.
}

current_row_ = -1;
}
else
{
Expand Down

0 comments on commit 0ea3281

Please sign in to comment.