Skip to content

Commit

Permalink
squash. genquery2 msis
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn committed Mar 19, 2024
1 parent 816af51 commit 2b6fb91
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/re/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_library(
irods_server_re
OBJECT
"${CMAKE_CURRENT_SOURCE_DIR}/src/extractAvuMS.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/genquery2.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/msi_genquery2.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/genQueryMS.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/icatAdminMS.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/icatGeneralMS.cpp"
Expand Down
23 changes: 23 additions & 0 deletions server/re/include/irods/msi_genquery2.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
#ifndef IRODS_MSI_GENQUERY2_HPP
#define IRODS_MSI_GENQUERY2_HPP

/// \file

struct MsParam;
struct RuleExecInfo;

/// TODO
///
/// \since 4.3.2
auto msi_genquery2_execute(MsParam* _handle, MsParam* _query_string, RuleExecInfo* _rei) -> int;

/// TODO
///
/// \since 4.3.2
auto msi_genquery2_next_row(MsParam* _handle, RuleExecInfo* _rei) -> int;

/// TODO
///
/// \since 4.3.2
auto msi_genquery2_column(MsParam* _handle, MsParam* _column_index, MsParam* _column_value, RuleExecInfo* _rei) -> int;

/// TODO
///
/// \since 4.3.2
auto msi_genquery2_free(MsParam* _handle, RuleExecInfo* _rei) -> int;

#endif // IRODS_MSI_GENQUERY2_HPP
4 changes: 4 additions & 0 deletions server/re/include/irods/reAction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ namespace irods
table_[ "msiCutBufferInHalf" ] = new irods::ms_table_entry( "msiCutBufferInHalf", 1, std::function<int(msParam_t*,ruleExecInfo_t*)>( msiCutBufferInHalf ) );
table_[ "msiDoSomething" ] = new irods::ms_table_entry( "msiDoSomething", 2, std::function<int(msParam_t*,msParam_t*,ruleExecInfo_t*)>( msiDoSomething ) );
table_[ "msiTakeThreeArgumentsAndDoNothing" ] = new irods::ms_table_entry( "msiTakeThreeArgumentsAndDoNothing", 3, std::function<int(msParam_t*,msParam_t*,msParam_t*,ruleExecInfo_t*)>( msiTakeThreeArgumentsAndDoNothing ) );
table_["msi_genquery2_execute"] = new irods::ms_table_entry("msi_genquery2_execute", 2, std::function<int(msParam_t*, msParam_t*, ruleExecInfo_t*)>(msi_genquery2_execute));
table_["msi_genquery2_next_row"] = new irods::ms_table_entry("msi_genquery2_next_row", 1, std::function<int(msParam_t*, ruleExecInfo_t*)>(msi_genquery2_next_row));
table_["msi_genquery2_column"] = new irods::ms_table_entry("msi_genquery2_column", 3, std::function<int(msParam_t*, msParam_t*, msParam_t*, ruleExecInfo_t*)>(msi_genquery2_column));
table_["msi_genquery2_free"] = new irods::ms_table_entry("msi_genquery2_free", 1, std::function<int(msParam_t*, ruleExecInfo_t*)>(msi_genquery2_free));
}; // ms_table::ms_table

// clang-format on
Expand Down
135 changes: 130 additions & 5 deletions server/re/src/msi_genquery2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "irods/rodsError.h"
#include "irods/rodsErrorTable.h"
#include "irods/msi_preconditions.hpp"
#include "irods/irods_exception.hpp"

#include <fmt/format.h>
#include <boost/any.hpp>
Expand Down Expand Up @@ -42,6 +43,8 @@ namespace

auto msi_genquery2_execute(MsParam* _handle, MsParam* _query_string, RuleExecInfo* _rei) -> int
{
log_msi::trace(__func__);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle);
IRODS_MSI_REQUIRE_VALID_POINTER(_query_string);
IRODS_MSI_REQUIRE_VALID_POINTER(_rei);
Expand All @@ -59,7 +62,7 @@ auto msi_genquery2_execute(MsParam* _handle, MsParam* _query_string, RuleExecInf
char* results{};

if (const auto ec = rs_genquery2(_rei->rsComm, &input, &results); ec < 0) {
log_msi::error("Error while executing GenQuery2 query [error_code=[{}]].", ec);
log_msi::error("{}: Error while executing GenQuery2 query [error_code=[{}]].", __func__, ec);
return ec;
}

Expand All @@ -72,17 +75,139 @@ auto msi_genquery2_execute(MsParam* _handle, MsParam* _query_string, RuleExecInf
return 0;
} // msi_genquery2_execute

auto msi_genquery2_next_row() -> int
auto msi_genquery2_next_row(MsParam* _handle, RuleExecInfo* _rei) -> int
{
log_msi::trace(__func__);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle);
IRODS_MSI_REQUIRE_VALID_POINTER(_rei);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle->type);

IRODS_MSI_REQUIRE_TYPE(_handle->type, STR_MS_T);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle->inOutStruct);

try {
const auto ctx_handle_index = std::stoll(static_cast<char*>(_handle->inOutStruct));

if (ctx_handle_index < 0 || static_cast<decltype(gq2_context)::size_type>(ctx_handle_index) >= gq2_context.size()) {
log_msi::error("{}: Unknown context handle.", __func__);
return SYS_INVALID_INPUT_PARAM;
}

auto& ctx = gq2_context.at(static_cast<decltype(gq2_context)::size_type>(ctx_handle_index));

if (ctx.current_row < static_cast<std::int32_t>(ctx.rows.size()) - 1) {
++ctx.current_row;
log_msi::trace("{}: Incremented row position [{} => {}]. Returning 0.", __func__, ctx.current_row - 1, ctx.current_row);
return 0;
}

log_msi::trace("{}: Skipping increment of row position [current_row=[{}]]. Returning 1.", __func__, ctx.current_row);

// TODO Update this.
// We must return ERROR(stop_code, "") to trigger correct usage of msi_genquery2_next_row().
// Otherwise, the NREP can loop forever. Ultimately, this means we aren't allowed to return
// CODE(stop_code) to signal there is no new row available.
return 1;
}
catch (const irods::exception& e) {
log_msi::error("{}: {}", __func__, e.client_display_what());
return static_cast<int>(e.code());
}
catch (const std::exception& e) {
log_msi::error("{}: {}", __func__, e.what());
return SYS_LIBRARY_ERROR;
}

return 0;
} // msi_genquery2_next_row

auto msi_genquery2_column() -> int
auto msi_genquery2_column(MsParam* _handle, MsParam* _column_index, MsParam* _column_value, RuleExecInfo* _rei) -> int
{
log_msi::trace(__func__);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle);
IRODS_MSI_REQUIRE_VALID_POINTER(_column_index);
IRODS_MSI_REQUIRE_VALID_POINTER(_column_value);
IRODS_MSI_REQUIRE_VALID_POINTER(_rei);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle->type);
IRODS_MSI_REQUIRE_VALID_POINTER(_column_index->type);

IRODS_MSI_REQUIRE_TYPE(_handle->type, STR_MS_T);
IRODS_MSI_REQUIRE_TYPE(_column_index->type, STR_MS_T);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle->inOutStruct);
IRODS_MSI_REQUIRE_VALID_POINTER(_column_index->inOutStruct);

try {
const auto ctx_handle_index = std::stoll(static_cast<char*>(_handle->inOutStruct));

if (ctx_handle_index < 0 ||
static_cast<decltype(gq2_context)::size_type>(ctx_handle_index) >= gq2_context.size()) {
log_msi::error("{}: Unknown context handle.", __func__);
return SYS_INVALID_INPUT_PARAM;
}

auto& ctx = gq2_context.at(static_cast<decltype(gq2_context)::size_type>(ctx_handle_index));
const auto column_index = std::stoll(static_cast<char*>(_column_index->inOutStruct));

const auto& value = ctx.rows.at(ctx.current_row).at(column_index).get_ref<const std::string&>();
log_msi::debug("{}: Column value = [{}]", __func__, value);
fillStrInMsParam(_column_value, value.c_str());

return 0;
}
catch (const irods::exception& e) {
log_msi::error("{}: {}", __func__, e.client_display_what());
return static_cast<int>(e.code());
}
catch (const std::exception& e) {
log_msi::error("{}: {}", __func__, e.what());
return SYS_LIBRARY_ERROR;
}

return 0;
} // msi_genquery2_column

auto msi_genquery2_destroy() -> int
auto msi_genquery2_free(MsParam* _handle, RuleExecInfo* _rei) -> int
{
log_msi::trace(__func__);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle);
IRODS_MSI_REQUIRE_VALID_POINTER(_rei);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle->type);

IRODS_MSI_REQUIRE_TYPE(_handle->type, STR_MS_T);

IRODS_MSI_REQUIRE_VALID_POINTER(_handle->inOutStruct);

try {
const auto ctx_handle_index = std::stoll(static_cast<char*>(_handle->inOutStruct));

if (ctx_handle_index < 0 ||
static_cast<decltype(gq2_context)::size_type>(ctx_handle_index) >= gq2_context.size()) {
log_msi::error("{}: Unknown context handle.", __func__);
return SYS_INVALID_INPUT_PARAM;
}

auto ctx_iter = std::begin(gq2_context);
std::advance(ctx_iter, ctx_handle_index);
gq2_context.erase(ctx_iter);

return 0;
}
catch (const irods::exception& e) {
log_msi::error("{}: {}", __func__, e.client_display_what());
return static_cast<int>(e.code());
}
catch (const std::exception& e) {
log_msi::error("{}: {}", __func__, e.what());
return SYS_LIBRARY_ERROR;
}

return 0;
} // msi_genquery2_destroy
} // msi_genquery2_free

0 comments on commit 2b6fb91

Please sign in to comment.