MySQL  8.0.20
Source Code Documentation
field_conv.cc File Reference

Functions to copy data to or from fields. More...

#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include "field_types.h"
#include "m_ctype.h"
#include "my_byteorder.h"
#include "my_compare.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_sys.h"
#include "my_time.h"
#include "mysql/udf_registration_types.h"
#include "mysql_com.h"
#include "mysql_time.h"
#include "mysqld_error.h"
#include "nullable.h"
#include "sql/current_thd.h"
#include "sql/field.h"
#include "sql/item_timefunc.h"
#include "sql/my_decimal.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"
#include "sql/sql_time.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql_string.h"
#include "template_utils.h"

Functions

static bool is_subtype_of (Field::geometry_type sub, Field::geometry_type super)
 Check if geometry type sub is a subtype of super. More...
 
static void do_field_eq (Copy_field *, const Field *from_field, Field *to_field)
 
static void set_to_is_null (Field *to_field, bool is_null)
 
static void do_field_to_null_str (Copy_field *, const Field *from_field, Field *to_field)
 
type_conversion_status set_field_to_null (Field *field)
 
type_conversion_status set_field_to_null_with_conversions (Field *field, bool no_conversions)
 Set field to NULL or TIMESTAMP or to next auto_increment number. More...
 
static void do_skip (Copy_field *, const Field *, Field *)
 
static void do_copy_null (Copy_field *copy, const Field *from_field, Field *to_field)
 
static void do_copy_not_null (Copy_field *copy, const Field *from_field, Field *to_field)
 
static void do_copy_maybe_null (Copy_field *copy, const Field *from_field, Field *to_field)
 
static void do_copy_timestamp (Copy_field *copy, const Field *from_field, Field *to_field)
 
static void do_copy_next_number (Copy_field *copy, const Field *from_field, Field *to_field)
 
static void do_copy_blob (Copy_field *, const Field *from_field, Field *to_field)
 
static void do_conv_blob (Copy_field *copy, const Field *from_field, Field *to_field)
 
static void do_save_blob (Copy_field *copy, const Field *from_field, Field *to_field)
 Save blob in copy->tmp for GROUP BY. More...
 
static void do_save_json (Copy_field *, const Field *from_field, Field *to_field)
 Copy the contents of one Field_json into another Field_json. More...
 
static void do_field_string (Copy_field *, const Field *from_field, Field *to_field)
 
static void do_field_enum (Copy_field *copy, const Field *from_field, Field *to_field)
 
static void do_field_varbinary_pre50 (Copy_field *copy, const Field *from_field, Field *to_field)
 
static void do_field_int (Copy_field *, const Field *from_field, Field *to_field)
 
static void do_field_real (Copy_field *, const Field *from_field, Field *to_field)
 
static void do_field_decimal (Copy_field *, const Field *from_field, Field *to_field)
 
type_conversion_status copy_time_to_time (const Field *from, Field *to)
 
static void do_field_time (Copy_field *, const Field *from_field, Field *to_field)
 Convert between fields using time representation. More...
 
static void do_cut_string (Copy_field *, const Field *from_field, Field *to_field)
 string copy for single byte characters set when to string is shorter than from string. More...
 
static void do_cut_string_complex (Copy_field *, const Field *from_field, Field *to_field)
 string copy for multi byte characters set when to string is shorter than from string. More...
 
static void do_expand_binary (Copy_field *, const Field *from_field, Field *to_field)
 
static void do_expand_string (Copy_field *, const Field *from_field, Field *to_field)
 
static size_t get_varstring_copy_length (Field_varstring *to, const Field_varstring *from)
 Find how many bytes should be copied between Field_varstring fields so that only the bytes in use in the 'from' field are copied. More...
 
static void copy_field_varstring (Field_varstring *const to, const Field_varstring *const from)
 A variable length string field consists of: (a) 1 or 2 length bytes, depending on the VARCHAR column definition (b) as many relevant character bytes, as defined in the length byte(s) (c) unused padding up to the full length of the column. More...
 
static void do_varstring (Copy_field *, const Field *from_field, Field *to_field)
 
static bool is_blob_type (Field *to)
 
type_conversion_status field_conv (Field *to, const Field *from)
 Simple quick field convert that is called on insert. More...
 

Detailed Description

Functions to copy data to or from fields.

Function Documentation

◆ copy_field_varstring()

static void copy_field_varstring ( Field_varstring *const  to,
const Field_varstring *const  from 
)
static

A variable length string field consists of: (a) 1 or 2 length bytes, depending on the VARCHAR column definition (b) as many relevant character bytes, as defined in the length byte(s) (c) unused padding up to the full length of the column.

This function only copies (a) and (b)

Condition for using this function: to and from must use the same number of bytes for length, i.e: to->length_bytes==from->length_bytes

Parameters
toVariable length field we're copying to
fromVariable length field we're copying from

◆ copy_time_to_time()

type_conversion_status copy_time_to_time ( const Field from,
Field to 
)
inline

◆ do_conv_blob()

static void do_conv_blob ( Copy_field copy,
const Field from_field,
Field to_field 
)
static

◆ do_copy_blob()

static void do_copy_blob ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ do_copy_maybe_null()

static void do_copy_maybe_null ( Copy_field copy,
const Field from_field,
Field to_field 
)
static

◆ do_copy_next_number()

static void do_copy_next_number ( Copy_field copy,
const Field from_field,
Field to_field 
)
static

◆ do_copy_not_null()

static void do_copy_not_null ( Copy_field copy,
const Field from_field,
Field to_field 
)
static

◆ do_copy_null()

static void do_copy_null ( Copy_field copy,
const Field from_field,
Field to_field 
)
static

◆ do_copy_timestamp()

static void do_copy_timestamp ( Copy_field copy,
const Field from_field,
Field to_field 
)
static

◆ do_cut_string()

static void do_cut_string ( Copy_field ,
const Field from_field,
Field to_field 
)
static

string copy for single byte characters set when to string is shorter than from string.

◆ do_cut_string_complex()

static void do_cut_string_complex ( Copy_field ,
const Field from_field,
Field to_field 
)
static

string copy for multi byte characters set when to string is shorter than from string.

◆ do_expand_binary()

static void do_expand_binary ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ do_expand_string()

static void do_expand_string ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ do_field_decimal()

static void do_field_decimal ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ do_field_enum()

static void do_field_enum ( Copy_field copy,
const Field from_field,
Field to_field 
)
static

◆ do_field_eq()

static void do_field_eq ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ do_field_int()

static void do_field_int ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ do_field_real()

static void do_field_real ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ do_field_string()

static void do_field_string ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ do_field_time()

static void do_field_time ( Copy_field ,
const Field from_field,
Field to_field 
)
static

Convert between fields using time representation.

◆ do_field_to_null_str()

static void do_field_to_null_str ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ do_field_varbinary_pre50()

static void do_field_varbinary_pre50 ( Copy_field copy,
const Field from_field,
Field to_field 
)
static

◆ do_save_blob()

static void do_save_blob ( Copy_field copy,
const Field from_field,
Field to_field 
)
static

Save blob in copy->tmp for GROUP BY.

◆ do_save_json()

static void do_save_json ( Copy_field ,
const Field from_field,
Field to_field 
)
static

Copy the contents of one Field_json into another Field_json.

◆ do_skip()

static void do_skip ( Copy_field ,
const Field ,
Field  
)
static

◆ do_varstring()

static void do_varstring ( Copy_field ,
const Field from_field,
Field to_field 
)
static

◆ field_conv()

type_conversion_status field_conv ( Field to,
const Field from 
)

Simple quick field convert that is called on insert.

◆ get_varstring_copy_length()

static size_t get_varstring_copy_length ( Field_varstring to,
const Field_varstring from 
)
static

Find how many bytes should be copied between Field_varstring fields so that only the bytes in use in the 'from' field are copied.

Handles single and multi-byte charsets. Adds warning if not all bytes in 'from' will fit into 'to'.

Parameters
toVariable length field we're copying to
fromVariable length field we're copying from
Returns
Number of bytes that should be copied from 'from' to 'to'.

◆ is_blob_type()

static bool is_blob_type ( Field to)
inlinestatic

◆ is_subtype_of()

static bool is_subtype_of ( Field::geometry_type  sub,
Field::geometry_type  super 
)
inlinestatic

Check if geometry type sub is a subtype of super.

Parameters
subThe type to check
superThe supertype
Returns
True if sub is a subtype of super

◆ set_field_to_null()

type_conversion_status set_field_to_null ( Field field)

The following piece of code is run for the case when a BLOB column that has value NULL is queried with GROUP BY NULL and the result is inserted into a some table's column declared having primitive type (e.g. INT) and NOT NULL.

For example, the following test case will hit this piece of code: CREATE TABLE t1 (a BLOB); CREATE TABLE t2 (a INT NOT NULL);

INSERT t1 VALUES (NULL); INSERT INTO t2(a) SELECT a FROM t1 GROUP BY NULL; <<== Hit here

In general, when set_field_to_null() is called a Field has to be either declared as NULL-able or be marked as temporary NULL-able. But in case of INSERT SELECT from a BLOB field and when GROUP BY NULL is specified the Field object for a destination column doesn't set neither NULL-able nor temporary NULL-able (see setup_copy_fields()).

◆ set_field_to_null_with_conversions()

type_conversion_status set_field_to_null_with_conversions ( Field field,
bool  no_conversions 
)

Set field to NULL or TIMESTAMP or to next auto_increment number.

Parameters
fieldField to update
no_conversionsSet to 1 if we should return 1 if field can't take null values. If set to 0 we will do store the 'default value' if the field is a special field. If not we will give an error.
Return values
0Field could take 0 or an automatic conversion was used
-1Field could not take NULL and no conversion was used. If no_conversion was not set, an error message is printed

◆ set_to_is_null()

static void set_to_is_null ( Field to_field,
bool  is_null 
)
static