MySQL  8.0.17
Source Code Documentation
Field_json Class Reference

A field that stores a JSON value. More...

#include <field.h>

Inheritance diagram for Field_json:
Field_blob Field_longstr Field_str Field Proto_field Field_typed_array

Public Member Functions

 Field_json (uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, TABLE_SHARE *share, uint blob_pack_length)
 
 Field_json (uint32 len_arg, bool maybe_null_arg, const char *field_name_arg)
 
enum_field_types type () const override
 
void sql_type (String &str) const override
 Get the type of this field (json). More...
 
const CHARSET_INFOcharset () const override
 Return a text charset so that string functions automatically convert the field value to string and treat it as a non-binary string. More...
 
const CHARSET_INFOsort_charset () const final override
 Sort should treat the field as binary and not attempt any conversions. More...
 
bool has_charset () const final override
 JSON columns don't have an associated charset. More...
 
type_conversion_status store (const char *to, size_t length, const CHARSET_INFO *charset) override
 Store data in this JSON field. More...
 
type_conversion_status store (double nr) override
 Store a double in a JSON field. Will raise an error for now. More...
 
type_conversion_status store (longlong nr, bool unsigned_val) override
 Store an integer in a JSON field. Will raise an error for now. More...
 
type_conversion_status store_decimal (const my_decimal *) final override
 Store a decimal in a JSON field. Will raise an error for now. More...
 
virtual type_conversion_status store_json (const Json_wrapper *json)
 Store a JSON value as binary. More...
 
type_conversion_status store_time (MYSQL_TIME *ltime, uint8 dec_arg) final override
 Store a TIME value in a JSON field. Will raise an error for now. More...
 
type_conversion_status store (Field_json *field)
 Copy the contents of a non-null JSON field into this field. More...
 
bool pack_diff (uchar **to, ulonglong value_options) const final override
 Write the field for the binary log in diff format. More...
 
longlong get_diff_vector_and_length (ulonglong value_options, const Json_diff_vector **diff_vector_p=nullptr) const
 Return the length of this field, taking into consideration that it may be in partial format. More...
 
bool is_before_image_equal_to_after_image () const
 Return true if the before-image and after-image for this field are equal. More...
 
bool unpack_diff (const uchar **from)
 Read the binary diff from the given buffer, and apply it to this field. More...
 
bool val_json (Json_wrapper *wr) const
 Retrieve the field's value as a JSON wrapper. More...
 
longlong val_int () const final override
 Retrieve the JSON as an int if possible. More...
 
double val_real () const final override
 
Retrieve the JSON as a double if possible. More...
 
Stringval_str (String *buf1, String *buf2) const final override
 Retrieve the JSON value stored in this field as text. More...
 
my_decimalval_decimal (my_decimal *m) const final override
 
bool get_time (MYSQL_TIME *ltime) const final override
 
bool get_date (MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const final override
 
Field_jsonclone (MEM_ROOT *mem_root) const override
 Create a shallow clone of this field in the specified MEM_ROOT. More...
 
Field_jsonclone () const override
 Create a shallow clone of this field. More...
 
uint is_equal (const Create_field *new_field) const final override
 Check if a new field is compatible with this one. More...
 
Item_result cast_to_int_type () const final override
 
int cmp_binary (const uchar *a, const uchar *b, uint32 max_length=~0L) const final override
 
bool sort_key_is_varlen () const final override
 Returns whether make_sort_key() writes variable-length sort keys, ie., whether it can return fewer bytes than it's asked for. More...
 
size_t make_sort_key (uchar *to, size_t length) const override
 Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comparison. More...
 
ulonglong make_hash_key (ulonglong hash_val)
 Make a hash key that can be used by sql_executor.cc/unique_hash in order to support SELECT DISTINCT. More...
 
const char * get_binary (ptrdiff_t row_offset=0) const
 Get a read-only pointer to the binary representation of the JSON document in this field. More...
 
- Public Member Functions inherited from Field_blob
 Field_blob (uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, TABLE_SHARE *share, uint blob_pack_length, const CHARSET_INFO *cs)
 
 Field_blob (uint32 len_arg, bool maybe_null_arg, const char *field_name_arg, const CHARSET_INFO *cs, bool set_packlength)
 
 Field_blob (uint32 packlength_arg)
 
bool match_collation_to_optimize_range () const override
 
enum ha_base_keytype key_type () const override
 
int cmp_max (const uchar *, const uchar *, uint max_length) const final override
 
int cmp (const uchar *a, const uchar *b) const final override
 
int cmp (const uchar *a, uint32 a_length, const uchar *b, uint32 b_length) const
 
int key_cmp (const uchar *, const uchar *) const override
 
int key_cmp (const uchar *str, uint length) const override
 
uint32 key_length () const override
 
uint32 pack_length () const final override
 
uint32 pack_length_no_ptr () const
 Return the packed length without the pointer size added. More...
 
uint row_pack_length () const final override
 
uint32 sort_length () const final override
 
uint32 max_data_length () const final override
 Get the maximum size of the data in packed format. More...
 
type_conversion_status reset () override
 
void reset_fields () final override
 
size_t get_field_buffer_size ()
 
void store_length (uchar *i_ptr, uint i_packlength, uint32 i_number)
 
void store_length (uint32 number)
 
uint32 data_length (ptrdiff_t row_offset=0) const final override
 
uint32 get_length (ptrdiff_t row_offset=0) const
 
uint32 get_length (const uchar *ptr, uint packlength, bool low_byte_first) const
 
uint32 get_length (const uchar *ptr_arg) const
 
const ucharget_ptr () const final override
 Get a const pointer to the BLOB data of this field. More...
 
ucharget_blob_data (ptrdiff_t row_offset=0)
 Get a non-const pointer to the BLOB data of this field. More...
 
void set_ptr (const uchar *length, const uchar *data)
 
void set_ptr_offset (ptrdiff_t ptr_diff, uint32 length, const uchar *data)
 
void set_ptr (uint32 length, const uchar *data)
 
size_t get_key_image (uchar *buff, size_t length, imagetype type) const override
 
void set_key_image (const uchar *buff, size_t length) final override
 
bool copy ()
 
ucharpack (uchar *to, const uchar *from, uint max_length, bool low_byte_first) const final override
 Pack the field into a format suitable for storage and transfer. More...
 
const ucharunpack (uchar *, const uchar *from, uint param_data, bool low_byte_first) final override
 Unpack a blob field from row data. More...
 
uint max_packed_col_length () final override
 This is a wrapper around pack_length() used by filesort() to determine how many bytes we need for packing "addon fields". More...
 
void mem_free () final override
 
uint32 max_display_length () const final override
 maximum possible display length for blob. More...
 
uint32 char_length () const override
 maximum possible character length for blob. More...
 
bool copy_blob_value (MEM_ROOT *mem_root)
 This function creates a separate copy of blob value. More...
 
bool is_text_key_type () const final override
 
void set_keep_old_value (bool old_value_flag)
 Mark that the BLOB stored in value should be copied before updating it. More...
 
void keep_old_value ()
 Save the current BLOB value to avoid that it gets overwritten. More...
 
void store_in_allocated_space (const char *from, uint32 length)
 Use to store the blob value into an allocated space. More...
 
bool backup_blob_field ()
 Backup data stored in 'value' into the backup_value. More...
 
void restore_blob_backup ()
 Restore backup value. More...
 
- Public Member Functions inherited from Field_longstr
 Field_longstr (uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, const CHARSET_INFO *charset_arg)
 
bool is_updatable () const final override
 Checks whether a string field is part of write_set. More...
 
- Public Member Functions inherited from Field_str
 Field_str (uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, const CHARSET_INFO *charset)
 
Item_result result_type () const override
 
Item_result numeric_context_result_type () const final override
 Returns Item_result type of a field when it appears in numeric context such as: SELECT time_column + 1; SELECT SUM(time_column); Examples: More...
 
uint decimals () const override
 
void make_field (Send_field *field) const final override
 
uint repertoire () const final override
 
void set_charset (const CHARSET_INFO *charset_arg)
 
void set_field_length (uint32 length) final override
 
enum Derivation derivation () const final override
 
void set_derivation (enum Derivation derivation_arg) final override
 
bool binary () const override
 
bool str_needs_quotes () const final override
 
- Public Member Functions inherited from Field
 Field (const Field &)=default
 
void operator= (Field &)=delete
 
bool has_insert_default_general_value_expression () const
 Checks if the field is marked as having a general expression to generate default values. More...
 
bool has_insert_default_datetime_value_expression () const
 Checks if the field is marked as having a datetime value expression to generate default values on inserts. More...
 
bool has_update_default_datetime_value_expression () const
 Checks if the field is marked as having a datetime value expression to generate default values on updates. More...
 
bool is_gcol () const
 
bool is_virtual_gcol () const
 
void set_hidden (dd::Column::enum_hidden_type hidden)
 Sets the hidden type for this field. More...
 
dd::Column::enum_hidden_type hidden () const
 
bool is_hidden_from_user () const
 
bool is_field_for_functional_index () const
 
 Field (uchar *ptr_arg, uint32 length_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg)
 This is used as a table name when the table structure is not set up. More...
 
 ~Field () override
 
void reset_warnings ()
 
void set_tmp_nullable ()
 Turn on temporary nullability for the field. More...
 
void reset_tmp_nullable ()
 Turn off temporary nullability for the field. More...
 
void reset_tmp_null ()
 Reset temporary NULL value for field. More...
 
void set_tmp_null ()
 Set field to temporary value NULL. More...
 
bool is_tmp_nullable () const
 
bool is_tmp_null () const
 
virtual type_conversion_status store_packed (longlong nr)
 Store a temporal value in packed longlong format into a field. More...
 
type_conversion_status store_time (MYSQL_TIME *ltime)
 Store MYSQL_TYPE value into a field when the number of fractional digits is not important or is not know. More...
 
type_conversion_status store (const char *to, size_t length, const CHARSET_INFO *cs, enum_check_fields check_level)
 
virtual longlong val_time_temporal () const
 Returns TIME value in packed longlong format. More...
 
virtual longlong val_date_temporal () const
 Returns DATE/DATETIME value in packed longlong format. More...
 
longlong val_temporal_by_field_type () const
 Returns "native" packed longlong representation of a TIME or DATE/DATETIME field depending on field type. More...
 
Stringval_str (String *str) const
 
Stringval_int_as_str (String *val_buffer, bool unsigned_flag) const
 Interpret field value as an integer but return the result as a string. More...
 
virtual Item_result cmp_type () const
 
bool gcol_expr_is_equal (const Create_field *field) const
 Check whether generated columns' expressions are the same. More...
 
virtual bool eq (Field *field) const
 
virtual bool eq_def (const Field *field) const
 
virtual uint32 pack_length_in_rec () const
 
virtual bool compatible_field_size (uint metadata, Relay_log_info *, uint16, int *order) const
 Check to see if field size is compatible with destination. More...
 
virtual uint pack_length_from_metadata (uint field_metadata) const
 
virtual int save_field_metadata (uchar *first_byte)
 
virtual bool get_timestamp (struct timeval *tm, int *warnings) const
 Returns timestamp value in "struct timeval" format. More...
 
virtual void store_timestamp (const timeval *)
 
Stores a timestamp value in timeval format in a field. More...
 
virtual void set_default ()
 
void evaluate_insert_default_function ()
 Evaluates the INSERT default function and stores the result in the field. More...
 
void evaluate_update_default_function ()
 Evaluates the UPDATE default function, if one exists, and stores the result in the record buffer. More...
 
virtual bool zero_pack () const
 
enum_field_types data_type () const
 For template-compatibility with Item. More...
 
virtual enum_field_types real_type () const
 
virtual enum_field_types binlog_type () const
 
int cmp (const uchar *str) const
 
virtual int cmp_offset (ptrdiff_t row_offset) const
 
virtual int cmp_binary_offset (ptrdiff_t row_offset) const
 
bool is_temporal () const
 
bool is_temporal_with_date () const
 
bool is_temporal_with_time () const
 
bool is_temporal_with_date_and_time () const
 
bool is_null (ptrdiff_t row_offset=0) const
 Check whether the full table's row is NULL or the Field has value NULL. More...
 
bool is_null_value () const
 For template-compatibility with Item. More...
 
bool update_null_value ()
 Same as above. Not actually used. More...
 
bool is_real_null (ptrdiff_t row_offset=0) const
 Check whether the Field has value NULL (temporary or actual). More...
 
bool is_null_in_record (const uchar *record) const
 Check if the Field has value NULL or the record specified by argument has value NULL for this Field. More...
 
void set_null (ptrdiff_t row_offset=0)
 Set field to value NULL. More...
 
void set_notnull (ptrdiff_t row_offset=0)
 Set field to value NOT NULL. More...
 
type_conversion_status check_constraints (int mysql_errno)
 Check NOT NULL constraint on the field after temporary nullability is disabled. More...
 
void set_check_for_truncated_fields (enum_check_fields check_for_truncated_fields)
 Remember the value of THD::check_for_truncated_fields to handle possible NOT-NULL constraint errors after BEFORE-trigger execution is finished. More...
 
bool maybe_null () const
 
bool real_maybe_null () const
 
uint null_offset (const uchar *record) const
 
uint null_offset () const
 
void set_null_ptr (uchar *p_null_ptr, uint p_null_bit)
 
size_t last_null_byte () const
 
virtual bool optimize_range (uint idx, uint part) const
 
virtual bool can_be_compared_as_longlong () const
 
virtual Fieldnew_field (MEM_ROOT *root, TABLE *new_table, bool keep_type) const
 
virtual Fieldnew_key_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uchar *new_null_ptr, uint new_null_bit) const
 
Fieldnew_key_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr)
 
void move_field (uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg)
 
void move_field (uchar *ptr_arg)
 
virtual void move_field_offset (ptrdiff_t ptr_diff)
 
virtual void get_image (uchar *buff, size_t length, const CHARSET_INFO *) const
 
virtual void set_image (const uchar *buff, size_t length, const CHARSET_INFO *)
 
longlong val_int_offset (ptrdiff_t row_offset)
 
longlong val_int (uchar *new_ptr)
 
Stringval_str (String *str, uchar *new_ptr)
 
bool send_binary (Protocol *protocol) const override
 
bool send_text (Protocol *protocol) const final override
 
ucharpack (uchar *to, const uchar *from) const
 
const ucharunpack (uchar *to, const uchar *from)
 
uint offset (uchar *record) const
 
void copy_data (ptrdiff_t src_record_offset)
 
uint fill_cache_field (CACHE_FIELD *copy)
 
virtual const CHARSET_INFOcharset_for_protocol () const
 
bool set_warning (Sql_condition::enum_severity_level level, unsigned int code, int cut_increment)
 Produce warning or note about data saved into field. More...
 
bool set_warning (Sql_condition::enum_severity_level level, uint code, int cut_increment, const char *view_db, const char *view_name)
 Produce warning or note about data saved into field. More...
 
bool check_overflow (int op_result)
 
bool check_truncated (int op_result)
 
bool warn_if_overflow (int op_result)
 Process decimal library return codes and issue warnings for overflow and truncation. More...
 
virtual void init (TABLE *table_arg)
 
longlong convert_decimal2longlong (const my_decimal *val, bool unsigned_flag, bool *has_overflow)
 Conversion from decimal to longlong. More...
 
virtual geometry_type get_geometry_type () const
 
void dbug_print ()
 
ha_storage_media field_storage_type () const
 
void set_storage_type (ha_storage_media storage_type_arg)
 
column_format_type column_format () const
 
void set_column_format (column_format_type column_format_arg)
 
virtual type_conversion_status validate_stored_val (THD *thd)
 
virtual void hash (ulong *nr, ulong *nr2) const
 
virtual ulonglong get_max_int_value () const
 Get the upper limit of the MySQL integral and floating-point type. More...
 
bool is_part_of_actual_key (THD *thd, uint cur_index, KEY *cur_index_info)
 Check whether field is part of the index taking the index extensions flag into account. More...
 
Key_map get_covering_prefix_keys ()
 Get covering prefix keys. More...
 
virtual bool is_array () const
 Whether the field is a typed array. More...
 
virtual uint32 get_length_bytes () const
 Return number of bytes the field's length takes. More...
 
bool handle_old_value ()
 Whether field's old valued have to be handled. More...
 
- Public Member Functions inherited from Proto_field
 Proto_field ()=default
 
virtual ~Proto_field ()=default
 
 Proto_field (const Proto_field &)=default
 

Private Member Functions

type_conversion_status unsupported_conversion ()
 Helper function for raising an error when trying to store a value into a JSON column, and that value needs to be cast to JSON before it can be stored. More...
 
type_conversion_status store_binary (const char *ptr, size_t length)
 Store the provided JSON binary data in this field. More...
 
void invalid_text (const char *err, size_t err_offset) const
 Diagnostics utility for ER_INVALID_JSON_TEXT. More...
 

Additional Inherited Members

- Public Types inherited from Field
enum  enum_auto_flags {
  NONE = 0, NEXT_NUMBER = 1, DEFAULT_NOW = 2, ON_UPDATE_NOW = 4,
  GENERATED_FROM_EXPRESSION = 8
}
 Flags for Proto_field::auto_flags / Create_field::auto_flags bitmaps. More...
 
enum  geometry_type {
  GEOM_GEOMETRY = 0, GEOM_POINT = 1, GEOM_LINESTRING = 2, GEOM_POLYGON = 3,
  GEOM_MULTIPOINT = 4, GEOM_MULTILINESTRING = 5, GEOM_MULTIPOLYGON = 6, GEOM_GEOMETRYCOLLECTION = 7
}
 
enum  imagetype { itRAW, itMBR }
 
enum  { LAST_NULL_BYTE_UNDEF = 0 }
 
- Static Public Member Functions inherited from Field
static bool type_can_have_key_part (enum_field_types)
 Check whether a field type can be partially indexed by a key. More...
 
static enum_field_types field_type_merge (enum_field_types, enum_field_types)
 Return type of which can carry value of both given types in UNION result. More...
 
static Item_result result_merge_type (enum_field_types)
 Detect Item_result by given field type of UNION merge result. More...
 
- Public Attributes inherited from Field_str
uint32 char_length_cache
 
- Public Attributes inherited from Field
ucharptr
 Holds the position to the field in record. More...
 
TABLEtable
 
TABLEorig_table
 
const char ** table_name
 
const char * field_name
 
LEX_CSTRING comment
 
Key_map key_start
 
Key_map part_of_key
 Keys that includes this field except of prefix keys. More...
 
Key_map part_of_prefixkey
 Prefix keys. More...
 
Key_map part_of_sortkey
 
Key_map part_of_key_not_extended
 All keys that include this field, but not extended by the storage engine to include primary key columns. More...
 
uint32 field_length
 
uint32 flags
 
uint16 field_index
 
uchar null_bit
 
uchar auto_flags
 Bitmap of flags indicating if field value is auto-generated by default and/or on update, and in which way. More...
 
bool is_created_from_null_item
 If true, this field was created in create_tmp_field_from_item from a NULL value. More...
 
bool m_indexed
 True if this field belongs to some index (unlike part_of_key, the index might have only a prefix). More...
 
Value_generatorgcol_info {nullptr}
 
bool stored_in_db
 
bool unsigned_flag
 Whether the field is signed or not. More...
 
Value_generatorm_default_val_expr {nullptr}
 Holds the expression to be used to generate default values. More...
 
- Protected Member Functions inherited from Field_blob
void store_ptr_and_length (const char *from, uint32 length)
 Store ptr and length. More...
 
- Protected Member Functions inherited from Field_longstr
type_conversion_status check_string_copy_error (const char *well_formed_error_pos, const char *cannot_convert_error_pos, const char *from_end_pos, const char *end, bool count_spaces, const CHARSET_INFO *cs)
 Report "not well formed" or "cannot convert" error after storing a character string info a field. More...
 
- Protected Member Functions inherited from Field
const ucharget_null_ptr () const
 
ucharget_null_ptr ()
 
ucharpack_int16 (uchar *to, const uchar *from, uint max_length, bool low_byte_first_to) const
 
const ucharunpack_int16 (uchar *to, const uchar *from, bool low_byte_first_from) const
 
ucharpack_int24 (uchar *to, const uchar *from, uint max_length, bool low_byte_first_to) const
 
const ucharunpack_int24 (uchar *to, const uchar *from, bool low_byte_first_from) const
 
ucharpack_int32 (uchar *to, const uchar *from, uint max_length, bool low_byte_first_to) const
 
const ucharunpack_int32 (uchar *to, const uchar *from, bool low_byte_first_from) const
 
ucharpack_int64 (uchar *to, const uchar *from, uint max_length, bool low_byte_first_to) const
 
const ucharunpack_int64 (uchar *to, const uchar *from, bool low_byte_first_from) const
 
- Protected Attributes inherited from Field_blob
uint packlength
 The number of bytes used to represent the length of the blob. More...
 
String value
 The 'value'-object is a cache fronting the storage engine. More...
 
- Protected Attributes inherited from Field_str
const CHARSET_INFOfield_charset
 
enum Derivation field_derivation
 
- Static Protected Attributes inherited from Field
static uchar dummy_null_buffer = ' '
 

Detailed Description

A field that stores a JSON value.

Constructor & Destructor Documentation

◆ Field_json() [1/2]

Field_json::Field_json ( uchar ptr_arg,
uchar null_ptr_arg,
uint  null_bit_arg,
uchar  auto_flags_arg,
const char *  field_name_arg,
TABLE_SHARE share,
uint  blob_pack_length 
)
inline

◆ Field_json() [2/2]

Field_json::Field_json ( uint32  len_arg,
bool  maybe_null_arg,
const char *  field_name_arg 
)
inline

Member Function Documentation

◆ cast_to_int_type()

Item_result Field_json::cast_to_int_type ( ) const
inlinefinaloverridevirtual

Reimplemented from Field.

◆ charset()

const CHARSET_INFO* Field_json::charset ( ) const
inlineoverridevirtual

Return a text charset so that string functions automatically convert the field value to string and treat it as a non-binary string.

Reimplemented from Field_str.

Reimplemented in Field_typed_array.

◆ clone() [1/2]

Field_json * Field_json::clone ( MEM_ROOT mem_root) const
overridevirtual

Create a shallow clone of this field in the specified MEM_ROOT.

Reimplemented from Field_blob.

Reimplemented in Field_typed_array.

◆ clone() [2/2]

Field_json * Field_json::clone ( ) const
overridevirtual

Create a shallow clone of this field.

Reimplemented from Field_blob.

Reimplemented in Field_typed_array.

◆ cmp_binary()

int Field_json::cmp_binary ( const uchar a,
const uchar b,
uint32  max_length = ~0L 
) const
finaloverridevirtual

Reimplemented from Field_blob.

◆ get_binary()

const char * Field_json::get_binary ( ptrdiff_t  row_offset = 0) const

Get a read-only pointer to the binary representation of the JSON document in this field.

Parameters
row_offsetField's data offset

◆ get_date()

bool Field_json::get_date ( MYSQL_TIME ltime,
my_time_flags_t  fuzzydate 
) const
finaloverridevirtual

Reimplemented from Field.

◆ get_diff_vector_and_length()

longlong Field_json::get_diff_vector_and_length ( ulonglong  value_options,
const Json_diff_vector **  diff_vector_p = nullptr 
) const

Return the length of this field, taking into consideration that it may be in partial format.

This is the format used when writing the binary log in row format and using a partial format according to @session.binlog_row_value_options.

Parameters
[in]value_optionsThe value of binlog_row_value options.
[out]diff_vector_pIf this is not NULL, the pointer it points to will be set to NULL if the field is to be stored in full format, or to the Json_diff_vector if the field is to be stored in partial format.
Returns
The number of bytes needed when writing to the binlog: the size of the full format if stored in full format and the size of the diffs if stored in partial format.

◆ get_time()

bool Field_json::get_time ( MYSQL_TIME ltime) const
finaloverridevirtual

Reimplemented from Field.

◆ has_charset()

bool Field_json::has_charset ( ) const
inlinefinaloverridevirtual

JSON columns don't have an associated charset.

Returning false here prevents SHOW CREATE TABLE from attaching a CHARACTER SET clause to the column.

Reimplemented from Field_blob.

◆ invalid_text()

void Field_json::invalid_text ( const char *  err,
size_t  err_offset 
) const
inlineprivate

Diagnostics utility for ER_INVALID_JSON_TEXT.

Parameters
errerror message argument for ER_INVALID_JSON_TEXT
err_offsetlocation in text at which there is an error

◆ is_before_image_equal_to_after_image()

bool Field_json::is_before_image_equal_to_after_image ( ) const

Return true if the before-image and after-image for this field are equal.

◆ is_equal()

uint Field_json::is_equal ( const Create_field new_field) const
finaloverridevirtual

Check if a new field is compatible with this one.

Parameters
new_fieldthe new field
Returns
true if new_field is compatible with this field, false otherwise

Reimplemented from Field_blob.

◆ make_hash_key()

ulonglong Field_json::make_hash_key ( ulonglong  hash_val)

Make a hash key that can be used by sql_executor.cc/unique_hash in order to support SELECT DISTINCT.

Parameters
[in]hash_valAn initial hash value.

◆ make_sort_key()

size_t Field_json::make_sort_key ( uchar buff,
size_t  length 
) const
overridevirtual

Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comparison.

Integers are always in big-endian regardless of hardware architecture. At most length bytes are written into the buffer.

Parameters
buffThe buffer, assumed to be at least length bytes.
lengthNumber of bytes to write.
Return values
Thenumber of bytes actually written. Note that unless sort_key_is_varlen() returns true, this must be exactly the same as length.

Reimplemented from Field_blob.

Reimplemented in Field_typed_array.

◆ pack_diff()

bool Field_json::pack_diff ( uchar **  to,
ulonglong  value_options 
) const
finaloverridevirtual

Write the field for the binary log in diff format.

This should only write the field if the diff format is smaller than the full format. Otherwise it should leave the buffer untouched.

Parameters
[in,out]toPointer to buffer where the field will be written. This will be changed to point to the next byte after the last byte that was written.
value_optionsbitmap that indicates if full or partial JSON format is to be used.
Return values
trueThe field was not written, either because the data type does not support it, or because it was disabled according to value_options, or because there was no diff information available from the optimizer, or because the the diff format was bigger than the full format. The 'to' parameter is unchanged in this case.
falseThe field was written.

Reimplemented from Field.

◆ sort_charset()

const CHARSET_INFO* Field_json::sort_charset ( ) const
inlinefinaloverridevirtual

Sort should treat the field as binary and not attempt any conversions.

Reimplemented from Field.

◆ sort_key_is_varlen()

bool Field_json::sort_key_is_varlen ( ) const
inlinefinaloverridevirtual

Returns whether make_sort_key() writes variable-length sort keys, ie., whether it can return fewer bytes than it's asked for.

Reimplemented from Field_blob.

◆ sql_type()

void Field_json::sql_type ( String str) const
overridevirtual

Get the type of this field (json).

Parameters
strthe string that receives the type

Reimplemented from Field_blob.

Reimplemented in Field_typed_array.

◆ store() [1/4]

type_conversion_status Field_json::store ( const char *  from,
size_t  length,
const CHARSET_INFO cs 
)
overridevirtual

Store data in this JSON field.

JSON data is usually stored using store(Field_json*) or store_json(), so this function will only be called if non-JSON data is attempted stored in a JSON field. This results in an error in most cases.

It will attempt to parse the string (unless it's binary) as JSON text, and store a binary representation of JSON document if the string could be parsed.

Note that we override store() and not store_internal() because Field_blob::store() contains logic that bypasses store_internal() in some cases we care about. In particular:

  • When supplied an empty string, we want to raise a JSON syntax error instead of silently inserting an empty byte string.
  • When called from GROUP_CONCAT with ORDER BY or DISTINCT, we want to do the same data conversion as usual, whereas Field_blob::store() jumps directly to Field_blob::store_to_mem() with the unprocessed input data.
Parameters
fromthe start of the data to be stored
lengththe length of the data
csthe character set of the data
Returns
zero on success, non-zero on failure

Reimplemented from Field_blob.

Reimplemented in Field_typed_array.

◆ store() [2/4]

type_conversion_status Field_json::store ( double  nr)
overridevirtual

Store a double in a JSON field. Will raise an error for now.

Reimplemented from Field_blob.

Reimplemented in Field_typed_array.

◆ store() [3/4]

type_conversion_status Field_json::store ( longlong  nr,
bool  unsigned_val 
)
overridevirtual

Store an integer in a JSON field. Will raise an error for now.

Reimplemented from Field_blob.

Reimplemented in Field_typed_array.

◆ store() [4/4]

type_conversion_status Field_json::store ( Field_json field)

Copy the contents of a non-null JSON field into this field.

Parameters
[in]fieldthe field to copy data from
Returns
zero on success, non-zero on failure

◆ store_binary()

type_conversion_status Field_json::store_binary ( const char *  data,
size_t  length 
)
private

Store the provided JSON binary data in this field.

Parameters
[in]datapointer to JSON binary data
[in]lengththe length of the binary data
Returns
zero on success, non-zero on failure

◆ store_decimal()

type_conversion_status Field_json::store_decimal ( const my_decimal )
finaloverridevirtual

Store a decimal in a JSON field. Will raise an error for now.

Reimplemented from Field_longstr.

◆ store_json()

type_conversion_status Field_json::store_json ( const Json_wrapper json)
virtual

Store a JSON value as binary.

Parameters
jsonthe JSON value to store
Returns
zero on success, non-zero otherwise

Reimplemented in Field_typed_array.

◆ store_time()

type_conversion_status Field_json::store_time ( MYSQL_TIME ltime,
uint8  dec_arg 
)
finaloverridevirtual

Store a TIME value in a JSON field. Will raise an error for now.

Reimplemented from Field.

◆ type()

enum_field_types Field_json::type ( ) const
inlineoverridevirtual

Reimplemented from Field_blob.

Reimplemented in Field_typed_array.

◆ unpack_diff()

bool Field_json::unpack_diff ( const uchar **  from)

Read the binary diff from the given buffer, and apply it to this field.

Parameters
[in,out]fromPointer to buffer where the binary diff is stored. This will be changed to point to the next byte after the field.
Return values
falseSuccess
trueError (e.g. failed to apply the diff). The error has been reported through my_error.

◆ unsupported_conversion()

type_conversion_status Field_json::unsupported_conversion ( )
private

Helper function for raising an error when trying to store a value into a JSON column, and that value needs to be cast to JSON before it can be stored.

◆ val_decimal()

my_decimal * Field_json::val_decimal ( my_decimal m) const
finaloverridevirtual

Reimplemented from Field_blob.

◆ val_int()

longlong Field_json::val_int ( void  ) const
finaloverridevirtual

Retrieve the JSON as an int if possible.

This requires a JSON scalar of suitable type.

Returns
the JSON value as an int

Reimplemented from Field_blob.

◆ val_json()

bool Field_json::val_json ( Json_wrapper wr) const

Retrieve the field's value as a JSON wrapper.

It there is an error, wr is not modified and we return false, else true.

Parameters
[out]wrthe JSON value
Returns
true if a value is retrieved (or NULL), false if error

◆ val_real()

double Field_json::val_real ( void  ) const
finaloverridevirtual


Retrieve the JSON as a double if possible.

This requires a JSON scalar of suitable type.

Returns
the JSON value as a double

Reimplemented from Field_blob.

◆ val_str()

String * Field_json::val_str ( String buf1,
String buf2 
) const
finaloverridevirtual

Retrieve the JSON value stored in this field as text.

Parameters
[in,out]buf1string buffer for converting JSON value to string
[in,out]buf2unused

Reimplemented from Field_blob.


The documentation for this class was generated from the following files: