Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-24893] Gateway's DML bug fixed #4535

Merged
merged 7 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/broker/cas.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ cas_main (void)
char tmp_passwd[SRV_CON_DBPASSWD_SIZE] = { 0, };
SUPPORTED_DBMS_TYPE dbms_type = NOT_SUPPORTED_DBMS;
char *find_gateway = NULL;
char errplog_path[BROKER_PATH_MAX] = { 0, };
char errlog_file[BROKER_PATH_MAX] = { 0, };
#endif

#if defined(CAS_FOR_ORACLE)
Expand Down Expand Up @@ -943,6 +945,12 @@ cas_main (void)
logddl_init (APP_NAME_CAS);

#if defined(CAS_FOR_CGW)
sprintf (errlog_file, "%s%s_%d.err",
get_cubrid_file (FID_CUBRID_ERR_DIR, errplog_path, BROKER_PATH_MAX), shm_appl->broker_name,
shm_as_index + 1);

er_init (errlog_file, ER_NEVER_EXIT);

if (cgw_init () < 0)
{
return -1;
Expand Down
254 changes: 168 additions & 86 deletions src/broker/cas_cgw.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
if (rc != SQL_SUCCESS) \
{ \
cgw_error_msg (h, ht, rc); \
} \
if (rc <= SQL_ERROR) \
{ \
if (db_error_code () == 0) \
{ \
er_set (ER_ERROR_SEVERITY, \
ARG_FILE_LINE, \
ER_CGW_NATIVE_ODBC, \
3, cgw_get_dbms_name (cgw_get_dbms_type ()), -1, "Unknown ODBC Driver Error"); \
} \
goto ODBC_ERROR; \
} \
}
Expand All @@ -67,7 +77,9 @@ struct t_supported_dbms
static INTL_CODESET client_charset = INTL_CODESET_UTF8;
static char conv_out_string[CONV_STRING_BUF_SIZE + 1];
static T_SUPPORTED_DBMS supported_dbms_list[] =
{ {"oracle", SUPPORTED_DBMS_ORACLE}, {"mysql", SUPPORTED_DBMS_MYSQL}, {"mariadb", SUPPORTED_DBMS_MARIADB} };
{ {"oracle", SUPPORTED_DBMS_ORACLE}, {"mysql", SUPPORTED_DBMS_MYSQL}, {"mariadb", SUPPORTED_DBMS_MARIADB},
{"not supported db", NOT_SUPPORTED_DBMS}
};

static int supported_dbms_max_num = sizeof (supported_dbms_list) / sizeof (T_SUPPORTED_DBMS);
static SUPPORTED_DBMS_TYPE curr_dbms_type = NOT_SUPPORTED_DBMS;
Expand Down Expand Up @@ -104,6 +116,7 @@ static int cgw_unicode_to_utf8 (wchar_t * in_src, int in_size, char **out_target
static int cgw_conv_mtow (wchar_t * destStr, char *sourStr);
static int cgw_uint32_to_uni16 (uint32_t i, uint16_t * u);
static SQLWCHAR *cgw_wchar_to_sqlwchar (wchar_t * src, size_t len);
static char *cgw_get_dbms_name (SUPPORTED_DBMS_TYPE db_type);


int
Expand Down Expand Up @@ -250,7 +263,7 @@ cgw_database_connect (SUPPORTED_DBMS_TYPE dbms_type, const char *connect_url, ch
}

int
cgw_execute (T_SRV_HANDLE * srv_handle)
cgw_execute (T_SRV_HANDLE * srv_handle, SQLLEN * row_count)
{
SQLRETURN err_code;

Expand All @@ -272,6 +285,14 @@ cgw_execute (T_SRV_HANDLE * srv_handle)

SQL_CHK_ERR (srv_handle->cgw_handle->hstmt, SQL_HANDLE_STMT, err_code = SQLExecute (srv_handle->cgw_handle->hstmt));

if (err_code < 0)
{
cgw_error_msg (srv_handle->cgw_handle->hstmt, SQL_HANDLE_STMT, err_code);
goto ODBC_ERROR;
}

SQLRowCount (srv_handle->cgw_handle->hstmt, row_count);

srv_handle->is_cursor_open = true;

return NO_ERROR;
Expand Down Expand Up @@ -1150,8 +1171,11 @@ cgw_error_msg (SQLHANDLE hHandle, SQLSMALLINT hType, RETCODE retcode)
char szMessage[SQL_MAX_MESSAGE_LENGTH + 1];
char szState[SQL_SQLSTATE_SIZE + 1];

er_clear ();

if (retcode == SQL_INVALID_HANDLE)
{
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_CGW_INVALID_STMT_HANDLE, 0);
return;
}

Expand Down Expand Up @@ -1200,6 +1224,7 @@ static int
cgw_set_bindparam (T_CGW_HANDLE * handle, int bind_num, void *net_type, void *net_value, ODBC_BIND_INFO * value_list)
{
char type;
char src_type = -1;
int err_code = 0;
int data_size;
SQLLEN indPtr = 0;
Expand Down Expand Up @@ -1227,6 +1252,14 @@ cgw_set_bindparam (T_CGW_HANDLE * handle, int bind_num, void *net_type, void *ne
data_size = 0;
}

// Oracle ODBC does not support the BIGINT type.
// So, change it to Numeric type.
if (curr_dbms_type == SUPPORTED_DBMS_ORACLE && type == CCI_U_TYPE_BIGINT)
{
src_type = type;
type = CCI_U_TYPE_NUMERIC;
}

switch (type)
{
case CCI_U_TYPE_CHAR:
Expand Down Expand Up @@ -1277,101 +1310,137 @@ cgw_set_bindparam (T_CGW_HANDLE * handle, int bind_num, void *net_type, void *ne

case CCI_U_TYPE_NUMERIC:
{
char *value, *p;
int val_size;
size_t precision, scale;
char num_str[64];
char tmp[64];
SQLHDESC hdesc = NULL;
if (curr_dbms_type == SUPPORTED_DBMS_MARIADB)
{

SQL_CHK_ERR (handle->hdbc, SQL_HANDLE_DBC, err_code = SQLAllocHandle (SQL_HANDLE_DESC, handle->hdbc, &hdesc));
char *value = NULL;
int val_size = 0;

memset (&value_list->ns_val, 0x00, sizeof (SQL_NUMERIC_STRUCT));
net_arg_get_str (&value, &val_size, net_value);

net_arg_get_str (&value, &val_size, net_value);
if (value != NULL)
{
strcpy (tmp, value);
}
tmp[val_size] = '\0';
ut_trim (tmp);
precision = strlen (tmp);
p = strchr (tmp, '.');
if (p == NULL)
{
scale = 0;
}
else
{
scale = strlen (p + 1);
precision--;
}
c_data_type = SQL_C_CHAR;
sql_bind_type = SQL_CHAR;

if (tmp[0] == '-')
{
precision--;
value_list->ns_val.sign = MINUS;
value_list->string_val = value;

SQL_CHK_ERR (handle->hstmt,
SQL_HANDLE_STMT,
err_code = SQLBindParameter (handle->hstmt,
bind_num,
SQL_PARAM_INPUT,
c_data_type,
sql_bind_type, val_size + 1, 0, value_list->string_val, 0, NULL));
}
else
{
value_list->ns_val.sign = PLUS;
}
char *value = NULL, *p = NULL;
int val_size = 0;
size_t precision = 0, scale = 0;
char num_str[64] = { 0, };
char tmp[64] = { 0, };
SQLHDESC hdesc = NULL;
DB_BIGINT bi_val;

value_list->ns_val.precision = precision;
value_list->ns_val.scale = scale;
SQL_CHK_ERR (handle->hdbc, SQL_HANDLE_DBC, err_code =
SQLAllocHandle (SQL_HANDLE_DESC, handle->hdbc, &hdesc));

if (value_list->ns_val.sign == MINUS)
{
strcpy (num_str, &tmp[1]);
}
else
{
strcpy (num_str, &tmp[0]);
}
memset (&value_list->ns_val, 0x00, sizeof (SQL_NUMERIC_STRUCT));

err_code = numeric_string_adjust (&value_list->ns_val, num_str);
if (err_code < 0)
{
goto ODBC_ERROR;
}
if (src_type == CCI_U_TYPE_BIGINT)
{
net_arg_get_bigint (&bi_val, net_value);
snprintf (tmp, sizeof (tmp), "%lld", bi_val);
}
else
{
net_arg_get_str (&value, &val_size, net_value);
if (value != NULL)
{
strcpy (tmp, value);
}
tmp[val_size] = '\0';
}

ut_trim (tmp);
precision = strlen (tmp);
p = strchr (tmp, '.');
if (p == NULL)
{
scale = 0;
}
else
{
scale = strlen (p + 1);
precision--;
}

c_data_type = SQL_C_NUMERIC;
sql_bind_type = SQL_DECIMAL;
if (tmp[0] == '-')
{
precision--;
value_list->ns_val.sign = MINUS;
}
else
{
value_list->ns_val.sign = PLUS;
}

indPtr = sizeof (value_list->ns_val);
SQL_CHK_ERR (handle->hstmt,
SQL_HANDLE_STMT,
err_code = SQLBindParameter (handle->hstmt,
bind_num,
SQL_PARAM_INPUT,
c_data_type,
sql_bind_type,
value_list->ns_val.precision,
value_list->ns_val.scale, &value_list->ns_val, 0,
(SQLLEN *) & indPtr));

SQL_CHK_ERR (hdesc,
SQL_HANDLE_DESC,
err_code = SQLSetDescField (hdesc, bind_num, SQL_DESC_TYPE, (SQLPOINTER) SQL_C_NUMERIC, SQL_NTS));

SQL_CHK_ERR (hdesc,
SQL_HANDLE_DESC,
err_code =
SQLSetDescField (hdesc, bind_num, SQL_DESC_PRECISION,
(SQLPOINTER) value_list->ns_val.precision, 0));

SQL_CHK_ERR (hdesc,
SQL_HANDLE_DESC,
err_code =
SQLSetDescField (hdesc, bind_num, SQL_DESC_SCALE, (SQLPOINTER) value_list->ns_val.scale, 0));

SQL_CHK_ERR (hdesc,
SQL_HANDLE_DESC,
err_code =
SQLSetDescField (hdesc, bind_num, SQL_DESC_DATA_PTR, (SQLPOINTER) & value_list->ns_val, 0));

SQLFreeHandle (SQL_HANDLE_DESC, hdesc);
value_list->ns_val.precision = precision;
value_list->ns_val.scale = scale;

if (value_list->ns_val.sign == MINUS)
{
strcpy (num_str, &tmp[1]);
}
else
{
strcpy (num_str, &tmp[0]);
}

err_code = numeric_string_adjust (&value_list->ns_val, num_str);
if (err_code < 0)
{
goto ODBC_ERROR;
}


c_data_type = SQL_C_NUMERIC;
sql_bind_type = SQL_DECIMAL;

indPtr = sizeof (value_list->ns_val);
SQL_CHK_ERR (handle->hstmt,
SQL_HANDLE_STMT,
err_code = SQLBindParameter (handle->hstmt,
bind_num,
SQL_PARAM_INPUT,
c_data_type,
sql_bind_type,
value_list->ns_val.precision,
value_list->ns_val.scale, &value_list->ns_val, 0,
(SQLLEN *) & indPtr));

SQL_CHK_ERR (hdesc,
SQL_HANDLE_DESC,
err_code =
SQLSetDescField (hdesc, bind_num, SQL_DESC_TYPE, (SQLPOINTER) SQL_C_NUMERIC, SQL_NTS));

SQL_CHK_ERR (hdesc,
SQL_HANDLE_DESC,
err_code =
SQLSetDescField (hdesc, bind_num, SQL_DESC_PRECISION,
(SQLPOINTER) value_list->ns_val.precision, 0));

SQL_CHK_ERR (hdesc,
SQL_HANDLE_DESC,
err_code =
SQLSetDescField (hdesc, bind_num, SQL_DESC_SCALE, (SQLPOINTER) value_list->ns_val.scale, 0));

SQL_CHK_ERR (hdesc,
SQL_HANDLE_DESC,
err_code =
SQLSetDescField (hdesc, bind_num, SQL_DESC_DATA_PTR, (SQLPOINTER) & value_list->ns_val, 0));

SQLFreeHandle (SQL_HANDLE_DESC, hdesc);
}
}
break;
case CCI_U_TYPE_BIGINT:
Expand All @@ -1380,7 +1449,7 @@ cgw_set_bindparam (T_CGW_HANDLE * handle, int bind_num, void *net_type, void *ne
DB_BIGINT bi_val;
net_arg_get_bigint (&bi_val, net_value);

c_data_type = SQL_C_UBIGINT;
c_data_type = SQL_C_SBIGINT;
sql_bind_type = SQL_BIGINT;

value_list->bigint_val = bi_val;
Expand Down Expand Up @@ -2362,7 +2431,7 @@ cgw_set_dbms_type (SUPPORTED_DBMS_TYPE dbms_type)
curr_dbms_type = dbms_type;
}

int
SUPPORTED_DBMS_TYPE
cgw_get_dbms_type ()
{
return curr_dbms_type;
Expand Down Expand Up @@ -2694,3 +2763,16 @@ cgw_wchar_to_sqlwchar (wchar_t * src, size_t len)

return NULL;
}

static char *
cgw_get_dbms_name (SUPPORTED_DBMS_TYPE db_type)
{
for (int i = 0; i < supported_dbms_max_num; i++)
{
if (db_type == supported_dbms_list[i].dbms_type)
{
return supported_dbms_list[i].dbms_name;
}
}
return "";
}
6 changes: 2 additions & 4 deletions src/broker/cas_cgw.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ union odbc_bind_info
#endif
};

extern void test_log (char *fmt, ...);

extern int cgw_init ();
extern void cgw_cleanup ();
extern int cgw_col_bindings (SQLHSTMT hstmt, SQLSMALLINT num_cols, T_COL_BINDER ** col_binding,
Expand All @@ -173,7 +171,7 @@ extern int cgw_get_col_info (SQLHSTMT hstmt, int col_num, T_ODBC_COL_INFO * col_

// Execute funtions
extern int cgw_set_commit_mode (SQLHDBC hdbc, bool auto_commit);
extern int cgw_execute (T_SRV_HANDLE * srv_handle);
extern int cgw_execute (T_SRV_HANDLE * srv_handle, SQLLEN * row_count);
extern int cgw_set_execute_info (T_SRV_HANDLE * srv_handle, T_NET_BUF * net_buf, int stmt_type);
extern int cgw_make_bind_value (T_CGW_HANDLE * handle, int num_bind, int argc, void **argv, ODBC_BIND_INFO ** ret_val);

Expand All @@ -187,6 +185,6 @@ extern int cgw_copy_tuple (T_COL_BINDER * src_col_binding, T_COL_BINDER * dst_co
extern int cgw_endtran (SQLHDBC hdbc, int tran_type);
extern SUPPORTED_DBMS_TYPE cgw_is_supported_dbms (char *dbms);
extern void cgw_set_dbms_type (SUPPORTED_DBMS_TYPE dbms_type);
extern int cgw_get_dbms_type ();
extern SUPPORTED_DBMS_TYPE cgw_get_dbms_type ();

#endif /* _CAS_CGW_H_ */
Loading