Repository: apache/arrow
File: cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_statement.cc (C++)

Code before:

void ODBCStatement::RevertAppDescriptor(bool isApd) {
  if (isApd) {
    current_apd_ = built_in_apd_.get();
  } else {
    current_ard_ = built_in_ard_.get();
  }
}

void ODBCStatement::CloseCursor(bool suppress_errors) {
  if (!suppress_errors && !current_result_) {
    throw DriverException("Invalid cursor state", "24000");
  }

  if (current_result_) {
    current_result_->Close();
    current_result_ = nullptr;
  }

  // Reset the fetching state of this statement.
  current_ard_->NotifyBindingsHaveChanged();
  row_number_ = 0;
  has_reached_end_of_result_ = false;
}

bool ODBCStatement::GetData(SQLSMALLINT record_number, SQLSMALLINT c_type,
                            SQLPOINTER data_ptr, SQLLEN buffer_length,
                            SQLLEN* indicator_ptr) {
  if (record_number == 0) {
    throw DriverException("Bookmarks are not supported", "07009");
  } else if (record_number > ird_->GetRecords().size()) {
    throw DriverException("Invalid column index: " + std::to_string(record_number),
                          "07009");
  }

  SQLSMALLINT evaluated_c_type = c_type;

  // TODO: Get proper default precision and scale from abstraction.
  int precision = 38;  // arrow::Decimal128Type::kMaxPrecision;
  int scale = 0;

  if (c_type == SQL_ARD_TYPE) {
    if (record_number > current_ard_->GetRecords().size()) {
      throw DriverException("Invalid column index: " + std::to_string(record_number),
                            "07009");
    }
    const DescriptorRecord& record = current_ard_->GetRecords()[record_number - 1];
    evaluated_c_type = record.concise_type;
    precision = record.precision;
    scale = record.scale;
  }

Review comment (suggestion):
TODO - fix `@brief` statement in `CloseCursor` at `odbc_statement.h` and update `ReleaseStatement` too

Code after:
          spi_statement_->SetAttribute(Statement::NOSCAN, attribute_to_write);
      break;
    case SQL_ATTR_QUERY_TIMEOUT:
      SetAttribute(value, attribute_to_write);
      successfully_written =
          spi_statement_->SetAttribute(Statement::QUERY_TIMEOUT, attribute_to_write);
      break;
    default:
      throw DriverException("Invalid attribute: " + std::to_string(attribute_to_write),
                            "HY092");
  }
  if (!successfully_written) {
    GetDiagnostics().AddWarning("Optional value changed.", "01S02",
                                arrow::flight::sql::odbc::ODBCErrorCodes_GENERAL_WARNING);
  }
}

void ODBCStatement::RevertAppDescriptor(bool isApd) {
  if (isApd) {
    current_apd_ = built_in_apd_.get();
  } else {
    current_ard_ = built_in_ard_.get();
  }
}

void ODBCStatement::CloseCursor(bool suppress_errors) {
  if (!suppress_errors && !current_result_) {
    throw DriverException("Invalid cursor state", "24000");
  }

  if (current_result_) {
    current_result_->Close();
    current_result_ = nullptr;
  }

  // Reset the fetching state of this statement.
  current_ard_->NotifyBindingsHaveChanged();
  row_number_ = 0;
  has_reached_end_of_result_ = false;
}

bool ODBCStatement::GetData(SQLSMALLINT record_number, SQLSMALLINT c_type,
                            SQLPOINTER data_ptr, SQLLEN buffer_length,
                            SQLLEN* indicator_ptr) {
  if (record_number == 0) {
    throw DriverException("Bookmarks are not supported", "07009");
  } else if (record_number > ird_->GetRecords().size()) {
    throw DriverException("Invalid column index: " + std::to_string(record_number),
                          "07009");
  }