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

[APIS-967] When Double type value is retrieved through CCI, when the value after the decimal point is 0, 0 is not returned. #73

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions src/cci/cci_handle_mng.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static int
compare_conn_info (unsigned char *ip_addr, int port, char *dbname, char *dbuser, char *dbpasswd, bool useSSL,
T_CON_HANDLE * con_handle)
{
if (con_handle->useSSL != useSSL || port != con_handle->port || memcmp (ip_addr, con_handle->ip_addr, 4) != 0
if (con_handle->useSSL != useSSL || port != con_handle->port || memcmp (ip_addr, con_handle->ip_addr, 4) != 0
airnet73 marked this conversation as resolved.
Show resolved Hide resolved
|| strcmp (dbname, con_handle->db_name) != 0 || strcmp (dbuser, con_handle->db_user) != 0
|| strcmp (dbpasswd, con_handle->db_passwd) != 0)
{
Expand Down Expand Up @@ -1233,7 +1233,8 @@ hm_make_empty_session (T_CCI_SESSION_ID * id)
}

static int
init_con_handle (T_CON_HANDLE * con_handle, char *ip_str, int port, char *db_name, char *db_user, char *db_passwd, bool useSSL)
init_con_handle (T_CON_HANDLE * con_handle, char *ip_str, int port, char *db_name, char *db_user, char *db_passwd,
bool useSSL)
{
unsigned char ip_addr[4];

Expand Down Expand Up @@ -1323,6 +1324,7 @@ init_con_handle (T_CON_HANDLE * con_handle, char *ip_str, int port, char *db_nam
con_handle->ssl_handle.ctx = NULL;
con_handle->useSSL = useSSL;
con_handle->__gateway = false;
con_handle->oracle_style_number_return = false;
con_handle->deferred_max_close_handle_count = DEFERRED_CLOSE_HANDLE_ALLOC_SIZE;
con_handle->deferred_close_handle_list = (int *) MALLOC (sizeof (int) * con_handle->deferred_max_close_handle_count);
con_handle->deferred_close_handle_count = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/cci/cci_handle_mng.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ typedef struct
char log_trace_network;
char useSSL;
char __gateway;
char oracle_style_number_return;

/* to check timeout */
struct timeval start_time; /* function start time to check timeout */
Expand All @@ -288,7 +289,8 @@ typedef struct
************************************************************************/

extern void hm_con_handle_table_init (void);
extern T_CON_HANDLE *hm_con_handle_alloc (char *ip_str, int port, char *db_name, char *db_user, char *db_passwd, bool useSSL);
extern T_CON_HANDLE *hm_con_handle_alloc (char *ip_str, int port, char *db_name, char *db_user, char *db_passwd,
bool useSSL);
extern int hm_req_handle_alloc (T_CON_HANDLE * connection, T_REQ_HANDLE ** statement);
extern void hm_req_handle_free (T_CON_HANDLE * con_handle, T_REQ_HANDLE * req_handle);
extern void hm_req_handle_free_all (T_CON_HANDLE * con_handle);
Expand Down
3 changes: 2 additions & 1 deletion src/cci/cci_properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ cci_conn_set_properties (T_CON_HANDLE * handle, char *properties)
{"disconnect_on_query_timeout", BOOL_PROPERTY,
&handle->disconnect_on_query_timeout},
{"useSSL", BOOL_PROPERTY, &handle->useSSL},
{"__gateway", BOOL_PROPERTY, &handle->__gateway}
{"__gateway", BOOL_PROPERTY, &handle->__gateway},
{"oracleStyleNumberReturn", BOOL_PROPERTY, &handle->oracle_style_number_return}
};
int error = CCI_ER_NO_ERROR;

Expand Down
26 changes: 22 additions & 4 deletions src/cci/cci_query_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,9 @@ qe_get_data (T_CON_HANDLE * con_handle, T_REQ_HANDLE * req_handle, int col_no, i
switch (a_type)
{
case CCI_A_TYPE_STR:
err_code = qe_get_data_str (&(req_handle->conv_value_buffer), u_type, col_value_p, data_size, value, indicator);
err_code =
qe_get_data_str (&(req_handle->conv_value_buffer), u_type, col_value_p, data_size, value, indicator,
con_handle->oracle_style_number_return);
break;
case CCI_A_TYPE_BIGINT:
err_code = qe_get_data_bigint (u_type, col_value_p, value);
Expand Down Expand Up @@ -3258,7 +3260,7 @@ qe_execute_batch (T_CON_HANDLE * con_handle, int num_query, char **sql_stmt, T_C

int
qe_get_data_str (T_VALUE_BUF * conv_val_buf, T_CCI_U_TYPE u_type, char *col_value_p, int col_val_size, void *value,
int *indicator)
int *indicator, bool oracle_style_number_return)
{
assert (u_type >= CCI_U_TYPE_FIRST && u_type <= CCI_U_TYPE_LAST);

Expand Down Expand Up @@ -3351,7 +3353,15 @@ qe_get_data_str (T_VALUE_BUF * conv_val_buf, T_CCI_U_TYPE u_type, char *col_valu
{
return CCI_ER_NO_MORE_MEMORY;
}
ut_double_to_str (data, (char *) conv_val_buf->data, 512);

if (oracle_style_number_return == false)
{
ut_double_to_str (data, (char *) conv_val_buf->data, 512);
}
else
{
ut_double_to_trailingzero_str (data, (char *) conv_val_buf->data, 512);
}
}
break;
case CCI_U_TYPE_FLOAT:
Expand All @@ -3364,7 +3374,15 @@ qe_get_data_str (T_VALUE_BUF * conv_val_buf, T_CCI_U_TYPE u_type, char *col_valu
{
return CCI_ER_NO_MORE_MEMORY;
}
ut_float_to_str (data, (char *) conv_val_buf->data, 128);

if (oracle_style_number_return == false)
{
ut_float_to_str (data, (char *) conv_val_buf->data, 128);
}
else
{
ut_float_to_trailingzero_str (data, (char *) conv_val_buf->data, 128);
}
}
break;
case CCI_U_TYPE_DATE:
Expand Down
2 changes: 1 addition & 1 deletion src/cci/cci_query_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ extern int qe_execute_batch (T_CON_HANDLE * con_handle, int num_query, char **sq
extern int qe_query_result_copy (T_REQ_HANDLE * req_handle, T_CCI_QUERY_RESULT ** res_qr);

extern int qe_get_data_str (T_VALUE_BUF * conv_val_buf, T_CCI_U_TYPE u_type, char *col_value_p, int col_val_size,
void *value, int *indicator);
void *value, int *indicator, bool oracle_style_number_return);
extern int qe_get_data_bigint (T_CCI_U_TYPE u_type, char *col_value_p, void *value);
extern int qe_get_data_ubigint (T_CCI_U_TYPE u_type, char *col_value_p, void *value);
extern int qe_get_data_int (T_CCI_U_TYPE u_type, char *col_value_p, void *value);
Expand Down
3 changes: 2 additions & 1 deletion src/cci/cci_t_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ t_set_get (T_SET * set, int index, T_CCI_A_TYPE a_type, void *value, int *indica
{
case CCI_A_TYPE_STR:
err_code =
qe_get_data_str (&(set->conv_value_buffer), (T_CCI_U_TYPE) u_type, ele_value_p, data_size, value, indicator);
qe_get_data_str (&(set->conv_value_buffer), (T_CCI_U_TYPE) u_type, ele_value_p, data_size, value, indicator,
false);
break;
case CCI_A_TYPE_INT:
err_code = qe_get_data_int ((T_CCI_U_TYPE) u_type, ele_value_p, value);
Expand Down
79 changes: 79 additions & 0 deletions src/cci/cci_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#endif
#include <sys/types.h>
#include <regex>
#include <math.h>

/************************************************************************
* OTHER IMPORTED HEADER FILES *
Expand All @@ -66,6 +67,8 @@
/************************************************************************
* PRIVATE DEFINITIONS *
************************************************************************/
#define MAX_DOUBLE_STRING (512)
#define MAX_FLOAT_STRING (128)

/************************************************************************
* PRIVATE TYPE DEFINITIONS *
Expand Down Expand Up @@ -772,6 +775,82 @@ ut_double_to_str (double value, char *str, int size)
snprintf (str, size, "%.16f", value);
}

void
ut_double_to_trailingzero_str (double value, char *str, int size)
airnet73 marked this conversation as resolved.
Show resolved Hide resolved
{
char double_str[MAX_DOUBLE_STRING];
char return_str[MAX_DOUBLE_STRING] = { '-', '0', '.', '\0', };
int exp_num, offset, p;

char *dot, *exp, *sp = return_str + 1;

sprintf (double_str, "%.16g", fabs (value));
airnet73 marked this conversation as resolved.
Show resolved Hide resolved
dot = strchr (double_str, '.');
exp = strchr (double_str, 'e');

if (!exp)
{
sprintf (str, "%s%s", (value < 0) ? "-" : "", double_str);
airnet73 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

exp_num = atoi (exp + 1);

if (exp_num > 0)
{
memcpy (sp, double_str, offset = (int) (dot - double_str));
memcpy (sp + offset, dot + 1, p = (int) (exp - dot) - 1);
memset (sp + offset + p, '0', exp_num - (int) (exp - dot) + 1);
}
else
{
exp_num = -exp_num;
memset (sp + 2, '0', offset = exp_num - 1);
memcpy (sp + 2 + offset, double_str, p = (int) (dot - double_str));
memcpy (sp + 2 + offset + p, dot + 1, (int) (exp - dot) - 1);
}

(value < 0) ? strncpy (str, return_str, size) : strncpy (str, return_str + 1, size);
airnet73 marked this conversation as resolved.
Show resolved Hide resolved
}

void
ut_float_to_trailingzero_str (float value, char *str, int size)
{
char float_str[MAX_FLOAT_STRING];
char return_str[MAX_FLOAT_STRING] = { '-', '0', '.', '\0', };
int exp_num, offset, p;

char *dot, *exp, *sp = return_str + 1;

sprintf (float_str, "%g", fabsf (value));
dot = strchr (float_str, '.');
exp = strchr (float_str, 'e');

if (!exp)
{
sprintf (str, "%s%s", (value < 0) ? "-" : "", float_str);
return;
}

exp_num = atoi (exp + 1);

if (exp_num > 0)
{
memcpy (sp, float_str, offset = (int) (dot - float_str));
memcpy (sp + offset, dot + 1, p = (int) (exp - dot) - 1);
memset (sp + offset + p, '0', exp_num - (int) (exp - dot) + 1);
}
else
{
exp_num = -exp_num;
memset (sp + 2, '0', offset = exp_num - 1);
memcpy (sp + 2 + offset, float_str, p = (int) (dot - float_str));
memcpy (sp + 2 + offset + p, dot + 1, (int) (exp - dot) - 1);
}

(value < 0) ? strncpy (str, return_str, size) : strncpy (str, return_str + 1, size);
airnet73 marked this conversation as resolved.
Show resolved Hide resolved
}

void
ut_date_to_str (T_CCI_DATE * value, T_CCI_U_TYPE u_type, char *str, int size)
{
Expand Down
2 changes: 2 additions & 0 deletions src/cci/cci_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ extern int ut_str_to_oid (char *str, T_OBJECT * value);
extern void ut_int_to_str (INT64 value, char *str, int size);
extern void ut_uint_to_str (UINT64 value, char *str, int size);
extern void ut_float_to_str (float value, char *str, int size);
extern void ut_float_to_trailingzero_str (float value, char *str, int size);
extern void ut_double_to_str (double value, char *str, int size);
extern void ut_double_to_trailingzero_str (double value, char *str, int size);
extern void ut_date_to_str (T_CCI_DATE * value, T_CCI_U_TYPE u_type, char *str, int size);
extern void ut_date_tz_to_str (T_CCI_DATE_TZ * value, T_CCI_U_TYPE u_type, char *str, int size);
extern void ut_oid_to_str (T_OBJECT * oid, char *str);
Expand Down