MySQL 9.1.0
Source Code Documentation
my_decimal.cc File Reference
#include "my_decimal.h"
#include "my_config.h"
#include <stdio.h>
#include <sys/time.h>
#include "decimal.h"
#include "my_dbug.h"
#include "my_sys.h"
#include "my_time.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_time.h"
#include "mysqld_error.h"
#include "sql/current_thd.h"
#include "sql/derror.h"
#include "sql/field.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"

Macros

#define DIG_PER_DEC1   9
 
#define ROUND_UP(X)   (((X) + DIG_PER_DEC1 - 1) / DIG_PER_DEC1)
 

Functions

int my_decimal2string (uint mask, const my_decimal *d, uint fixed_prec, uint fixed_dec, String *str)
 Converting decimal to string. More...
 
bool str_set_decimal (uint mask, const my_decimal *val, String *str, const CHARSET_INFO *cs, uint decimals)
 Converting decimal to string with character set conversion. More...
 
int my_decimal2binary (uint mask, const my_decimal *d, uchar *bin, int prec, int scale)
 
int str2my_decimal (uint mask, const char *from, size_t length, const CHARSET_INFO *charset, my_decimal *decimal_value)
 
static my_decimallldiv_t2my_decimal (const lldiv_t *lld, bool neg, my_decimal *dec)
 Convert lldiv_t value to my_decimal value. More...
 
my_decimaldate2my_decimal (const MYSQL_TIME *ltime, my_decimal *dec)
 Convert datetime value to my_decimal in format YYYYMMDDhhmmss.ffffff. More...
 
my_decimaltime2my_decimal (const MYSQL_TIME *ltime, my_decimal *dec)
 Convert time value to my_decimal in format hhmmss.ffffff. More...
 
my_decimaltimeval2my_decimal (const my_timeval *tm, my_decimal *dec)
 Convert timeval value to my_decimal. More...
 
void my_decimal_trim (ulong *precision, uint *scale)
 
void print_decimal (const my_decimal *dec)
 
void print_decimal_buff (const my_decimal *dec, const uchar *ptr, int length)
 
const char * dbug_decimal_as_string (char *buff, const my_decimal *val)
 

Macro Definition Documentation

◆ DIG_PER_DEC1

#define DIG_PER_DEC1   9

◆ ROUND_UP

#define ROUND_UP (   X)    (((X) + DIG_PER_DEC1 - 1) / DIG_PER_DEC1)

Function Documentation

◆ date2my_decimal()

my_decimal * date2my_decimal ( const MYSQL_TIME ltime,
my_decimal dec 
)

Convert datetime value to my_decimal in format YYYYMMDDhhmmss.ffffff.

Parameters
ltimeDate value to convert from.
decDecimal value to convert to.

◆ dbug_decimal_as_string()

const char * dbug_decimal_as_string ( char *  buff,
const my_decimal val 
)

◆ lldiv_t2my_decimal()

static my_decimal * lldiv_t2my_decimal ( const lldiv_t *  lld,
bool  neg,
my_decimal dec 
)
static

Convert lldiv_t value to my_decimal value.

Integer part of the result is set to lld->quot. Fractional part of the result is set to lld->rem divided to 1000000000.

Parameters
lldThe lldiv_t variable to convert from.
negSign flag (negative, 0 positive).
[out]decDecimal number to convert to.

◆ my_decimal2binary()

int my_decimal2binary ( uint  mask,
const my_decimal d,
uchar bin,
int  prec,
int  scale 
)

◆ my_decimal2string()

int my_decimal2string ( uint  mask,
const my_decimal d,
uint  fixed_prec,
uint  fixed_dec,
String str 
)

Converting decimal to string.

Convert given my_decimal to String; allocate buffer as needed.

Parameters
[in]maskwhat problems to warn on (mask of E_DEC_* values)
[in]dthe decimal to print
[in]fixed_precoverall number of digits if ZEROFILL, 0 otherwise
[in]fixed_decnumber of decimal places (if fixed_prec != 0)
[out]strwhere to store the resulting string
Returns
error code
Return values
E_DEC_OKok
E_DEC_TRUNCATEDtruncated
E_DEC_OVERFLOWoverflow
E_DEC_OOMout-of-memory

◆ my_decimal_trim()

void my_decimal_trim ( ulong *  precision,
uint *  scale 
)

◆ print_decimal()

void print_decimal ( const my_decimal dec)

◆ print_decimal_buff()

void print_decimal_buff ( const my_decimal dec,
const uchar ptr,
int  length 
)

◆ str2my_decimal()

int str2my_decimal ( uint  mask,
const char *  from,
size_t  length,
const CHARSET_INFO charset,
my_decimal decimal_value 
)

◆ str_set_decimal()

bool str_set_decimal ( uint  mask,
const my_decimal val,
String str,
const CHARSET_INFO cs,
uint  decimals 
)

Converting decimal to string with character set conversion.

Convert given my_decimal to String; allocate buffer as needed.

Parameters
[in]maskwhat problems to warn on (mask of E_DEC_* values)
[in]valthe decimal to print
[out]strwhere to store the resulting string
[in]cscharacter set
[in]decimalsround to desired number of decimals
Returns
error code
Return values
E_DEC_OKok
E_DEC_TRUNCATEDtruncated
E_DEC_OVERFLOWoverflow
E_DEC_OOMout-of-memory

Would be great to make it a method of the String class, but this would need to include my_decimal.h from sql_string.h and sql_string.cc, which is not desirable.

◆ time2my_decimal()

my_decimal * time2my_decimal ( const MYSQL_TIME ltime,
my_decimal dec 
)

Convert time value to my_decimal in format hhmmss.ffffff.

Parameters
ltimeDate value to convert from.
decDecimal value to convert to.

◆ timeval2my_decimal()

my_decimal * timeval2my_decimal ( const my_timeval tm,
my_decimal dec 
)

Convert timeval value to my_decimal.