CUBRID Engine  latest
arithmetic.c File Reference
#include "arithmetic.h"
#include "config.h"
#include "crypt_opfunc.h"
#include "db_date.h"
#include "db_json.hpp"
#include "db_json_path.hpp"
#include "dbtype.h"
#include "error_manager.h"
#include "memory_private_allocator.hpp"
#include "memory_reference_store.hpp"
#include "numeric_opfunc.h"
#include "object_primitive.h"
#include "object_representation.h"
#include "string_opfunc.h"
#include "tz_support.h"
#include <algorithm>
#include <assert.h>
#include <cctype>
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Macros

#define RETURN_ERROR(err)
 
#define RETURN_ERROR_WITH_ARG(err, arg)
 
#define MAX_DOMAIN_NAME_SIZE   150
 

Functions

static int db_mod_short (DB_VALUE *value, DB_VALUE *value1, DB_VALUE *value2)
 
static int db_mod_int (DB_VALUE *value, DB_VALUE *value1, DB_VALUE *value2)
 
static int db_mod_bigint (DB_VALUE *value, DB_VALUE *value1, DB_VALUE *value2)
 
static int db_mod_float (DB_VALUE *value, DB_VALUE *value1, DB_VALUE *value2)
 
static int db_mod_double (DB_VALUE *value, DB_VALUE *value1, DB_VALUE *value2)
 
static int db_mod_string (DB_VALUE *value, DB_VALUE *value1, DB_VALUE *value2)
 
static int db_mod_numeric (DB_VALUE *value, DB_VALUE *value1, DB_VALUE *value2)
 
static int db_mod_monetary (DB_VALUE *value, DB_VALUE *value1, DB_VALUE *value2)
 
static double round_double (double num, double integer)
 
static int move_n_days (int *monthp, int *dayp, int *yearp, const int interval)
 
static int round_date (DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
 
static double truncate_double (double num, double integer)
 
static DB_BIGINT truncate_bigint (DB_BIGINT num, DB_BIGINT integer)
 
static int truncate_date (DB_DATE *date, const DB_VALUE *format_str)
 
static int get_number_dbval_as_double (double *d, const DB_VALUE *value)
 
static int get_number_dbval_as_long_double (long double *ld, const DB_VALUE *value)
 
static int db_width_bucket_calculate_numeric (double *result, const DB_VALUE *value1, const DB_VALUE *value2, const DB_VALUE *value3, const DB_VALUE *value4)
 
static int is_str_find_all (DB_VALUE *val, bool &find_all)
 
static bool is_any_arg_null (DB_VALUE *const *args, int num_args)
 
int db_floor_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_ceil_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_sign_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_abs_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_exp_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_sqrt_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_power_dbval (DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
 
int db_mod_dbval (DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
 
int db_round_dbval (DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
 
int db_log_dbval (DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
 
int db_trunc_dbval (DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
 
int db_random_dbval (DB_VALUE *result)
 
int db_drandom_dbval (DB_VALUE *result)
 
int db_cos_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_sin_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_tan_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_cot_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_acos_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_asin_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_atan_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_atan2_dbval (DB_VALUE *result, DB_VALUE *value, DB_VALUE *value2)
 
int db_degrees_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_radians_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_log_generic_dbval (DB_VALUE *result, DB_VALUE *value, long b)
 
int db_bit_count_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_typeof_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_width_bucket (DB_VALUE *result, const DB_VALUE *value1, const DB_VALUE *value2, const DB_VALUE *value3, const DB_VALUE *value4)
 
int db_sleep (DB_VALUE *result, DB_VALUE *value)
 
int db_crc32_dbval (DB_VALUE *result, DB_VALUE *value)
 
int db_evaluate_json_contains (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_type_dbval (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_valid (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_length (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_depth (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_quote (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_unquote (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_pretty (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_accumulate_json_arrayagg (const DB_VALUE *json_db_val, DB_VALUE *json_res)
 
int db_accumulate_json_objectagg (const DB_VALUE *json_key, const DB_VALUE *json_db_val, DB_VALUE *json_res)
 
int db_evaluate_json_extract (DB_VALUE *result, DB_VALUE *const *args, int num_args)
 
int db_evaluate_json_object (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_array (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_insert (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_replace (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_set (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_keys (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_remove (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_array_append (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_array_insert (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_evaluate_json_contains_path (DB_VALUE *result, DB_VALUE *const *arg, const int num_args)
 
int db_evaluate_json_merge_preserve (DB_VALUE *result, DB_VALUE *const *arg, const int num_args)
 
int db_evaluate_json_merge_patch (DB_VALUE *result, DB_VALUE *const *arg, const int num_args)
 
int db_evaluate_json_search (DB_VALUE *result, DB_VALUE *const *args, const int num_args)
 
int db_evaluate_json_get_all_paths (DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
 
int db_least_or_greatest (DB_VALUE *arg1, DB_VALUE *arg2, DB_VALUE *result, bool least)
 

Macro Definition Documentation

#define MAX_DOMAIN_NAME_SIZE   150

Referenced by db_width_bucket().

#define RETURN_ERROR (   err)
Value:
do \
{ \
{ \
db_make_null (result); \
er_clear (); \
return NO_ERROR; \
} \
{ \
return (err); \
} \
} \
while (0)
#define NO_ERROR
Definition: error_code.h:46
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
if(extra_options)
Definition: dynamic_load.c:958
#define err(fd,...)
Definition: porting.h:431
#define ARG_FILE_LINE
Definition: error_manager.h:44
bool prm_get_bool_value(PARAM_ID prm_id)
void er_clear(void)
else
int db_make_null(DB_VALUE *value)
while(1)
Definition: cnvlex.c:816

Referenced by db_width_bucket().

#define RETURN_ERROR_WITH_ARG (   err,
  arg 
)
Value:
do \
{ \
{ \
db_make_null (result); \
er_clear (); \
return NO_ERROR; \
} \
{ \
return (err); \
} \
} \
while (0)
#define NO_ERROR
Definition: error_code.h:46
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
if(extra_options)
Definition: dynamic_load.c:958
#define err(fd,...)
Definition: porting.h:431
#define ARG_FILE_LINE
Definition: error_manager.h:44
bool prm_get_bool_value(PARAM_ID prm_id)
void er_clear(void)
else
int db_make_null(DB_VALUE *value)
while(1)
Definition: cnvlex.c:816

Referenced by db_width_bucket().

Function Documentation

int db_accumulate_json_arrayagg ( const DB_VALUE json_db_val,
DB_VALUE json_res 
)
int db_accumulate_json_objectagg ( const DB_VALUE json_key,
const DB_VALUE json_db_val,
DB_VALUE json_res 
)
int db_atan2_dbval ( DB_VALUE result,
DB_VALUE value,
DB_VALUE value2 
)

Definition at line 4006 of file arithmetic.c.

References DB_IS_NULL, db_make_double(), db_make_null(), DB_TYPE_NULL, DB_VALUE_DOMAIN_TYPE, err, get_number_dbval_as_double(), and NO_ERROR.

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_atan_dbval ( DB_VALUE result,
DB_VALUE value 
)

Definition at line 3970 of file arithmetic.c.

References DB_IS_NULL, db_make_double(), db_make_null(), DB_TYPE_NULL, DB_VALUE_DOMAIN_TYPE, err, get_number_dbval_as_double(), and NO_ERROR.

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_cos_dbval ( DB_VALUE result,
DB_VALUE value 
)

Definition at line 3737 of file arithmetic.c.

References DB_IS_NULL, db_make_double(), db_make_null(), DB_TYPE_NULL, DB_VALUE_DOMAIN_TYPE, err, get_number_dbval_as_double(), and NO_ERROR.

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_cot_dbval ( DB_VALUE result,
DB_VALUE value 
)

Definition at line 3833 of file arithmetic.c.

References DB_IS_NULL, db_make_double(), db_make_null(), DB_TYPE_NULL, DB_VALUE_DOMAIN_TYPE, err, get_number_dbval_as_double(), and NO_ERROR.

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_degrees_dbval ( DB_VALUE result,
DB_VALUE value 
)

Definition at line 4054 of file arithmetic.c.

References DB_IS_NULL, db_make_double(), db_make_null(), DB_TYPE_NULL, DB_VALUE_DOMAIN_TYPE, err, get_number_dbval_as_double(), and NO_ERROR.

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_drandom_dbval ( DB_VALUE result)

Definition at line 3672 of file arithmetic.c.

References db_make_double(), and NO_ERROR.

int db_evaluate_json_array ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)
int db_evaluate_json_contains ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)
int db_evaluate_json_contains_path ( DB_VALUE result,
DB_VALUE *const arg,
const int  num_args 
)
int db_evaluate_json_depth ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)

Definition at line 5269 of file arithmetic.c.

References assert, DB_IS_NULL, db_json_get_depth(), db_make_int(), db_make_null(), db_value_to_json_doc(), ER_FAILED, and NO_ERROR.

Referenced by pt_evaluate_function_w_args(), and qdata_evaluate_function().

Here is the caller graph for this function:

int db_evaluate_json_extract ( DB_VALUE result,
DB_VALUE *const args,
int  num_args 
)
int db_evaluate_json_get_all_paths ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)
int db_evaluate_json_length ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)
int db_evaluate_json_merge_patch ( DB_VALUE result,
DB_VALUE *const arg,
const int  num_args 
)
int db_evaluate_json_merge_preserve ( DB_VALUE result,
DB_VALUE *const arg,
const int  num_args 
)
int db_evaluate_json_pretty ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)
int db_evaluate_json_quote ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)

Definition at line 5294 of file arithmetic.c.

References assert, db_string_quote(), and ER_FAILED.

Referenced by pt_evaluate_function_w_args(), and qdata_evaluate_function().

Here is the caller graph for this function:

int db_evaluate_json_type_dbval ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)
int db_evaluate_json_unquote ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)
int db_evaluate_json_valid ( DB_VALUE result,
DB_VALUE *const arg,
int const  num_args 
)
int db_least_or_greatest ( DB_VALUE arg1,
DB_VALUE arg2,
DB_VALUE result,
bool  least 
)

Definition at line 6454 of file arithmetic.c.

References assert_release, DB_EQ, DB_GT, DB_IS_NULL, DB_LT, db_make_null(), DB_UNK, ER_FAILED, NO_ERROR, pr_clone_value(), and tp_value_compare_with_error().

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_log_generic_dbval ( DB_VALUE result,
DB_VALUE value,
long  b 
)
static int db_mod_string ( DB_VALUE value,
DB_VALUE value1,
DB_VALUE value2 
)
static
int db_radians_dbval ( DB_VALUE result,
DB_VALUE value 
)

Definition at line 4086 of file arithmetic.c.

References DB_IS_NULL, db_make_double(), db_make_null(), DB_TYPE_NULL, DB_VALUE_DOMAIN_TYPE, err, get_number_dbval_as_double(), and NO_ERROR.

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_random_dbval ( DB_VALUE result)

Definition at line 3659 of file arithmetic.c.

References db_make_int(), and NO_ERROR.

int db_round_dbval ( DB_VALUE result,
DB_VALUE value1,
DB_VALUE value2 
)
int db_sin_dbval ( DB_VALUE result,
DB_VALUE value 
)

Definition at line 3769 of file arithmetic.c.

References DB_IS_NULL, db_make_double(), db_make_null(), DB_TYPE_NULL, DB_VALUE_DOMAIN_TYPE, err, get_number_dbval_as_double(), and NO_ERROR.

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_sleep ( DB_VALUE result,
DB_VALUE value 
)
int db_tan_dbval ( DB_VALUE result,
DB_VALUE value 
)

Definition at line 3801 of file arithmetic.c.

References DB_IS_NULL, db_make_double(), db_make_null(), DB_TYPE_NULL, DB_VALUE_DOMAIN_TYPE, err, get_number_dbval_as_double(), and NO_ERROR.

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_trunc_dbval ( DB_VALUE result,
DB_VALUE value1,
DB_VALUE value2 
)

Definition at line 3311 of file arithmetic.c.

References ARG_FILE_LINE, assert, d1, db_datetime::date, db_datetimetz::datetime, db_get_bigint(), db_get_date(), db_get_datetime(), db_get_datetimetz(), db_get_double(), db_get_float(), db_get_int(), db_get_monetary(), db_get_short(), db_get_string(), db_get_timestamp(), db_get_timestamptz(), DB_IS_NULL, db_locate_numeric, db_make_bigint(), db_make_double(), db_make_float(), db_make_int(), db_make_monetary(), db_make_null(), db_make_numeric(), db_make_short(), db_make_string(), DB_MAX_NUMERIC_PRECISION, DB_NUMERIC_BUF_SIZE, db_timestamp_decode_ses(), db_timestamp_decode_w_tz_id(), DB_TYPE_BIGINT, DB_TYPE_CHAR, DB_TYPE_DATE, DB_TYPE_DATETIME, DB_TYPE_DATETIMELTZ, DB_TYPE_DATETIMETZ, DB_TYPE_DOUBLE, DB_TYPE_FLOAT, DB_TYPE_INTEGER, DB_TYPE_MONETARY, DB_TYPE_NUMERIC, DB_TYPE_SHORT, DB_TYPE_TIMESTAMP, DB_TYPE_TIMESTAMPLTZ, DB_TYPE_TIMESTAMPTZ, DB_TYPE_UNKNOWN, DB_VALUE_DOMAIN_TYPE, DB_VALUE_PRECISION, db_value_put_encoded_date(), DB_VALUE_SCALE, DOMAIN_COMPATIBLE, er_clear(), ER_ERROR_SEVERITY, ER_QPROC_INVALID_DATATYPE, ER_QSTR_INVALID_FORMAT, er_set(), NO_ERROR, NULL, numeric_coerce_dec_str_to_num(), numeric_coerce_num_to_dec_str(), p, pr_clear_value(), prm_get_bool_value(), PRM_ID_RETURN_NULL_ON_FUNCTION_ERRORS, QSTR_IS_ANY_CHAR, strlen, db_timestamptz::timestamp, tp_domain_resolve_default(), TP_IS_DATE_TYPE, tp_value_coerce(), truncate_bigint(), truncate_date(), truncate_double(), tz_datetimeltz_to_local(), db_timestamptz::tz_id, db_datetimetz::tz_id, and tz_utc_datetimetz_to_local().

Referenced by fetch_peek_arith(), and pt_evaluate_db_value_expr().

Here is the caller graph for this function:

int db_width_bucket ( DB_VALUE result,
const DB_VALUE value1,
const DB_VALUE value2,
const DB_VALUE value3,
const DB_VALUE value4 
)
static int db_width_bucket_calculate_numeric ( double *  result,
const DB_VALUE value1,
const DB_VALUE value2,
const DB_VALUE value3,
const DB_VALUE value4 
)
static
static bool is_any_arg_null ( DB_VALUE *const args,
int  num_args 
)
static
static int is_str_find_all ( DB_VALUE val,
bool find_all 
)
static
static int move_n_days ( int *  monthp,
int *  dayp,
int *  yearp,
const int  interval 
)
static

Definition at line 2022 of file arithmetic.c.

References db_date_decode(), db_date_encode(), error(), and NO_ERROR.

Referenced by round_date().

Here is the caller graph for this function:

static double round_double ( double  num,
double  integer 
)
static

Definition at line 1987 of file arithmetic.c.

References ARG_FILE_LINE, ER_ERROR_SEVERITY, ER_IT_DATA_OVERFLOW, er_set(), FINITE, pr_type::name, tp_Double_domain, and tp_domain::type.

Referenced by db_round_dbval().

Here is the caller graph for this function:

static DB_BIGINT truncate_bigint ( DB_BIGINT  num,
DB_BIGINT  integer 
)
static

Definition at line 3183 of file arithmetic.c.

Referenced by db_trunc_dbval().

Here is the caller graph for this function:

static int truncate_date ( DB_DATE date,
const DB_VALUE format_str 
)
static
static double truncate_double ( double  num,
double  integer 
)
static

Definition at line 3140 of file arithmetic.c.

Referenced by db_trunc_dbval().

Here is the caller graph for this function: