Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-hx committed Nov 20, 2024
1 parent eaf6b75 commit ca93ea8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
8 changes: 4 additions & 4 deletions cpp/lib/ClientBindUploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@ void ClientBindUploader::createStageIfNeeded()
return;
}

_mutex_lock(&conn->mutex_parameters);
_mutex_lock(&conn->mutex_stage_bind);
if (conn->binding_stage_created)
{
_mutex_unlock(&conn->mutex_parameters);
_mutex_unlock(&conn->mutex_stage_bind);
return;
}

std::string command = getCreateStageStmt();
SF_STATUS ret = snowflake_query(m_stmt, command.c_str(), 0);
if (ret != SF_STATUS_SUCCESS)
{
_mutex_unlock(&conn->mutex_parameters);
_mutex_unlock(&conn->mutex_stage_bind);
SNOWFLAKE_THROW_S(&m_stmt->error);
}

conn->binding_stage_created = SF_BOOLEAN_TRUE;
_mutex_unlock(&conn->mutex_parameters);
_mutex_unlock(&conn->mutex_stage_bind);
}

void ClientBindUploader::executeUploading(const std::string &sql,
Expand Down
4 changes: 2 additions & 2 deletions cpp/lib/Exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ SnowflakeGeneralException::SnowflakeGeneralException(SF_ERROR_STRUCT *error) :
m_message(error->msg ? error->msg : ""),
m_file(error->file ? error->file : ""),
m_line(error->line),
m_queryId(error->sfqid ? error->sfqid : ""),
m_sqlState(error->sqlstate ? error->sqlstate : ""),
m_queryId(error->sfqid),
m_sqlState(error->sqlstate),
m_code((int)error->error_code)
{
std::string errmsg = setupErrorMessage(m_message, m_file, m_line, m_queryId, m_sqlState, m_code);
Expand Down
2 changes: 2 additions & 0 deletions include/snowflake/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ typedef struct SF_CONNECT {
int64 get_threshold;

// stage binding
/* used when updating stage binding options */
SF_MUTEX_HANDLE mutex_stage_bind;
sf_bool binding_stage_created;
uint64 stage_binding_threshold;
// the flag indecates the threshold from session parameter is overridden
Expand Down
2 changes: 2 additions & 0 deletions lib/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ SF_CONNECT *STDCALL snowflake_init() {
sf->get_maxretries = SF_DEFAULT_GET_MAX_RETRIES;
sf->get_threshold = SF_DEFAULT_GET_THRESHOLD;

_mutex_init(&sf->mutex_stage_bind);
sf->binding_stage_created = SF_BOOLEAN_FALSE;
sf->stage_binding_threshold = SF_DEFAULT_STAGE_BINDING_THRESHOLD;
}
Expand Down Expand Up @@ -809,6 +810,7 @@ SF_STATUS STDCALL snowflake_term(SF_CONNECT *sf) {

_mutex_term(&sf->mutex_sequence_counter);
_mutex_term(&sf->mutex_parameters);
_mutex_term(&sf->mutex_stage_bind);
SF_FREE(sf->host);
SF_FREE(sf->port);
SF_FREE(sf->user);
Expand Down
3 changes: 3 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ message("CLOUD_PROVIDER is set to " $ENV{CLOUD_PROVIDER})
if (APPLE OR WIN32 OR CLIENT_CODE_COVERAGE)
set(TESTS_C ${TESTS_C})
set(TESTS_CXX ${TESTS_CXX} ${TESTS_PUTGET})
elseif(DEFINED ENV{GITHUB_ACTIONS} AND $ENV{BUILD_TYPE} STREQUAL "Debug")
message("Skip CXX test on github Linux Debug for disk space issue")
set (TESTS_CXX "")
endif ()

if (UNIX)
Expand Down
16 changes: 11 additions & 5 deletions tests/test_bind_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void test_array_binding_core(unsigned int array_size) {
uint8 uint8_value = 12;
char uint8_expected_result[] = "12";
int64* int64_array = NULL;
int64 int64_value = -12345;
char int64_expected_result[] = "-12345";
int64 int64_value = 12345;
char int64_expected_result[] = "12345";
uint64* uint64_array = NULL;
uint64 uint64_value = 12345;
char uint64_expected_result[] = "12345";
Expand All @@ -133,8 +133,8 @@ void test_array_binding_core(unsigned int array_size) {
char* string_array = NULL;
char string_value[] = "str";
char string_expected_result[] = "str";
byte* binary_array = NULL;
byte binary_value[] = {0x12, 0x34, 0x56, 0x78};
unsigned char* binary_array = NULL;
unsigned char binary_value[] = {0x12, 0x34, 0x56, 0x78};
char binary_expected_result[] = "12345678";
sf_bool* bool_array = NULL;
sf_bool bool_value = SF_BOOLEAN_TRUE;
Expand Down Expand Up @@ -237,6 +237,9 @@ void test_array_binding_core(unsigned int array_size) {

/* Connect with all parameters set */
SF_CONNECT* sf = setup_snowflake_connection();
// turn on FAIL_OPEN to around certificate issue with GCP
sf_bool value = SF_BOOLEAN_TRUE;
snowflake_set_attribute(sf, SF_CON_OCSP_FAIL_OPEN, &value);
status = snowflake_connect(sf);
assert_int_equal(status, SF_STATUS_SUCCESS);

Expand Down Expand Up @@ -272,8 +275,11 @@ void test_array_binding_core(unsigned int array_size) {
for (i = 0; i < array_size; i++)
{
status = snowflake_fetch(stmt);
if (status != SF_STATUS_SUCCESS) {
dump_error(&(stmt->error));
}
assert_int_equal(status, SF_STATUS_SUCCESS);
char* result = NULL;
const char* result = NULL;
for (j = 0; j < 8; j++)
{
snowflake_column_as_const_str(stmt, j + 1, &result);
Expand Down

0 comments on commit ca93ea8

Please sign in to comment.