Skip to content

Commit

Permalink
move error methods intended to be called from C
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Oct 23, 2023
1 parent 4e2c333 commit ceed414
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions r/adbcdrivermanager/src/driver_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ class Error {
details_.push_back({key, value});
}

int DetailCount() const { return details_.size(); }

AdbcErrorDetail Detail(int index) const {
const auto& detail = details_[index];
return {detail.first.c_str(), reinterpret_cast<const uint8_t*>(detail.second.data()),
detail.second.size()};
}

void ToAdbc(AdbcError* adbc_error, AdbcDriver* driver = nullptr) {
auto error_owned_by_adbc_error = new Error(message_, details_);
adbc_error->message = const_cast<char*>(error_owned_by_adbc_error->message_.c_str());
Expand All @@ -70,6 +62,18 @@ class Error {
std::vector<std::pair<std::string, std::string>> details_;
std::string sql_state_;

// Let the Driver use these to expose C callables wrapping option setters/getters
template <typename DatabaseT, typename ConnectionT, typename StatementT>
friend class Driver;

int CDetailCount() const { return details_.size(); }

AdbcErrorDetail CDetail(int index) const {
const auto& detail = details_[index];
return {detail.first.c_str(), reinterpret_cast<const uint8_t*>(detail.second.data()),
detail.second.size()};
}

static void CRelease(AdbcError* error) {
auto error_obj = reinterpret_cast<Error*>(error->private_data);
delete error_obj;
Expand Down Expand Up @@ -391,12 +395,12 @@ class Driver {
}

auto error_obj = reinterpret_cast<Error*>(error->private_data);
return error_obj->DetailCount();
return error_obj->CDetailCount();
}

static AdbcErrorDetail CErrorGetDetail(const AdbcError* error, int index) {
auto error_obj = reinterpret_cast<Error*>(error->private_data);
return error_obj->Detail(index);
return error_obj->CDetail(index);
}

// Templatable trampolines
Expand Down

0 comments on commit ceed414

Please sign in to comment.