File: default_values.h

package info (click to toggle)
mysql-8.0 8.0.44-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,272,892 kB
  • sloc: cpp: 4,685,345; ansic: 412,712; pascal: 108,395; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; python: 21,816; sh: 17,285; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,083; makefile: 1,793; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (115 lines) | stat: -rw-r--r-- 4,608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* Copyright (c) 2015, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#ifndef DEFAULT_VALUES_INCLUDED
#define DEFAULT_VALUES_INCLUDED

#include <stddef.h>

#include "my_inttypes.h"

/** Forward declarations. */

class Create_field;
class THD;
template <class T>
class List;

namespace dd {
class Column;
class Table;
}  // namespace dd
struct TABLE;
struct TABLE_SHARE;

/**
  Find the largest field among a list of create fields.

  Iterates over the list of create fields and find the largest one, i.e.
  the field with largest pack length.

  @param   create_fields    List of create fields.
  @return                   Size of the largest field, as number of bytes.
*/

size_t max_pack_length(const List<Create_field> &create_fields);

/**
  Prepare the default value of a single column.

  This function creates a fake field using the submitted fake table
  object, which also has assigned a fake table share. The field is
  create in order to use existing code to store the default value. The
  value is stored into the submitted buffer, which has been allocated
  in advance (and will be deleted afterwards). The fake table and
  share are required by the field infrastructure.

  After storing the default value into the buffer, the value is read back
  and copied into the column object's default value field. For bit fields
  with leftover bits in the preamble, these bits are copied and appended
  onto the default value as the last byte.

  @param          thd       Thread context.
  @param          buf       Buffer to store the default value into. The buffer
                            size must be at least two bytes.
  @param          table     Fake table to use when storing the default value.
  @param          field     Create_field corresponding to the column object.
  @param [in,out] col_obj   Column for which to prepare the default value.

  @retval         true      Failure.
  @retval         false     Success.
*/

bool prepare_default_value(THD *thd, uchar *buf, TABLE *table,
                           const Create_field &field, dd::Column *col_obj);

/**
  Prepare the default value buffer for an empty record.

  This function prepares the buffer based on the objects retrieved from the
  data dictionary. The function will scan the columns of the submitted table
  objects and calculate the length of the record, the number of null bits,
  etc. The empty buffer is allocated, and all bits are set to 0, including
  used null bits, the actual field values, etc. Afterwards, the unused bits
  in the preamble, up to the next full byte border, are set to 1. Finally,
  the buffer is assigned to the 'TABLE_SHARE::default_values' field.

 @note This function does not fill in the actual default values, it just
        allocates and prepares the buffer.

  @param          thd          Thread context.
  @param          table        Table for which the default value buffer should
                               be prepared.
  @param [in,out] share        Table share for the table. The default value
                               buffer is assigned to the appropriate table
                               share field.

  @retval         true         Failure.
  @retval         false        Success.
*/

bool prepare_default_value_buffer_and_table_share(THD *thd,
                                                  const dd::Table &table,
                                                  TABLE_SHARE *share);

#endif /* DEFAULT_VALUES_INCLUDED */